🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Loading DLL with param weirdly fails

#12042
From: Muzzy
Date: Wed, 31 Dec 2003 07:11
64 lines
2825 bytes
Hi,

I have a .DLL library providing me with a function which returns false 
or true depending on some conditions. It's declared in DLL as:

//----------------------
extern "C" __declspec(dllexport) _stdcall bool VPNStart();
//----------------------


And i call it from an app (using func Start):

//----------------------
typedef bool (*HVPNSTART)(void);

bool Start()
{
   HINSTANCE hLib = LoadLibrary("MyDLL.DLL");
   if (hLib == NULL) {
     MessageBox(0, "Unable to Load MyDLL.DLL", "Error", MB_OK);
     return false;
   }
   HVPNSTART vs = (HVPNSTART)GetProcAddress(hLib, "VPNStart");
   if (vs == NULL) {
     MessageBox(0, "Failed calling VPNStart", "Error", MB_OK);
     FreeLibrary(hLib);
     return false;
   }
   bool result = vs();

   //MessageBox(0, "VPNStart Loaded!", "SUCCESS", MB_OK);
   if (result) MessageBox(0, "TRUE", "RESULT", MB_OK);
   else MessageBox(0, "FALSE", "RESULT", MB_OK);

   FreeLibrary(hLib);
   return result;
}
//----------------------

Everything works perfect until... i add an argument to the DLL fucn 
VPNStart:
//----------------------
extern "C" __declspec(dllexport) _stdcall bool VPNStart();
//----------------------

So i change the main app code:
//----------------------
typedef bool (*HVPNSTART)(ShortString);
bool Start( ShortString s ) {...}


It starts to act WEIRD!!! When i trace (F8 -:)) thru the 'Start()' func 
i see the following - after i load library, i write down it's address, 
say ':013A000'.
But after the line 'result = vs(s)', the hLib address changes to 
':8000004', and of course after i 'FreeLibrary' and return, it gives me 
an access violation... How come the address of library handle could change?

I also tried to pass char* instead of ShortString, doesn't work also...

Any ideas, PLEASE!!!

Thank you,
Andrey
Technical Details
Message-ID: <3ff276c0$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,4f80ac21c2728a9b,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-12-30 23:39:14 PST
Date: Wed, 31 Dec 2003 02:11:42 -0500
From: Muzzy <leyandrew@yahoo.com>
User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.5) Gecko/20031013 Thunderbird/0.3
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Loading DLL with param weirdly fails
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 24.91.233.60
Message-ID: <3ff276c0$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1072854720 24.91.233.60 (30 Dec 2003 23:12:00 -0700)
Lines: 65
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail