Thread View: borland.public.cppbuilder.internet.socket
4 messages
4 total messages
Started by Colin B Maharaj
Sun, 12 Mar 2006 13:22
Server Socket DLL calling external function
Author: Colin B Maharaj
Date: Sun, 12 Mar 2006 13:22
Date: Sun, 12 Mar 2006 13:22
7 lines
1157 bytes
1157 bytes
Hi all I was considering making a DLL with an Indy Server socket. The thing is I want to call a function from the DLL that exists on the calling application, whenever the OnExecute fires. Is it possible to do this in a DLL? Is this what they call callback? Any pointers will be appreciated.
Re: Server Socket DLL calling external function
Author: Paul
Date: Sun, 12 Mar 2006 13:35
Date: Sun, 12 Mar 2006 13:35
22 lines
1848 bytes
1848 bytes
Hi Colin, I'm not an expert on DLLs, but I have just finished wrapping a BCB component into a DLL, to be used in VC++ and BCB. It took me quiet some time to get it right. The __stdcall is a good calling convention to use, and use standard types for parameters (I used ints and enums and it went horribly wrong, so changed them to ulong, char, etc). You also have to make sure that the DLL releases memory it creates and vice versa. Haven't tried callbacks though. Paul. "Colin B Maharaj" <noreply@myhost.com> wrote in message news:4414209d@newsgroups.borland.com... > Hi all I was considering making a DLL with an Indy Server socket. The > thing is I want to call a function from the DLL that exists on the calling > application, whenever the OnExecute fires. > > Is it possible to do this in a DLL? Is this what they call callback? > > Any pointers will be appreciated.
Re: Server Socket DLL calling external function
Author: Remy Lebeau (TeamB)
Date: Mon, 13 Mar 2006 20:29
Date: Mon, 13 Mar 2006 20:29
16 lines
1287 bytes
1287 bytes
"Colin B Maharaj" <noreply@myhost.com> wrote in message news:4414209d@newsgroups.borland.com... > The thing is I want to call a function from the DLL that exists on > the calling application, whenever the OnExecute fires. You would need to have the application pass a function pointer to the DLL. Then the DLL can store that pointer and call it when needed. > Is this what they call callback? Yes. Gambit
Re: Server Socket DLL calling external function
Author: Remy Lebeau (TeamB)
Date: Mon, 13 Mar 2006 20:39
Date: Mon, 13 Mar 2006 20:39
92 lines
2818 bytes
2818 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:4415d5ca$1@newsgroups.borland.com...
> You would need to have the application pass a function pointer to the DLL.
> Then the DLL can store that pointer and call it when needed.
For example:
--- MyDll.h ---
#ifndef MyDllH
#define MyDllH
typedef void __stdcall (*MYCALLBACKTYPE)(void);
#ifdef _BUILDING_DLL_
#define MYAPI __declspec(dllexport)
#else
#define MYAPI __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C" {
#endif
MYAPI void __stdcall SetExecuteCallback(MYCALLBACKTYPE);
#ifdef __cplusplus
}
#endif
#endif
--- MyDll.cpp ---
#define _BUILDING_DLL_
#include "MyDll.h"
class TMyServer
{
private:
TIdTCPServer *FServer;
TMyServer();
TMyServer(const TMyServer&) {}
TMyServer& operator=(const TMyServer&) {}
void __fastcall ServerExecute(TIdPeerThread *AThread);
public:
MYCALLBACKTYPE ExecuteCallback;
~TMyServer();
static TMyServer& Instance();
};
TMyServer::TMyServer()
{
ExecuteCallback = NULL;
FServer = new TIdTCPServer(NULL);
FServer->OnExecute = ServerExecute;
//...
}
TMyServer::~TMyServer()
{
delete FServer;
}
TMyServer& TMyServer::Instance()
{
static TMyServer inst;
return inst;
}
void __fastcall TMyServer::ServerExecute(TIdPeerThread *AThread)
{
if( ExecuteCallback )
ExecuteCallback();
else
Sleep(50);
}
void __stdcall SetExecuteCallback(MYCALLBACKTYPE Callback)
{
TMyServer.Instance().ExecuteCallback = AppCallback;
}
Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads