Hi,
I found a problem when I call the DLL function Connected.
This is the secuence:
I Open correctly the card 0 wiht OpenDevice.
I disconnect the USB wire.
When I try to call any function after this, the DLL display “Error: 5”, why??
If I call the “Connected” function , the return value is 1 instead of 0, why?? (PowerGood fnction works properly)
If The USB is disconnect before call OpenDevice, the Connected function works properly.
My application is based on the C example but with a Connected and PowerGood functions call (why the example program not use the Connected function ?)
I’m using k8061_softwarepack_2011.zip package
can you help me, thanks.
I tested the same with the example of VC + + 2008 and works properly, the Connected function returns 0 when the USB is disconneted, but I need use mingw at windows SO (MinGW-gcc440_1.zip)
[code]#include
#include <windows.h>
#include
using namespace std;
typedef void(WINAPI *t_func0)();
typedef int(WINAPI *t_func5)();
typedef bool(WINAPI *t_func9)(int);
t_func5 OpenDevice;
t_func9 PowerGood;
t_func9 Connected;
t_func0 CloseDevices;
int init();
HINSTANCE hDLL;
int foundDLL = 0;
int main(void)
{
int CardAddress;
int h = init();
if (!h)
{
cout << "DLL found" << endl;
foundDLL = 1;
}
else
{
cout << "DLL not found" << endl;
cout << "Error code: " << h << endl;
cout << "Press a key to exit." << endl;
cin.get();
}
if (foundDLL)
{
CardAddress = OpenDevice();
if (CardAddress >= 0)
{
cout << "Card #"<< CardAddress << " opened." << endl;
}
else
{
cout << "Card not found" << endl;
}
}
if (foundDLL)
{
bool ret;
cout << "Press Enter to \"PowerGood\"" << endl;
cin.get();
ret = true;
ret = PowerGood(CardAddress);
cout << "-------------- PowerGood " << ret << endl << "-------------"<< endl;
cout << "Press Enter to \"Connected\"" << endl;
cin.get();
ret = true;
ret = Connected(CardAddress);
cout << "-------------- Connected " << ret << endl << "-------------"<< endl;
cout << "Press Enter to \"CloseDevices\" and to \"FreeLibrary\"" << endl;
cin.get();
CloseDevices();
FreeLibrary(hDLL);
}
return EXIT_SUCCESS;
}
int init()
{
hDLL = LoadLibrary(TEXT(“K8061.DLL”));
if (hDLL != NULL)
{
OpenDevice = (t_func5) GetProcAddress(hDLL, “OpenDevice”);
if (!OpenDevice)
{ // handle the error
FreeLibrary(hDLL);
return -2;
}
CloseDevices = (t_func0) GetProcAddress(hDLL, “CloseDevices”);
if (!CloseDevices)
{ // handle the error
FreeLibrary(hDLL);
return -3;
}
Connected = (t_func9) GetProcAddress(hDLL, “Connected”);
if (!Connected)
{ // handle the error
FreeLibrary(hDLL);
return -4;
}
PowerGood = (t_func9) GetProcAddress(hDLL, “PowerGood”);
if (!PowerGood)
{ // handle the error
FreeLibrary(hDLL);
return -5;
}
return 0; // OK
}
return -1; // error load DLL
}
[/code]
