I try load NTDirect.dll from C# like this:
[DllImport("NTDirect.dll")]
public static extern int Last(string instrument, double price, int size);
I try this code:
typedef int(*last_func)(const char* instrument, double price, int size);
typedef int(*conn_func)(int show_message);
HMODULE nt_lib;
last_func Last;
conn_func Connected;
BOOL APIENTRY DllMain(HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
{
char err_msg[10];
switch (fdwReason)
{
case DLL_PROCESS_ATTACH: // Подключение DLL
nt_lib = LoadLibrary("NTDirect.dll");
if (!nt_lib) {
OutputDebugString("could not load the dynamic library");
sprintf_s(err_msg, "%d", GetLastError());
OutputDebugString(err_msg);
return FALSE;
}
//# resolve function address here
Last = (last_func)GetProcAddress(nt_lib, "Last");
if (!Last) {
OutputDebugString("could not locate the function");
sprintf_s(err_msg, "%d", GetLastError());
OutputDebugString(err_msg);
return FALSE;
}
//# resolve function address here
Connected = (conn_func)GetProcAddress(nt_lib, "Connected");
if (!Connected) {
OutputDebugString("could not locate the function");
sprintf_s(err_msg, "%d", GetLastError());
OutputDebugString(err_msg);
return FALSE;
}
break;
case DLL_PROCESS_DETACH: // Отключение DLL
break;
case DLL_THREAD_ATTACH: // Создание нового потока
break;
case DLL_THREAD_DETACH: // Завершение потока
break;
}
return TRUE;
}
....
const char* instr = "TEST";
Last(instr, 200, 100);
I have this error:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

Comment