I had trouble with this particular software which I couldn't call the .dll using windows 7. I gave up on using .lib method because a lot of error came out and I couldn't solve the link and conversion errors.
Loading the library at runtime require extra efforts but not so much once you get a hold of it.
Let say we have a .dll file which contain listed functions below:
short TUSBSLC_API Tusbs01lc_Device_Open( short id );
void TUSBSLC_API Tusbs01lc_Device_Close( short id );
short TUSBSLC_API Tusbs01lc_Single_Sample( short id ,double *Data);
short TUSBSLC_API Tusbs01lc_Start_Sample( short id ,short SampleRate);
short TUSBSLC_API Tusbs01lc_Get_Datas( short id ,double *Data,unsigned char *SerNum,unsigned char *Size);
short TUSBSLC_API Tusbs01lc_Zero_Adj( short id, double Data );
Firstly we need to declare in your header file (.h) these definitions:
typedef short (*DEVICE_OPEN)(short);
DEVICE_OPEN Tusbs01lc_Device_Open;
typedef void (*DEVICE_CLOSE)(short);
DEVICE_CLOSE Tusbs01lc_Device_Close;
typedef short (*SINGLE_SAMPLE)(short, double*);
SINGLE_SAMPLE Tusbs01lc_Single_Sample;
typedef short (*START_SAMPLE)(short, short);
START_SAMPLE Tusbs01lc_Start_Sample;
typedef short (*GET_DATAS)(short, double*, unsigned char*, unsigned char*);
GET_DATAS Tusbs01lc_Get_Datas;
typedef short (*ZERO_ADJ)(short, double);
ZERO_ADJ Tusbs01lc_Zero_Adj;
You could give any name to DEVICE_OPEN, DEVICE_CLOSE and so on. The colors will give you hints on how to create your own definition.
Next, just call the function!!
HINSTANCE dllhandle = LoadLibrary("path\\TUSBSLC.dll");
if(dllhandle != NULL) {
Tusbs01lc_Device_Open = (DEVICE_OPEN)GetProcAddress(dllhandle, "Tusbs01lc_Device_Open");
Tusbs01lc_Device_Close = (DEVICE_CLOSE)GetProcAddress(dllhandle, "Tusbs01lc_Device_Close");
Tusbs01lc_Single_Sample = (SINGLE_SAMPLE)GetProcAddress(dllhandle, "Tusbs01lc_Single_Sample");
Tusbs01lc_Start_Sample = (START_SAMPLE)GetProcAddress(dllhandle, "Tusbs01lc_Start_Sample");
Tusbs01lc_Get_Datas = (GET_DATAS)GetProcAddress(dllhandle, "Tusbs01lc_Get_Datas");
Tusbs01lc_Zero_Adj = (ZERO_ADJ)GetProcAddress(dllhandle, "Tusbs01lc_Zero_Adj");
}
else {
ShowMessage("Unable to load the DLL");
}
Finally, you have to release/free the memory at the end of your program.
if(dllhandle) FreeLibrary(dllhandle);
Good luck!!
No comments:
Post a Comment