Das liegt an einer einfachen Sache:
Eine Methode eines Objekts ist im Grunde ein Pointer auf die Funktion / Prozedur und ein Pointer auf das zugehörige Objekt. Siehe auch den Record TMethod.
Du kannst das also einfach lösen, indem du keinen Pointer sondern eine solche Methode an die DLL übergibst:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37:
| type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private public procedure OnMyCallBack(); stdcall; end;
implementation
type TMyCallBack = procedure of object; stdcall; TMyDLLFunction = procedure(procPointer: TMyCallBack); stdcall;
var MyDLL: THandle; MyDLLFunction: TMyDLLFunction;
procedure TForm1.FormCreate(Sender: TObject); begin MyDLL := LoadLibrary(PChar(ExtractFilePath(ParamStr(0)) + 'MyDll.DLL')); @MyDLLFunction := GetProcAddress(MyDLL, 'MYDLLFUNCTION'); MyDLLFunction(OnMyCallBack); end;
procedure TForm1.FormDestroy(Sender: TObject); begin FreeLibrary(MyDLL); end;
procedure TForm1.OnMyCallBack; begin ShowMessage('Hallo'#13#10 + Caption); end; |
Und:
DLL
1: 2:
| type TMyCallBack = procedure of object; stdcall; |
Ich hoffe ich habe mich nicht vertippt, aber zumindest sollte das Vorgehen klar sein.
// EDIT:
Doch vertippt, der Parameter an TMyDLLFunction muss natürlich auch TMyCallBack sein. *korrigiert*