🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.ms-windows.programmer.tools.mfc
5 messages
5 total messages Started by ESSA Tue, 06 Feb 1996 16:05
Prob calling VC++ 4.0 DLL from VB4 (32bit)
#47
Author: ESSA
Date: Tue, 06 Feb 1996 16:05
30 lines
1395 bytes
Having a frustrating time trying to call a function in a DLL developed in
VC++ 4.0 from Visual Basic 4.0 (32bit). I'm getting VB error 49 (bad DLL
calling convention) from the following simple function ...

In mydll.h
#define DllExport __declspec(dllexport)
extern "C" long DllExport TestLongParam(long lParam);

In mydll.cpp
extern "C" long DllExport TestLongParam(long lParam)
{
	TRACE("TestLongParam called with %ld\n", lParam);
	return(1L);
}

The Declare in VB is
Declare Function TestLongParam Lib "MYDLL.DLL" (ByVal lParam As Long) As Long

When I call TestLongParam from VB, I get the TRACE output with the correct 
value for the passed parameter, but on return, VB gives error 49.

Can anyone sugesst what is wrong with the way I have declared the functions ?
I have played around with the __stdcall modifier, the WINAPI macro and even
tried the old obsolete FAR PASCAL with no success.

Thx

---
pwhiteside@essa.com
Re: Prob calling VC++ 4.0 DLL from VB4 (32bit)
#53
Author: Bill Boland
Date: Tue, 20 Feb 1996 10:26
65 lines
2703 bytes
a09748@giant.mindlink.bc.ca (ESSA) wrote:

>
>Having a frustrating time trying to call a function in a DLL developed in
>VC++ 4.0 from Visual Basic 4.0 (32bit). I'm getting VB error 49 (bad DLL
>calling convention) from the following simple function ...
>
>In mydll.h
>#define DllExport __declspec(dllexport)
>extern "C" long DllExport TestLongParam(long lParam);
>
>In mydll.cpp
>extern "C" long DllExport TestLongParam(long lParam)
>{
>	TRACE("TestLongParam called with %ld\n", lParam);
>	return(1L);
>}
>
>The Declare in VB is
>Declare Function TestLongParam Lib "MYDLL.DLL" (ByVal lParam As Long) As Long
>
>When I call TestLongParam from VB, I get the TRACE output with the correct 
>value for the passed parameter, but on return, VB gives error 49.
>
>Can anyone sugesst what is wrong with the way I have declared the functions ?
>I have played around with the __stdcall modifier, the WINAPI macro and even
>tried the old obsolete FAR PASCAL with no success.
>
>

I may have a clue since I had a similar situation today.
If a DLL is compiled with VB 4.0 WITHOUT a module definition file and
uses  the new __declspec( dllexport ) to declare functions as
exportable, VB4 cannot seem to understand them. At least that is what
I discovered today on my own.

I created a small DLL with a function that passes a long value and
returned the long value. For example:

#define DllExport	__declspec( dllexport )

DllExport DWORD		Test( DWORD data );

DWORD
Test( DWORD data )
{
	return data;
}

VB4 could not seem to handle this. Yet, if I went back to the
traditional method (FAR PASCAL), used a module definition file and
declared the function name in the EXPORTS section, I had no problem. I
really don't know enough about VB4 or the __declspec( dllexport ) to
know why this is...but as soon as I used an EXPORTS section and a
module definition file, all my problems went away.

I hope this helps. I know it's a stab in the dark but it sure did
cause me grief and sounded close to the problem you have encountered.

Good luck,

Bill Boland
--------
billbo@ix.netcom.com
Just a friendly little hobbit. Master of his domain.
Re: Prob calling VC++ 4.0 DLL from VB4 (32bit)
#54
Author: Lauren Vanderhoof
Date: Wed, 21 Feb 1996 04:01
31 lines
1510 bytes
billbo@ix.netcom.com (Bill Boland) wrote:

>a09748@giant.mindlink.bc.ca (ESSA) wrote:

>>
>>Having a frustrating time trying to call a function in a DLL developed in
>>VC++ 4.0 from Visual Basic 4.0 (32bit). I'm getting VB error 49 (bad DLL
>>calling convention) from the following simple function ...
>>
<snip> non-working code

>Bill Boland
>--------
>billbo@ix.netcom.com
>I may have a clue since I had a similar situation today.
>If a DLL is compiled with VB 4.0 WITHOUT a module definition file and
>uses  the new __declspec( dllexport ) to declare functions as
>exportable, VB4 cannot seem to understand them. At least that is what
>I discovered today on my own.

Yes a module definition file seems to be necessary, VB couldn't find
the C function names until I included one.

However, this doesn't quite explain the "Bad Calling Convention"
error.

Check out VB4DLL.TXT in the \VB directory on the CDROM. It should help
explain all.

Cheers,
	lauren :}
Re: Prob calling VC++ 4.0 DLL from VB4 (32bit)
#55
Author: ESSA
Date: Thu, 22 Feb 1996 04:41
22 lines
1673 bytes
Bill Boland (billbo@ix.netcom.com) wrote:
: >Having a frustrating time trying to call a function in a DLL developed in
: >VC++ 4.0 from Visual Basic 4.0 (32bit). I'm getting VB error 49 (bad DLL
: >calling convention) from the following simple function ...

: I may have a clue since I had a similar situation today.
: If a DLL is compiled with VB 4.0 WITHOUT a module definition file and
: uses  the new __declspec( dllexport ) to declare functions as
: exportable, VB4 cannot seem to understand them. At least that is what
: I discovered today on my own.

Thanks Bill. And thanks Rob Ross of FTP Software, who got back to me after 
phoning MS support about the same problem.
In the root of the VB4 installation directory, there is a file called 
vb4dll.txt that explains a number of issues concerning 32bit DLL's, including
the problems I'd been having.
The solution, as Bill discovered (how many hours do you figure we've all 
collectively wasted ?) is the use of the DEF file.

---
pwhiteside@essa.com
ESSA Software Ltd.
Re: Prob calling VC++ 4.0 DLL from VB4 (32bit)
#60
Author: Tony O'Brien
Date: Tue, 27 Feb 1996 04:37
35 lines
1889 bytes
a09748@giant.mindlink.bc.ca (ESSA) wrote:

>Bill Boland (billbo@ix.netcom.com) wrote:
>: >Having a frustrating time trying to call a function in a DLL developed in
>: >VC++ 4.0 from Visual Basic 4.0 (32bit). I'm getting VB error 49 (bad DLL
>: >calling convention) from the following simple function ...

>: I may have a clue since I had a similar situation today.
>: If a DLL is compiled with VB 4.0 WITHOUT a module definition file and
>: uses  the new __declspec( dllexport ) to declare functions as
>: exportable, VB4 cannot seem to understand them. At least that is what
>: I discovered today on my own.

>Thanks Bill. And thanks Rob Ross of FTP Software, who got back to me after 
>phoning MS support about the same problem.
>In the root of the VB4 installation directory, there is a file called 
>vb4dll.txt that explains a number of issues concerning 32bit DLL's, including
>the problems I'd been having.
>The solution, as Bill discovered (how many hours do you figure we've all 
>collectively wasted ?) is the use of the DEF file.

>---
>pwhiteside@essa.com
>ESSA Software Ltd.

The DEF file is certainly useful but probably NOT the source of this
error...You need to specify _STDCALL (calling convention) in the
projects settings...

regards,


Tony O'Brien
Sourcecode, Inc.
srccode@voicenet.com
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads