Hi,
I'm new to Delphi programming (well re-learning after a 14 year break) and I'm trying to get a Delphi application to communicate with a Dll writen in C++ (I don't have access to the Dll source code). I can call most of the dll's functions fine but I'm struggling to get callbacks to work. The C++ Dll provides the following code for callbacks:
[tt]typedef void(__stdcall *eventCallback)(void); // stdcall used for WINAPI compatibility.
DLLAPI void DLLCALL SetConnectedCallback(eventCallback);
DLLAPI void DLLCALL SetDisconnectedCallback(eventCallback);[/tt]
I want my Delphi application to register with these callbacks and be informed of connections/disconnections.
I have the following pieces of code (I've changed some of the object/function names etc.. as they contain brand names):
[tt]type
TDisconnectedFunctionPtr = procedure() of object;
TSetDisconnectedCallback = procedure(CallbackFunction: TDisconnectedFunctionPtr); stdcall;
fSetDisconnected: TSetDisconnectedCallback;
protected
property SetDisconnectedCallback: TSetDisconnectedCallback read fSetDisconnected;
public
procedure OnDisconnectedCallback(); virtual; // my callback function
end;
function TMyObject.OpenComms(openConnection: Boolean; connectionType: LongInt; portNumber: LongInt): LongInt;
begin
// other code.....
SetDisconnectedCallback(OnDisconnectedCallback);
end;
procedure TMyObject.GetDLLProcs;
begin
...
fSetDisconnected := GetProc('SetDisconnectedCallback');
end;[/tt]
Any help with this would be much appreciated. Thanks.
I'm new to Delphi programming (well re-learning after a 14 year break) and I'm trying to get a Delphi application to communicate with a Dll writen in C++ (I don't have access to the Dll source code). I can call most of the dll's functions fine but I'm struggling to get callbacks to work. The C++ Dll provides the following code for callbacks:
[tt]typedef void(__stdcall *eventCallback)(void); // stdcall used for WINAPI compatibility.
DLLAPI void DLLCALL SetConnectedCallback(eventCallback);
DLLAPI void DLLCALL SetDisconnectedCallback(eventCallback);[/tt]
I want my Delphi application to register with these callbacks and be informed of connections/disconnections.
I have the following pieces of code (I've changed some of the object/function names etc.. as they contain brand names):
[tt]type
TDisconnectedFunctionPtr = procedure() of object;
TSetDisconnectedCallback = procedure(CallbackFunction: TDisconnectedFunctionPtr); stdcall;
fSetDisconnected: TSetDisconnectedCallback;
protected
property SetDisconnectedCallback: TSetDisconnectedCallback read fSetDisconnected;
public
procedure OnDisconnectedCallback(); virtual; // my callback function
end;
function TMyObject.OpenComms(openConnection: Boolean; connectionType: LongInt; portNumber: LongInt): LongInt;
begin
// other code.....
SetDisconnectedCallback(OnDisconnectedCallback);
end;
procedure TMyObject.GetDLLProcs;
begin
...
fSetDisconnected := GetProc('SetDisconnectedCallback');
end;[/tt]
Any help with this would be much appreciated. Thanks.