Author |
Message |
Simon Rolf #1 / 8
|
 Calling C DLLs (again)
I am having immense hassle calling a DLL written in BC5 (I think). Apparently, it doesn't use the StdCall calling convention, and according to something I read somewhere, it has to in order to work. I keep getting a "Bad DLL calling convention". Could anyone who can solve this, offer any help at all, or just sympathise, reply... Also, if you could verify or deny the StdCall thing, it would be much appreciated. Thanks.
|
Thu, 28 Dec 2000 03:00:00 GMT |
|
 |
Brad Pane #2 / 8
|
 Calling C DLLs (again)
Hi Rolfe; I am assuming that you delcared the DLL in a BAS module. A common problem is that the data types that are declared in in VB are not the same size as the data types being used in the C DLL. An Integer is a common variable which is frequenlty different in different compilers. Compare the data types and their Byte sizes between the VB and the BC. You can cheat between a signed and unsigned variable, but not between a Byte and a Word, their sizes must match. If the DLL has been called successfully by other applications before, it should already have the StdCall or something equivalent in it. Quote:
> I am having immense hassle calling a DLL written in BC5 (I think). > Apparently, it doesn't use the StdCall calling convention, and according > to something I read somewhere, it has to in order to work. > I keep getting a "Bad DLL calling convention". Could anyone who can > solve this, offer any help at all, or just sympathise, reply... > Also, if you could verify or deny the StdCall thing, it would be much > appreciated. > Thanks.
|
Thu, 28 Dec 2000 03:00:00 GMT |
|
 |
Simon Rolf #3 / 8
|
 Calling C DLLs (again)
Hi. Inexperienced as I am, I happen to have a C++ guru helping me out, and he assures me of the following: A C++ LPSTR is a VB5 ByVal String, a C++ WORD is a VB5 ByVal Long, and a C++ DWORD is also a ByVal Long. This may be the problem, but I have expreimented with other types. Also, no-one has ever actually managed to call the DLL from outside the EXE it was made for. I have had no problems with any of the other DLLs I have tried, but unfortunately this one wasn't written by the company I work for, so we have no sure-fire way of checking anything about it. Thanks anyway, and any other ideas are appreciated. Quote:
> Hi Rolfe; > I am assuming that you delcared the DLL in a BAS module. A common problem > is that the data types that are declared in in VB are not the same size as > the data types being used in the C DLL. An Integer is a common variable > which is frequenlty different in different compilers. > Compare the data types and their Byte sizes between the VB and the BC. > You can cheat between a signed and unsigned variable, but not between a Byte > and a Word, their sizes must match. > If the DLL has been called successfully by other applications before, it > should already have the StdCall or something equivalent in it.
> > I am having immense hassle calling a DLL written in BC5 (I think). > > Apparently, it doesn't use the StdCall calling convention, and according > > to something I read somewhere, it has to in order to work. > > I keep getting a "Bad DLL calling convention". Could anyone who can > > solve this, offer any help at all, or just sympathise, reply... > > Also, if you could verify or deny the StdCall thing, it would be much > > appreciated. > > Thanks.
|
Fri, 29 Dec 2000 03:00:00 GMT |
|
 |
Matthew V. Jessic #4 / 8
|
 Calling C DLLs (again)
Quote:
> I am having immense hassle calling a DLL written in BC5 (I think). > Apparently, it doesn't use the StdCall calling convention, and according > to something I read somewhere, it has to in order to work. > I keep getting a "Bad DLL calling convention". Could anyone who can > solve this, offer any help at all, or just sympathise, reply... > Also, if you could verify or deny the StdCall thing, it would be much > appreciated. > Thanks.
VB expects stdcall. Also, in MS VC++5 and VB5, VB integer is 16 bit = VC++5 short VB long is 32 bit = VC++5 int - Matt
|
Fri, 29 Dec 2000 03:00:00 GMT |
|
 |
Dmitri Alperovit #5 / 8
|
 Calling C DLLs (again)
Quote: >A C++ LPSTR is a VB5 ByVal String, a C++ WORD is a VB5 ByVal Long, and a C++
Nope. A VB5 ByVal string is a BSTR (have to use OLE apis to do stuff with it). A VB5 ByRef string is a BSTR*. This is true for both VB4 and VB5. A VB3 string, however, was an LPSTR. Regards, Dmitri http://www.cdc.net/~dmitri/
|
Sun, 31 Dec 2000 03:00:00 GMT |
|
 |
Jim Mac #6 / 8
|
 Calling C DLLs (again)
Dmitri - You're right about BSTR, but a nice thing about BSTR is that to a function that doesn't know any better, a BSTR looks and acts exactly like an LPSTR. Anywhere a C function specifies LPSTR for an [in] parameter, you can freely use a VB ByVal string. Only when you need to modify the length of a BSTR do you need to worry about the SysString API for dealing with BSTR. -- Jim Mack MicroDexterity, Inc PO Box 5372 Plymouth, MI 48170-5372 http://www.microdexterity.com
Fax: +1 734-453-8942
.. Quote: > >A C++ LPSTR is a VB5 ByVal String, a C++ WORD is a VB5 ByVal Long, and a C++ > Nope. > A VB5 ByVal string is a BSTR (have to use OLE apis to do stuff with it). A > VB5 ByRef string is a BSTR*. This is true for both VB4 and VB5. A VB3 > string, however, was an LPSTR. > Regards, > Dmitri > http://www.cdc.net/~dmitri/
|
Sun, 31 Dec 2000 03:00:00 GMT |
|
 |
Dmitri Alperovit #7 / 8
|
 Calling C DLLs (again)
Quote: > You're right about BSTR, but a nice thing about BSTR is that to a >function that doesn't know any better, a BSTR looks and acts exactly like an >LPSTR. Anywhere a C function specifies LPSTR for an [in] parameter, you can >freely use a VB ByVal string. Only when you need to modify the length of a >BSTR do you need to worry about the SysString API for dealing with BSTR.
It probably automatically does a (LPSTR)paramString on any BSTRs that are passed to a procedure that expects LPSTR. I don't know this for sure because I always do my own conversion - I feel safer that way... Regards, Dmitri http://www.cdc.net/~dmitri/
|
Sun, 31 Dec 2000 03:00:00 GMT |
|
 |
Jim Mac #8 / 8
|
 Calling C DLLs (again)
Dmitri - No, there's no conversion from BSTR to LPSTR, though there is an automatic conversion from Unicode BSTR to Ansi BSTR for Declared external procedures. The reason why you can pass a BSTR where an LPSTR is needed lies in how a BSTR is constructed and stored. It is in fact just a pointer to a zero-terminated series of characters (LPSZ). What makes it a BSTR is that the byte length is stored in a dword at a -negative- offset to the string body. Routines that expect LPSTR don't know to look "backward" for this length prefix and so they never see it. -- Jim Mack MicroDexterity, Inc PO Box 5372 Plymouth, MI 48170-5372 http://www.microdexterity.com
Fax: +1 734-453-8942 Quote:
> > You're right about BSTR, but a nice thing about BSTR is that to a > >function that doesn't know any better, a BSTR looks and acts exactly like an > >LPSTR. Anywhere a C function specifies LPSTR for an [in] parameter, you can > >freely use a VB ByVal string. Only when you need to modify the length of a > >BSTR do you need to worry about the SysString API for dealing with BSTR. > It probably automatically does a (LPSTR)paramString on any BSTRs that are > passed to a procedure that expects LPSTR. I don't know this for sure because > I always do my own conversion - I feel safer that way...
|
Sun, 31 Dec 2000 03:00:00 GMT |
|
|
|