C++ connect card k8097

good evening,

I can’t connect my card k8097 with C++, could you please help me, (my card work with demo software), I wrote :

typedef bool(CALLBACK* t_func)(string*, int);
t_func SMCConnect;
.
.
.
hDLL = LoadLibrary(“mtrapi32”);
.
.
.
bool CarteK8097::ouvreLaCarte()
{
bool h;
string p(“COM3”);
string *port;
port = &p;
h = Connect(port, 4);
if (h)
return true;
else
return false;
}

could you please confirm that DLL mtrapi32 work with C++, or must I use C code.

have you got a C++ example code

Everything works with C or C++, they are very powerful programming languages. Code in C is identical to C++ for what you want to do.

We don’t have any example code in C, but the internet and this forum is absolutely full of examples on how to load and use a DLL in C. Search for keywords like “LoadLibrary”, “GetProcAddress”, and “Dynamically loading a DLL in C”. This article may also be interesting to you: msdn.microsoft.com/en-us/library/ms810279.aspx

It is very confusing if you mix french and english in source code.

ok thank you, could you please confirm arguments and returned value of function SMCConnect :

I wrote in C++ : bool SMCConnect(string*; long);

SMCConnect return a bool
SMCConnect has 2 arguments :
string* -> pointer on a string wish contain USB port address
long -> engines quantity (1 for K8096 or 4 for K8097)

I’am right ?

The first argument is a char*, the second argument is a 32-bit integer. The return value is also a 32-bit integer.

ok, so first argument is a char* = pointer on a single character.
How can I stock my USB port wish is “com3” in a single character ?

No, a char* in C is a pointer to a single char or a nul-byte terminated string. In this case it is the latter.

Regards,
Jan

Thank you, my card K8097 now work with C++.
juste a note : the return value of function SMCConnect is really a bool, not an int as written before.

See below my simplified code :

using namespace std;

typedef bool (CALLBACK* prototypeConnectCardK8097)(const char*, int);

int main()
{
HINSTANCE dllHandle = NULL;
prototypeConnectCardK8097 connectCardK8097 = NULL;
dllHandle = LoadLibrary(“mtrapi32.dll”);
if (dllHandle != NULL)
{
cout << “DLL OK” << endl;
connectCardK8097 = (prototypeConnectCardK8097)GetProcAddress(dllHandle, “SMCConnect”);
const char *port;
string p(“com3”);
port = p.c_str();
bool h;
h = connectCardK8097(port, 4);
if(h)
cout << “connected” << endl;
else
cout << “not connected” << endl;
}
else
cout << “DLL NOK” << endl;
}

Glad to be of help.

And yes, according to this post it is a function returning BOOL:

viewtopic.php?f=3&t=8932&p=34570&hilit=K8097+pascal#p34570

However, WinDef.h defines BOOL as

typedef int BOOL;

which means it is represented in a 32 bit signed integer. So both statements are actually true.

Regards,
Jan

[quote=“MostlyHarmless”]However, WinDef.h defines BOOL as

typedef int BOOL;

which means it is represented in a 32 bit signed integer. So both statements are actually true.[/quote]That is absolutely correct. I chose 32-bit integer because it is important that it is 32-bits. Bool does not always have the same value for true and false across all programming languages.

Hi,
i would like to control my K8097 board with C/C++, too. But I cannot find the respective header file or any API reference.
Can anyone post a link to the api documentation of the mtrapi32.dll?