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!!
Showing posts with label CPP. Show all posts
Showing posts with label CPP. Show all posts
Wednesday, November 27, 2013
Tuesday, November 12, 2013
CPP Series: Pointer to Pointer
Everytime..... this pointer fella give me headache... fuhhh...
here the reference for future headache [link].
This function modify the variable piStuff inside the function putStuff.
Example pointer to double pointer:
int **piStuff;
putStuff(&piStuff);
void putStuff(int ***ppiStuff)
{
*ppiStuff = new int* [SIZE_A];
for(int i=0; i<SIZE_A;i++) {
(*ppiStuff)[i] = new int [SIZE_B];
}
for(int i=0; i <SIZE_B;i++) {
for(int j=0; j <SIZE_B;j++) {
(*ppiStuff)[i][j] = iSomeVar;
}
}
}
Example pointer to pointer:
int *piStuff;
putStuff(&piStuff);
void putStuff(int **ppiStuff)
{
*ppiStuff = new int [SIZE];
for(int j=0; j <SIZE;j++) {
(*ppiStuff)[j] = iSomeVar;
}
}
here the reference for future headache [link].
This function modify the variable piStuff inside the function putStuff.
Example pointer to double pointer:
int **piStuff;
putStuff(&piStuff);
void putStuff(int ***ppiStuff)
{
*ppiStuff = new int* [SIZE_A];
for(int i=0; i<SIZE_A;i++) {
}
for(int i=0; i
}
}
}
Example pointer to pointer:
int *piStuff;
putStuff(&piStuff);
void putStuff(int **ppiStuff)
{
*ppiStuff = new int [SIZE];
for(int j=0; j
}
}
Thursday, July 12, 2012
CPP Series - Variable definition
Lesson of the day
Lesson #1
Try to avoid global definition for variables
Lesson #2
define variable for "for loop" inside the loop... don't EVER define them as global!! Local variable should be acceptable because it is easy to debug in case of error happened.
Subscribe to:
Posts (Atom)