Autor Beitrag
Timbo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 166



BeitragVerfasst: Mi 19.01.11 12:51 
Hallo zusammen,

ich versuche eine DLL in Delphi einzubinden, doch leider schließt sich bei meinen bisherigen Versuchen das Programm komplett, ohne Fehlermeldung.
Leider habe ich in C nicht so viel Erfahrung, habe aber den Quellcode der DLL.


Also in der HeaderDatei steht:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
#if _USRDLL
MYDWORD __declspec(dllexport)LogicalVersN(MYBOOL);
#else
MYDWORD __declspec(dllimport)LogicalVersN(MYBOOL);
#endif

in der CPP Datei:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
DWORD CBDD6App::Dll_LogicalVersN(BOOL bState)
{
  CString strToSend;  // zu sendener Frame
  DWORD dwResult;    // ErrorCode
  if(bState)
  {
    //... code raus genommen
  }
  else
  {
    //... noch was anderes
  }
  return dwResult;
}

extern "C" MYDWORD LogicalVersN(MYBOOL bState)
{
  AFX_MANAGE_STATE(AfxGetStaticModuleState());
  return theApp.Dll_LogicalVersN(bState);
}


Ich hab versucht:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
function LogicalVersN (SetOn: Boolean): Longword;
stdcallexternal 'BDD6.dll';

function MyLogicalVersN(SetOn: Boolean): Integer;
begin
  result:= LogicalVersN(SetOn);
end;


Auch das führt leider zum selben Ergebnis:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function LogicalVersN (SetOn: Longword): Longword;
stdcallexternal 'BDD6.dll';

function MyLogicalVersN(SetOn: Longword): Integer;
begin
  if SetOn then
    result:= LogicalVersN(1)
  else
    result:= LogicalVersN(0);
end;


Was mache ich falsch?

Vielen vielen Dank schon mal.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 19.01.11 15:47 
Wie ist MYBOOL definiert?

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Timbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 166



BeitragVerfasst: Mi 19.01.11 15:58 
ausblenden C#-Quelltext
1:
typedef bool  MYBOOL;					


Ist es das?
Bin hier echt am verzweifeln, irgendwo knallt es da mächtig...
Timbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 166



BeitragVerfasst: Mi 19.01.11 16:48 
ich habe jetzt
ausblenden Delphi-Quelltext
1:
2:
function LogicalVersN (SetOn: Longword): Longword;
stdcallexternal 'BDD6.dll';


in
ausblenden Delphi-Quelltext
1:
2:
function LogicalVersN (SetOn: Longword): Longword;
cdeclexternal 'BDD6.dll';


geändert, nun geht es, kann es das gewesen sein???
GuaAck
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 378
Erhaltene Danke: 32

Windows 8.1
Delphi 10.4 Comm. Edition
BeitragVerfasst: Mi 19.01.11 17:01 
Hallo,

Bei Functions werden die Parameter über den Stack übergeben. Da gibt es Unterschiede, z. B. in der Reihenfolge der Parameter.

Bei Dir ist aber wichtig, das bei cdecl der Aufrufer den Stack (auf dem er ja auch die Parameter abgelegt hat) wieder aufräumt, bei stdcall wird das von der aufgerufen Routine erwartet. Mit stdcall statt cdecl war also Dein Stck nach dem Aufruf durcheinander und Dein Programmm hat immer auf andere Variablen zugegriffen, als es "dachte" und schließlich auch den Rücksprung zu seinem Aufrufer nicht mehr gefunden. Hätte eigentlich eine Exception geben müssen.

Gruß GuaAck
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 19.01.11 17:03 
Dann probier mal LongBool als Parameter. Das entspricht eher REM Verhalten der C-Deklaration.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 19.01.11 17:42 
user profile iconTimbo hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden C#-Quelltext
1:
typedef bool  MYBOOL;					

Ist das eigentlich ein Grund für eine fristlose Kündigung? :wall:
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 19.01.11 20:57 
Naja, wenn man schon den Quelltext offenlegen muss, dann kann man ihn zumindest so schreiben, dass jemand anderes ihn nicht so einfach versteht... :lol: :nut: