![]() |
Vorhandene Delphi 7 Forms Anwendung in DLL umwandeln
Liste der Anhänge anzeigen (Anzahl: 2)
Hallo liebe Community,
kurz zum Sachverhalt: Ich muss mit C# zum schreiben einer alten Datenstruktur die (TVirtualStringTree) vorhandene Delphi 7 Anwendung (Anhang 1 + Anhang 2) verwenden. Diese Anwendung ist eine Windows Forms Anwendung. Ich habe diese schon (so gut es ging) gecleant (also das wirklich nur mehr diese Komponenten auf der Form sind, die benötigt werden). Nun geht's eigentlich nur um folgendes: Auszug aus der Delphi 7 Anwendung:
Delphi-Quellcode:
Ich muss mit C# über die Delphi Com Anwendung auf diese Funktion zugreifen.
PTFolderBrowseDlg: TPTFolderBrowseDlg;
MMDesigner: TMMDesigner; TempFile: TMMAudioFile; VSTArchivList: TVirtualStringTree; VSTArchiv: TVirtualStringTree; ZipMaster: TZipMaster; SkinData1: TSkinData; ... Node := VSTArchivList.AddChild(VSTArchivList.RootNode); ... VSTArchivList.SaveToFile(Path + '\' + VSTArchiv.Text[TNode, 0] + VSTArchiv.Text[TNode, 1] + '.dat'); Leider verwendet Delphi hier eine Windows Form (VSTArchivList sowie VSTArchiv). Funktioniert das überhaupt eine DLL einzubinden die eigentlich eine Windows Form ist? Wenn nicht, kann ich "virtuell" eine Listbox im Code erstellen sodass die Anwendung diese dann direkt als DLL rauspeichern kann? Ich habe bereits eine Delphi Anwendung (DLL) erstellt mit der ich über C# -> zugreifen kann (weiter unten diese Anwendung (eine Ver-/Entschlüsselung (funktioniert prima!)). Nun geht es darum auch die Funktionen der oben erwähnten Anwendung in diese DLL einzubauen (Windows Forms). Hier ein Auszug aus der Delphi Com Anwendung:
Delphi-Quellcode:
Hier ein Auszug aus meiner C# App:
// Dateiname: Com.dll
library Com; { Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. } uses SysUtils, Classes, Blowfish, StdCtrls, DCPcrypt; {$R *.res} function sth(const Value: string): string; begin ... end; function hts(const Value: string): string; begin ... end; function decr(Input: string; Phrase: string): string; var Cipher: TDCP_blowfish; str: string; begin ... Result := Input; end; function encr(Input: string; Phrase: string): string; var Cipher: TDCP_blowfish; str: string; begin ... Result := Input; end; function ComFunc(inputInt : integer; inputString : PAnsiChar; out outputInt : integer;outputStringBufferSize : integer; var outputStringBuffer : PAnsiChar;errorMsgBufferSize : integer; var errorMsgBuffer : PAnsiChar; mode : integer) : WordBool; stdcall; export; var s : string; begin outputInt := 0; try outputInt := inputInt + 1; if mode = 1 then begin s := encr(inputString,CryptPhrase); end; if mode = 2 then begin s := decr(inputString,CryptPhrase); end; StrLCopy(outputStringBuffer, PAnsiChar(s), outputStringBufferSize-1); errorMsgBuffer[0] := #0; Result := true; except on e : exception do begin StrLCopy(errorMsgBuffer, PAnsiChar(e.Message), errorMsgBufferSize-1); Result := false; end; end; end; exports ComFunc; begin end.
Code:
Leider befasse ich mich mit Delphi erst seit zirka einem Monat, ... hoffe ihr könnt mir helfen..
using System.Runtime.InteropServices;
... public string Cmd(string value, int mode) { int inputInt = 1; string inputString = value; int outputInt; const int stringBufferSize = 1024; var outputStringBuffer = new String('\x00', stringBufferSize); var errorMsgBuffer = new String('\x00', stringBufferSize); if (!Com.ComFunc(inputInt, inputString, out outputInt, stringBufferSize, ref outputStringBuffer, stringBufferSize, ref errorMsgBuffer, mode)) { return "Error: " + errorMsgBuffer; } else { return outputStringBuffer; } } public class Com { [DllImport("Com.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] public static extern bool ComFunc(int inputInt, string inputString, out int outputInt, int outputStringBufferSize, ref string outputStringBuffer, int errorMsgBufferSize, ref string errorMsgBuffer, int mode); } VIELEN DANK schon mal vorweg! Lg Iceget |
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:55 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz