Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to connect to callback function in C++ dll

Status
Not open for further replies.

Vovin

Programmer
Aug 24, 2003
63
GB
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.
 
It's ok I've eventually worked it out for myself. There's not a lot of activity on this forum.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top