Article View: borland.public.cppbuilder.nativeapi
Article #12045Re: Loading DLL with param weirdly fails
From: Remy Lebeau (TeamB)
Date: Wed, 31 Dec 2003 08:10
Date: Wed, 31 Dec 2003 08:10
38 lines
2316 bytes
2316 bytes
"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.
Gambit
Technical Details
Message-ID:
<3ff28343@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<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:17 PST From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3ff276c0$1@newsgroups.borland.com> Subject: Re: Loading DLL with param weirdly fails Date: Wed, 31 Dec 2003 00:10:53 -0800 Lines: 40 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 67.22.139.199 Message-ID: <3ff28343@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1072857923 67.22.139.199 (31 Dec 2003 00:05:23 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail