🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Loading DLL with param weirdly fails

#12044
From: Muzzy
Date: Wed, 31 Dec 2003 07:55
73 lines
3232 bytes
Muzzy wrote:

> 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

Wow, i just made a very simple example of a dll func with "ShortString" 
arguement and it gives access violation as well... I can't use 
ShortString arguement to pass to a dll func? I am using BCB 6.0

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

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,4f80ac21c2728a9b
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-12-31 00:09:16 PST
Date: Wed, 31 Dec 2003 02:55:54 -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: Re: Loading DLL with param weirdly fails
References: <3ff276c0$1@newsgroups.borland.com>
In-Reply-To: <3ff276c0$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 24.91.233.60
Message-ID: <3ff2811c$2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1072857372 24.91.233.60 (30 Dec 2003 23:56:12 -0700)
Lines: 74
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail