AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Algorithmen, Datenstrukturen und Klassendesign Vorhandene Delphi 7 Forms Anwendung in DLL umwandeln
Thema durchsuchen
Ansicht
Themen-Optionen

Vorhandene Delphi 7 Forms Anwendung in DLL umwandeln

Ein Thema von iceget · begonnen am 11. Feb 2015
Antwort Antwort
iceget

Registriert seit: 26. Jan 2015
13 Beiträge
 
#1

Vorhandene Delphi 7 Forms Anwendung in DLL umwandeln

  Alt 11. Feb 2015, 08:41
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:
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');
Ich muss mit C# über die Delphi Com Anwendung auf diese Funktion zugreifen.
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:
// 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.
Hier ein Auszug aus meiner C# App:
Code:
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);
}
Leider befasse ich mich mit Delphi erst seit zirka einem Monat, ... hoffe ihr könnt mir helfen..

VIELEN DANK schon mal vorweg!

Lg Iceget
Miniaturansicht angehängter Grafiken
anhang1.jpg   anhang2.jpg  

Geändert von iceget (11. Feb 2015 um 10:13 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort

 

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:52 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz