I'm primarily a Visual Basic programmer and I'm making calls to a DLL written in C.
I have no problems using the DLL except when trying to implement a callback function in VB.
All I need are the few lines of Visual Basic code that will implement the callback.
Just want a simple example. I can only offer the header file, not the DLL.
Below is the header file:
#ifndef _USBCDDLL_HPP
#define _USBCDDLL_HPP
#define DEVICE_COMMANDOK 0
#define DEVICE_IDERROR 1
#define DEVICE_BUSY 2
#define DEVICE_UNKNOWERROR 3
extern "C"
{
typedef void (CALLBACK* CDDeviceChangePROC )(int);
WINUSERAPI VOID WINAPI InitUSBCDLibrary();
WINUSERAPI VOID WINAPI CloseUSBCDLibrary();
WINUSERAPI VOID WINAPI SetCDCallbackProc( CDDeviceChangePROC lpProc );
WINUSERAPI int WINAPI GetDeviceNumber();
WINUSERAPI int WINAPI EnumDevice( int);
// CD Device Operate function below
WINUSERAPI int WINAPI USBCDReset( int ID );
WINUSERAPI int WINAPI USBCDMoveto( int ID, int Index );
WINUSERAPI int WINAPI USBCDGetCDDown( int ID );
WINUSERAPI int WINAPI USBCDLEDON( int ID );
WINUSERAPI int WINAPI USBCDLEDOFF( int ID );
WINUSERAPI int WINAPI USBCDGetStatus( int ID );
}
#endif
ADDITIONAL INFORMATION
Here's some text from the documentation provided to me. Keep in mind I'm looking for the implementation that will work in VB.
Our library support a callback function, when device is add or remove, you callback function will called with now device number pass in.
The callback function should be below type:
typedef void (CALLBACK* CDDeviceChangePROC )(int);
use SetCDCallbackProc( CDDeviceChangePROC lpProc ) to set your callback function.
Ex :
// Callback function
void CALLBACK OnCDDeviceChange( int nDeviceNumber )
{
// Do what you want to do when device changed ( because user add or remove device )
}
in your main code, use below code to set callback function:
SetCDCallbackProc( (CDDeviceChangePROC)OnCDDeviceChange );
**Added Note**
I have already tried the 'standard' callback procedure's as is used with the Win32 APIs using addressof. But, I get a runtime error:
Run-time error '49'
Bad DLL calling convention.
## Deliverables
1) Complete and fully-functional working program(s) in executable form as well as complete source code of all work done.
## Platform
Win32
Visual Basic