Article View: borland.public.cppbuilder.nativeapi
Article #12047Re: Loading DLL with param weirdly fails
From: Muzzy
Date: Wed, 31 Dec 2003 08:13
Date: Wed, 31 Dec 2003 08:13
47 lines
2659 bytes
2659 bytes
Remy Lebeau (TeamB) wrote: > "Muzzy" <leyandrew@yahoo.com> wrote in message > news:3ff276c0$1@newsgroups.borland.com... > > >>typedef bool (*HVPNSTART)(void); > > > You are missing the calling convention. That line should be more like the > following instead: > > typedef bool __stdcall (*HVPNSTART)(void); > > >>Everything works perfect until... i add an argument to >>the DLL fucn VPNStart: > > > You did not show that actual declaration. Perhaps you copy/pasted the other > declaration by accident? > > >>typedef bool (*HVPNSTART)(ShortString); > > > Again, you are missing the calling convention, it should be this instead: > > typedef bool __stdcall (*HVPNSTART)(ShortString); > > >>It starts to act WEIRD!!! > > > As well it should. By neglecting to include the appropriate calling > convention in your typedef, you are corrupting the stack when you actuall > call the exported function. In the absence of any explically specified > calling convention, the compiler uses the default convention of __cdecl. > However, the actual DLL function is using __stdcall instead of __cdecl. The > two conventions manage the stack very differently in regards to who (the > caller or the callee) pushes and pops the function parameters on the stack, > in what order the parameters are pushed, etc. Since you are mixing > conventions, the exported function is being called differently than the DLL > actually expects, and as such your application goes crazy. > > Yeap, thank you Remy! I already added _stdcall and it works fine now.
Technical Details
Message-ID:
<3ff28551@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-mailReferences:
<3ff276c0$1@newsgroups.borland.com> <3ff28343@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:39:17 PST Date: Wed, 31 Dec 2003 03:13:49 -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> <3ff28343@newsgroups.borland.com> In-Reply-To: <3ff28343@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: <3ff28551@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1072858449 24.91.233.60 (31 Dec 2003 00:14:09 -0700) Lines: 48 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