In the past two daysProgramC To call the corresponding function in dynamic library.
Interface prototype in
Prototype: (the actual name is omitted in the example)
Bool openviewa (Cstring strpro1, cstring strpro2, cstring strpro3)
{
...
Return ture;
}
Because C has a similar interface openviewcc, copy it and change its name. Its original prototype is:
Note parameter type
Bool openviewcc (Lpcstr strpro1,LpcstrStrpro2,LpcstrStrpro3)
{
...
Return ture;
}
The prototype of the called interface added in C is
Extern "C" _ declspec (dllexport) bool openviewa (Cstring strpro1, cstring strpro2, cstring strpro3)
{
// Define the function pointer of the same type in a to be called
Typedef bool (* func )();
// Obtain the corresponding function interface from the OBC dynamic library
Func proc = (func) getprocaddress (m_hadll, "openviewa ");
// If a function exists, call it directly.
If (null! = Proc)
{
Return proc (strpro1, strpro2, strpro3 );
}
// If the function does not exist, false is returned.
Return false;
}
Results An exception occurs during each call. It was later found that it was a parameter problem. The parameter types of interfaces in master C and dynamic library a must be strictly consistent. Either cstring or lcpstr. Otherwise, exceptions are not surprising.
Note the parameter type of the interface.