Click to See Complete Forum and Search --> : Bad DLL Calling Convention, please help..


Spotnick2
January 17th, 2000, 09:26 AM
I'm not a VB Expert, but I would like to know what the hell is the error here.

My C++ DLL is declared this way:


extern "C" __declspec(dllexport) int PublishPDF(int Version, LPSTR source, LPSTR destination, int delai);




And my VB declare is:


private Declare Function PublishPDF Lib "PubPDF" (byval Version as Integer, byval Source as string, byval Destination as string, byval Delay as Integer) as Integer




And Visual Basic returns me a "bad calling convention" error (runtime error #49).. this is only happening at design time.

Thank you in advance, I'm lost here...!



---
Nicolas LeBlanc
Software Engineer
Ordiplan Inc.

Lothar Haensler
January 18th, 2000, 01:24 AM
2 things:
- you need to specify _stdcall calling convention
- you have to take into account, that in a 32 bit OS a C int is 4 Bytes, but a VB Integer is 2 bytes.
Thus change your VB declare from "AS Integer" to "As Long"

Spotnick2
January 18th, 2000, 08:57 AM
Yes, I added the stdcall but I noticed then my DLL wasn't working. And then I finally found the answer to my problems that nobody told me yet.

I'm going to write about it for people searching the messages to answers about this...

When you have a dll function that uses the "_stdcall", you *NEED* to declare this function into your .DEF file.. otherwise your function won't have an entry point. If you don't use the _stdcall, you will have access to your functions, but in Visual Basic, you'll have a bad calling convention.


I'm getting to learn about DLL just as they're being replaced by OCX ;-)

BTW, thanks for the 2 vs 4 bits integer, I didn't know about this one. I had one of my variables set as a long in VC++, what would that be then in VB?


---
Nicolas LeBlanc
Software Engineer
Ordiplan Inc.

Lothar Haensler
January 18th, 2000, 09:01 AM
>I had one of my variables set as a long in VC++, what would that be then in VB?

"...As Long" would be OK.