Hello All
I need to call Clarion DLL from C++ app.
For that purpose, here is console app calling Clarion DLL:
#include <windows.h>
#include <iostream>
typedef int(__stdcall* ClarionFuncType)(char*, char*, char*, char*, int);
int main() {
SetConsoleOutputCP(CP_ACP);
HMODULE hClarionDLL = LoadLibraryA("MyClarion.dll");
if (!hClarionDLL) {
std::cerr << "Can not read MyClarion.dll. Error: " << GetLastError() << std::endl;
return 1;
}
ClarionFuncType MyFunction = (ClarionFuncType)GetProcAddress(hClarionDLL, "MyFunction");
if (!MyFunction) {
std::cerr << "Function MyFunction not found. Error: " << GetLastError() << std::endl;
FreeLibrary(hClarionDLL);
return 2;
}
char par1[256] = "Param1";
char par2[256] = "Param2";
char par3[256] = "Param3";
char resultBuffer[1024] = { 0 };
int retLen = MyFunction(par1, par2, par3, resultBuffer, sizeof(resultBuffer) / sizeof(char));
std::cout << "Returned size: " << retLen << std::endl;
std::cout << "resultBuffer content: " << resultBuffer << std::endl;
FreeLibrary(hClarionDLL);
return 0;
}
and here is Clarion DLL:
PROGRAM
MAP
MyFunction(*cSTRING par1, *cSTRING par2, *cSTRING par3, *CSTRING r1, LONG r2), LONG, PASCAL, NAME('MyFunction')
END
CODE
MyFunction PROCEDURE(*CSTRING par1, *CSTRING par2, *CSTRING par3, *CSTRING r1, LONG r2)
temp CSTRING(1024)
CODE
message('par1: '&clip(par1)&' par2: '&clip(par2)&' par3: '&clip(par3))
As you can see, message display some wired things - instead of Param1, Param2 and Param3, here is what I see: