🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #15756

Dynamic DLL..Help!

#15756
From: Loz
Date: Wed, 18 Jun 2003 15:39
125 lines
5534 bytes
Hi,

I've written a static dll that I'm binding to dynamically.  I'm having 
some big problems and really need some help.

I'm finding my application is doing some odd things which I think can be 
attributed to some kind of heap problem related to the DLL.

For example,

In my main app I do the following...

    Plugin[0] = NULL;
    Plugin[0] = new TCommsModule(Owner);
    Plugin[0]->OpenModule( "tcpmod.dll" );
    char * MyDescription = new char[20];
    strcpy(MyDescription,"CLIENT");
    Plugin[0]->Initialise(Application->Handle,"CLIENT");
    int a = 1;
    double speed = Plugin[0]->GetSpeed();
    delete[] MyDescription;
    speed = Plugin[0]->GetSpeed(); // Called again to see if still valid

When I delete the char * MyDescription, which was used in the function 
Initialise (not used in the above example), the dll gets called again 
and hops to its entry point.  From that point onwards, it's a new 
instance and my previous call to my Initialise function is useless.

As you can see, MyDescription is not being used for anything, so why the 
dll seems to re-initialise itself, I don't know.  My only guess is that 
I'm doing something wrong with the importing and exporting of functions.

I should add that the dll is static and contains memmgr.lib, as does the 
main calling app.

Could someone please verify my imports and exports below please?

#ifndef dllcodeH
#define dllcodeH
//----------------------------------------------------------------------
#include "tcpipcode.h"
//----------------------------------------------------------------------
extern "C"
{
    __declspec(dllexport) void __stdcall Initialise(void *,char *);
    __declspec(dllexport) void __stdcall DestroyPlugin(void);
    __declspec(dllexport) void __stdcall Debug(char *);
    __declspec(dllexport) void __stdcall CommsSendMessage(AnsiString, 
AnsiString);  // If don't want to include memmgr.lib, would need to 
change to char*
    __declspec(dllexport) void __stdcall WhosThere(void);
    __declspec(dllexport) double __stdcall GetModuleVersion(void);
    __declspec(dllexport) double __stdcall GetSpeed(void);
    __declspec(dllexport) void __stdcall EnableComms(void);
    __declspec(dllexport) void __stdcall DisableComms(void);
    __declspec(dllexport) void __stdcall GetConnectionList(TStringList 
*);
    __declspec(dllexport) void __stdcall RegisterDataPathway(void
(__closure *) (char *));
}
bool Initialised;
char Name[100];
TTCPIPForm *TCPIP;// Pointer to a VCL form 

My main application then imports the functions...

Header...

    // Public imported function prototypes...
    void (__stdcall *Initialise)(void *, char *);
    void (__stdcall *DestroyPlugin)(void);  // Not used...?
    void (__stdcall *Debug)(char *);        // Debug interface with 
command passing char *
    void (__stdcall *CommsSendMessage)(AnsiString, AnsiString);  // If 
don't want to include memmgr.lib, would need to change to char*
    void (__stdcall *WhosThere)(void);
    double (__stdcall *GetModuleVersion)(void);
    double (__stdcall *GetSpeed)(void);
    void (__stdcall *EnableComms)(void);
    void (__stdcall *DisableComms)(void);
    void (__stdcall *GetConnectionList)(TStringList *);
    void (__stdcall *RegisterDataPathway)(void(__closure *) (char *));


Main App Code...

void TCommsModule::ObtainFunctionPointers(void)
{
    if (!Initialised)
        return;  // Abort function

    Initialise = (void (__stdcall*)(void*, char *)) GetProcAddress
(hInstLib, "Initialise");
    DestroyPlugin = (void (__stdcall*)(void)) GetProcAddress(hInstLib, 
"DestroyPlugin");
    Debug = (void (__stdcall*)(char *))GetProcAddress(hInstLib, 
"Debug");
    CommsSendMessage = (void (__stdcall*)(AnsiString, AnsiString)) 
GetProcAddress(hInstLib, "CommsSendMessage");
    WhosThere = (void (__stdcall*)(void))GetProcAddress(hInstLib, 
"WhosThere");
    GetModuleVersion = (double (__stdcall*)(void))GetProcAddress
(hInstLib, "GetModuleVersion");
    GetSpeed = (double (__stdcall*)(void))GetProcAddress(hInstLib, 
"GetSpeed");
    EnableComms = (void (__stdcall*)(void))GetProcAddress(hInstLib, 
"EnableComms");
    DisableComms = (void (__stdcall*)(void))GetProcAddress(hInstLib, 
"DisableComms");
    GetConnectionList = (void (__stdcall*)(TStringList *))GetProcAddress
(hInstLib, "GetConnectionList");
    RegisterDataPathway = (void (__stdcall*)(void(__closure *) (char 
*)))GetProcAddress(hInstLib, "RegisterDataPathway");
}
//----------------------------------------------------------------------

I could use a typedef to reduce my typing!  Aside from that, am I doing 
anything wrong in my imports and exports?

I'd really appreciate some help.  Sorry this posting is a little on the 
large side.

Thanks,

Loz
Technical Details
Message-ID: <Xns939EA95FE5225Loz@207.105.83.65>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,96f04d20cd206c09,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-06-18 08:42:35 PST
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Dynamic DLL..Help!
From: Loz <noemail@nowhere.com>
Message-ID: <Xns939EA95FE5225Loz@207.105.83.65>
User-Agent: Xnews/5.04.25
NNTP-Posting-Host: 217.37.62.138
Date: 18 Jun 2003 08:39:17 -0700
X-Trace: newsgroups.borland.com 1055950757 217.37.62.138 (18 Jun 2003 08:39:17 -0700)
Lines: 126
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail