HELP! Calling a VC DLL from VB 
Author Message
 HELP! Calling a VC DLL from VB

I'm using 16-bit VB 4.0 to the DLL as shown below (16bit one). This works
fine with the VB statement:

DECLARE FUNCTION osload lib "win6400.DLL" (ByVal address%, ByVal rsvdstr$,
ByVal rsvd%) As Integer

The same function is provided in a 32-bit (?) dll for Windows 95 (see
second above). In VB 4.0 32-bit I can't get either to work.
I've tried changing the parameter types in the VB declare statement but the
call never returns to VB.

What should the declare statement look like for the second DLL in 32-bit VB
?
Can you reply by e-mail as well as news. TIA

WIN64000.DLL 16-bit .H
==================
extern int FAR Pascal osload(unsigned int address, LPSTR rev, HWND hWnd)

WN95600.DLL 32-bit .H
=================
short osload(unsiged short address, LPSTR options, HWND hWnd)



Tue, 31 Aug 1999 03:00:00 GMT  
 HELP! Calling a VC DLL from VB

I'd try the following declaration:
Declare Function osload lib "win6400.DLL" (ByVal address as integer, ByVal
options as string, ByVal hWnd long) As Integer

1st Param:
I'm a bit curious what the first parameter does inside your DLL. In C on
Win32 using VB 32-bit version of VB, a short integer is equivalent to a VB
integer (16 bits). I'm curious why you have an address that is a 16 bit
value. Most memory addresses in the 32-bit world are 32 bit numbers (VB
long). I am assuming that you have this address value in an integer in VB
and you are just passing the value of this address to your DLL. If instead
you are sending the address of a structure, string, array or anything else
you will have to change the way the first parameter is declared and passed.
2nd Param:
An LPSTR is a pointer to a string, in VB a string passed by value.
3rd Param:
An hWnd has to be a 32-bit value, in VB this is a long.  



< snip >

Quote:
> short osload(unsiged short address, LPSTR options, HWND hWnd)



Tue, 31 Aug 1999 03:00:00 GMT  
 HELP! Calling a VC DLL from VB

I'm not sure this will solve your problem but in the 32 bit version the C
type HWND resolves to a Long Integer in VB so the call should be declared:

#If Win32 then
DECLARE FUNCTION osload lib "win6400.DLL" (ByVal address%, ByVal rsvdstr$,
 ByVal rsvd&) As Integer
#End If

--
Richard Buhrer



Quote:
> I'm using 16-bit VB 4.0 to the DLL as shown below (16bit one). This works
> fine with the VB statement:

> DECLARE FUNCTION osload lib "win6400.DLL" (ByVal address%, ByVal
rsvdstr$,
> ByVal rsvd%) As Integer

> The same function is provided in a 32-bit (?) dll for Windows 95 (see
> second above). In VB 4.0 32-bit I can't get either to work.
> I've tried changing the parameter types in the VB declare statement but
the
> call never returns to VB.

> What should the declare statement look like for the second DLL in 32-bit
VB
> ?
> Can you reply by e-mail as well as news. TIA

> WIN64000.DLL 16-bit .H
> ==================
> extern int FAR PASCAL osload(unsigned int address, LPSTR rev, HWND hWnd)

> WN95600.DLL 32-bit .H
> =================
> short osload(unsiged short address, LPSTR options, HWND hWnd)



Tue, 31 Aug 1999 03:00:00 GMT  
 HELP! Calling a VC DLL from VB

Quote:

>I'm using 16-bit VB 4.0 to the DLL as shown below (16bit one). This works
>fine with the VB statement:
>DECLARE FUNCTION osload lib "win6400.DLL" (ByVal address%, ByVal rsvdstr$,
>ByVal rsvd%) As Integer
>The same function is provided in a 32-bit (?) dll for Windows 95 (see
>second above). In VB 4.0 32-bit I can't get either to work.
>I've tried changing the parameter types in the VB declare statement but the
>call never returns to VB.
>What should the declare statement look like for the second DLL in 32-bit VB
>?
>Can you reply by e-mail as well as news. TIA
>WIN64000.DLL 16-bit .H
>==================
>extern int FAR PASCAL osload(unsigned int address, LPSTR rev, HWND hWnd)
>WN95600.DLL 32-bit .H
>=================
>short osload(unsiged short address, LPSTR options, HWND hWnd)

Hi Martin,

First of all, I would suggest you create a simpler function for
testing with, so you know you don't have parameter passing problems.

As far as I know, VB can only access DLLs that use the PASCAL calling
convention. This is probably why the call never returns.
I am working on a similar thing, and I have a function declared in VC
4.2 as:
extern "C" _declspec(dllexport) long _stdcall WATCHDOG_Test(long x)

And then I would use the DLL in VB using the declaration

(ByVal x as Long) as Long

The Alias clause needs a bit of explanation:
It seems that VC mangles (or decorates) the function names when using
the PASCAL calling convention. It puts the underscore in front and
appends the number of bytes taken up by the parameters.
I discovered this using a program called Keyview, which allows me to
view the functions in any DLL, to see their names. I'm sure this isn't
the only way to see this information.
I expect you can stop VC mangling the names by using a DEF file, but I
haven't yet tried.

I've used this method in 2 DLLs, with about a dozen functions, with
different types of parameters, and it works fine. However, I would
expect it to crash out if the parameters were typed in wrong - This is
because the PASCAL calling convention is quite delicate.

Hope this Helps,

Steven
--



Tue, 31 Aug 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. HELP! Calling a VC DLL from VB

2. vb calls vc dll and strings get chopped

3. Problems calling a VC DLL from VB

4. calling VC DLL from VB

5. Calling VC++ programs and VC created dlls from VB

6. Calling C DLLs with VB/VC 5

7. Calling VB DLLs from VC/C++

8. can you create a dll in VB and call in VC

9. VB Call to VC DLL

10. callbacks (VB calls a VC DLL)

11. Calling VB DLLs from VC/C++

12. vb calling vc dll :csaa

 

 
Powered by phpBB® Forum Software