PC and operation is in the dynamic library:
PC:
The callback function declarations TOnResponse=procedure (sCmdBack: PChar) of the object; Callback function declarations and definitions,
The callback function interface function function RegisterHWCallback (aCallback: TOnResponse) : Integer; Stdcall; External 'Hardware. DLL';
The dynamic library:
The callback function declarations typedef void (* TOnResponse) (PCHAR sCmdBack);
The callback function interface function of extern "C" _declspec (dllexport) int _stdcall RegisterHWCallback (TOnResponse aCallback)
Once in the interface function, even if it is empty, jump out of the interface function will pop up "access violation at addressXXXX, write of addressXXXX"
What is solution of the problem, written for the dynamic library before vs upper machine, is no problem, but the link on the other side of the Delphi PC will pop up after the problem,
CodePudding user response:
TOnResponse=procedure (sCmdBack: PChar) of the object;There is of the object! With dynamic library statement corresponds not top?
CodePudding user response:
The change of dynamic libraries, dynamic database statement should be how to writeCodePudding user response:
TOnResponse=procedure (sCmdBack: PChar) of the object;To:
TOnResponse=procedure (sCmdBack: PChar); Cdecl;
CodePudding user response:
I'm sorry, is to change the dynamic library, do not change PC, dynamic library is written VS,CodePudding user response:
I'm sorry, can't do that, unless you let Microsoft changed the compiler,Your Delphi program, TOnResponse=procedure (sCmdBack: PChar) of the object; It declares a method pointer, because you don't have pointed out that calling convention, the default is Borland register agreement, so for the callback function parameter passed in is right: eax=self (this) in c + + and edx=sCmdBack, function do stack balance; And your VC code defined in the typedef void (* TOnResponse) (PCHAR sCmdBack); Use cdecl calling convention, sCmdBack use stack, stack the caller do balance,
You can see both on? The monkey is eating Fried dough twist - ManNing,
If you must call of Delphi method in the C code, then you cannot use a function pointer call directly, want to write a call transformation function, such as:
Void CallBackThunk (TOnResponse & amp; P, PCHAR sCmdBack);
Pointer with embedded in the internal assembly simulation method calls, but C code does not know the called method is an instance of the pointer, which is a serious hidden trouble, so it is better to define the callback function of Delphi change,
CodePudding user response:
If the PC and dynamic libraries such as stdcall calling conventions, Delphi program still states method PointersTOnResponse=procedure (sCmdBack: PChar) of the object; The corresponding VC dynamic library how to declare to correspond to the method Pointers
CodePudding user response: