The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Translate DLL function into VB

I am not familiar with VB but I need to write a program to use a DLL (written in C). Do not know how to translate the function prototype. For example, what is the corresponding delcaration of this DLL function:

HRESULT __stdcall get_Property(HANDLE handle, BOOL *pVal);

I tried the following prototype in VB
Declare Function get_Property Lib "mydll.dll" (ByVal handle As Long, ByRef pVal As Any)

It did not work.
Slave_VB_Programmer
Tuesday, May 16, 2006
 
 
Maybe you need an "AS Long" at the end.  The default return type of VB functions is Variant.
Almost H. Anonymous Send private email
Tuesday, May 16, 2006
 
 
I believe you can also "Declare Sub" instead of "Declare Function" if you don't want to have a return type...
Former COBOL Programmer Send private email
Tuesday, May 16, 2006
 
 
You CAN declare it 'Sub' instead of 'Function'.  However, if it actually DOES return a value, you'll crash the Windows run-time.

Been there, done that, own the T-shirt.

A 'Declare' of this sort in VB MUST match the DLL, or Bad Things Happen.  You probably need a copy of Appleman's "Visual Basic Programmer's Guide to the Win32 API".
AllanL5
Tuesday, May 16, 2006
 
 
Thanks. I have figured out by adding the Long as return type.

But how to translate those functions:

HRESULT __stdcall get_Font(HANDLE handle, IFontDisp** pVal);
HRESULT __stdcall put_Font(HANDLE handle, IFontDisp* val);
HRESULT __stdcall get_Picture(HANDLE handle, IPictureDisp** pPicture);

Thanx in advance.
Slave_VB_Programmer
Tuesday, May 16, 2006
 
 
Same way.
John
Tuesday, May 16, 2006
 
 
Those are COM methods.  VB6 may support accessing them directly if you can work out the right typelib to reference.  What is the DLL that is exposing these methods?
Joe
Tuesday, May 16, 2006
 
 
Yes the underlying is a COM object. But the boss wants a DLL version without any registry dependencies (the DLL itself may use some standard COM objects but that is fine). We wrapped the COM into a DLL, and now we are writing samples demonstrating how to call in VB. Any ideas how to call IFontDisp* in VB?
Slave_VB_Programmer
Tuesday, May 16, 2006
 
 
"Any ideas how to call IFontDisp* in VB?"

IFontDisp* would be "ByVal x as Object" (or better IFontDisp if you've got a type library with it)

IFontDisp** would be "ByRef x as Object"
Almost H. Anonymous Send private email
Tuesday, May 16, 2006
 
 
I don't think you can do that, the Object would have to be registered as a normal COM object and the type library would have to be imported to get the interface definition.
Joe Don
Tuesday, May 16, 2006
 
 
> But the boss wants a DLL version without any registry dependencies
Use reg-free com if your boss likes making things difficult
Joe
Wednesday, May 17, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz