Posts: 35
Threads: 7
Joined: Sep 2009
I got a dll and call the function "StartEngine()",it works well in script of qm,and return 1
(looks like this function start a new thread and do network something)
but when change to exe file,seems return 0 only,and couldn't find out a new thread which should be there...... :?
is there some secret options to "start" it?thanks a lot!
Posts: 12,147
Threads: 143
Joined: Dec 2002
QM does not show threads started in exe process. You can see threads of your exe process in "Explore Windows" dialog.
Also, the first exe thread must not end until other threads not finished their work.
But if the return value is different, the reason probably is other.
Maybe because exe file path is different?
Maybe exe must run as administrator, but it doesn't?
Posts: 35
Threads: 7
Joined: Sep 2009
it works very well in qm,but can't work if change to exe file... :?:
(winxp with administrator account)
any suggestions?
(I use ProcessExplorer to check thread,they said it's not bad )
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
dll- "III.dll"
#SetServer $szHost nPort
#StartEngine
#StopEngine
#GetEngineStatus
str controls = "1201 1202"
str e3 e4
e3="123"
if(!ShowDialog("Dialog111" &Dialog111 &controls)) ret
BEGIN DIALOG
0 "" 0x90C80A44 0x100 0 0 223 135 "Dialog"
1 Button 0x54030001 0x4 120 116 48 14 "OK"
2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
1201 Edit 0x54030080 0x200 14 14 96 14 ""
1202 Edit 0x54030080 0x200 14 32 96 14 ""
1203 Edit 0x54030080 0x200 14 50 96 14 ""
1204 Edit 0x54030080 0x200 14 68 96 14 ""
1205 Edit 0x54030080 0x200 14 86 96 14 ""
3 Button 0x54032000 0x0 20 116 48 14 "Query"
END DIALOG
DIALOG EDITOR: "" 0x2030005 "*" "" ""
ret
messages
sel message
case WM_INITDIALOG
int+ howner=hDlg
str s;s.getwintext(id(1201 hDlg));s.setwintext(id(1202 hDlg))
out SetServer("11.22.11.22", 12345)
out StartEngine()
case WM_DESTROY
out StopEngine()
case WM_COMMAND goto messages2
ret
messages2
sel wParam
case 3
query something...
_s.format("%.2f" d1);_s.setwintext(id(1201 hDlg))
_s.format("%.2f" d2);_s.setwintext(id(1202 hDlg))
_s.format("%.2f" d3);_s.setwintext(id(1203 hDlg))
_s.format("%.2f" d4);_s.setwintext(id(1204 hDlg))
_s.format("%.2f" d5);_s.setwintext(id(1205 hDlg))
case IDOK
case IDCANCEL
ret 1
Posts: 12,147
Threads: 143
Joined: Dec 2002
This macro creates almost the same program in C language. Does it work?
Requires QM 2.3.2.
Macro
Macro1404
str se="$desktop$\test.exe"
__Tcc x.Compile("" se 1)
run se
#ret
#include <windows.h>
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HMODULE hm;
int (__stdcall*SetServer)(LPSTR,int);
int (__stdcall*StartEngine)();
int (__stdcall*StopEngine)();
int (__stdcall*GetEngineStatus)();
//if these functions use C calling convention (__cdecl), delete all __stdcall.
int r1=0, r2=0;
if(hm=LoadLibrary("III.dll"))
{
SetServer=GetProcAddress(hm, "SetServer");
StartEngine=GetProcAddress(hm, "StartEngine");
StopEngine=GetProcAddress(hm, "StopEngine");
GetEngineStatus=GetProcAddress(hm, "GetEngineStatus");
r1=SetServer("11.22.11.22", 12345);
r2=StartEngine();
}
char s[1000];
_snprintf(s, 999, "hm=%i r1=%i r2=%i", hm, r1, r2);
MessageBox(0, s, "test", MB_TOPMOST);
return 0;
}
Posts: 35
Threads: 7
Joined: Sep 2009
hm=268435456 r1=4204469 r2=0
I copy that dll file to desktop too,but didn't find the new thread in process test.exe... :?:
Posts: 35
Threads: 7
Joined: Sep 2009
and test.exe is very small,just 2.xk,nice...
Posts: 12,147
Threads: 143
Joined: Dec 2002
Try to remove all __stdcall.
Posts: 35
Threads: 7
Joined: Sep 2009
int (*GetEngineStatus)();
...
linenumber: warning: assignment from incompatible pointer type
Posts: 12,147
Threads: 143
Joined: Dec 2002
__stdcall was correct.
Maybe the dll requres some special conditions. Are the functions documented somewhere? Can you somehow retrieve error description?
Posts: 35
Threads: 7
Joined: Sep 2009
you are right,"Maybe because exe file path is different?"
the dll in "my qm" was a very low version,return 0 always... :roll:

:o
after update to same version,the script and exe both work very well :lol: :lol: :lol:
Many thanks! :wink: