Importing Unmanaged DLL from VB (2005)

fkmfkm

New member
Joined
Nov 2, 2007
Messages
4
Programming Experience
3-5
I need to call this dll from vb.net .

int __stdcall ConnectEx(const char* address, const char* port,
const char* id, idk_callback_ex* lpfunc, unsigned long user_param,
int connect_type, unsigned long connect_attempts);

anyone can help me on this ? Totally no idea how ...

This is provided to me :
IIDK consist of the following files:
• iidk.dll — the SecurOS integration functions library.
• iidk.h — the header file with the declarations of the functions to be imported.
• iidk_VC6.lib — the library file for work with iidk.dll (a library for MS Visual C++ 6.0).
• iidk_VC71.lib — the library file for work with IIDK consist of the following files:
• iidk.dll — the SecurOS integration functions library.
• iidk.h — the header file with the declarations of the functions to be imported.
• iidk_VC6.lib — the library file for work with iidk.dll (a library for MS Visual C++ 6.0).
• iidk_VC71.lib — the library file for work with iidk.dll (a library for MS Visual C++ 7.1).

Please help Thank you.
 
You have to use the Declare statement or the DllImport attribute to declare an external function in VB.NET. MSDN has details of how to use each. DllImport would be the preferred mechanism. You then have to declare each argument as the .NET type equivalent to the unmanaged type in the original declaration. You'd use the following replacements:

char* => String
idk_callback_ex* => Delegate
unsigned long => ULong
int => Integer
 
You have to use the Declare statement or the DllImport attribute to declare an external function in VB.NET. MSDN has details of how to use each. DllImport would be the preferred mechanism. You then have to declare each argument as the .NET type equivalent to the unmanaged type in the original declaration. You'd use the following replacements:

char* => String
idk_callback_ex* => Delegate
unsigned long => ULong
int => Integer


Thanks for your reply. I will try. This is very new to me...One more question

idk_callback_ex*. Is this a type ? Where can I get this when I construct my delegate ?

Thank you.
 
You don't need that type. It's basically a function pointer. All you need to do is declare the corresponding argument as type Delegate and then when you call the external function you pass the AddressOf your callback method. As long as that callback method has the appropriate signature it will work.
 
You don't need that type. It's basically a function pointer. All you need to do is declare the corresponding argument as type Delegate and then when you call the external function you pass the AddressOf your callback method. As long as that callback method has the appropriate signature it will work.


Thanks for replying. The given sample is this

void __stdcall myfunc(const char* msg, char* slave_id,
unsigned long user_param) {
printf("\r\nReceived:%s from %s, user param %d\r\n",
msg, slave_id, user_param);
}

Can you help me create a sample for me(including the call back and the calling) if that is not too troublesome. I am totally noob on this.

Thank you very much.
 
Back
Top