🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #2594

Re: Server Socket DLL calling external function

#2594
From: Remy Lebeau (TeamB)
Date: Mon, 13 Mar 2006 20:39
92 lines
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
Technical Details
Message-ID: <4415d81c$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4414209d@newsgroups.borland.com> <4415d5ca$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,635d156d10eec29e
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <4414209d@newsgroups.borland.com> <4415d5ca$1@newsgroups.borland.com>
Subject: Re: Server Socket DLL calling external function
Date: Mon, 13 Mar 2006 12:39:05 -0800
Lines: 94
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <4415d81c$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1142282268 68.69.17.41 (13 Mar 2006 12:37:48 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail