Posts: 35
	Threads: 7
	Joined: Sep 2009
	
	
 
	
	
		There is a dll file from my friend,it will connect to server and reconnect if need,so there is a function in it:
StartConnect("serverip",serverport)
it will start a thread when call it,it work well if call it with c++,but I call it with qm,it can't work... 
 
 
I check the "netstat" and "thread",looks like the connection and thread were killed when finished qm call,
what should I do to handle this case? Thank anyway!
	
 
 
	
	
	
		
	Posts: 12,239
	Threads: 144
	Joined: Dec 2002
	
	
 
	
	
		Maybe the caller thread must be running all the time.
StartConnect("serverip",serverport)
;opt waitmsg 1 ;;try this if does not work
wait -1
	
	
	
	
	
 
 
	
	
	
		
	Posts: 35
	Threads: 7
	Joined: Sep 2009
	
	
 
	
	
		it doesn't work,but he said I should start a thread in qm,that would be ok,but...
I can't handle his interface like this:
typedef struct tag_EXPORT_INFO_111
	{
		int flag ;//flag
		float	total;
......
and use it with this:
EXPORT_INFO_111 my_list[3]; 
---------------------------------------------------
how to find a way to handle "float"? and "[3]"?
thanks a lot!
	
	
	
	
	
 
 
	
	
	
		
	Posts: 12,239
	Threads: 144
	Joined: Dec 2002
	
	
 
	
	
		C++ 'float' type in QM is 'FLOAT'.
type EXPORT_INFO_111 flag FLOAT'total ...
________________________________________
QM does not have C++ static arrays. Use variable of ARRAY type.
C++
EXPORT_INFO_111 my_list[3];
Function(... my_list ...)
QM
ARRAY(EXPORT_INFO_111) my_list.create(3);
Function(... &a[0] ...)
	
	
	
	
	
 
 
	
	
	
		
	Posts: 35
	Threads: 7
	Joined: Sep 2009
	
	
 
	
	
		looks like "ARRAY(...)" works,but "FLOAT" still can't work,there is this:
#pragma pack(push,1) //
	typedef struct ...
how to "push 1" in qm? :?:
	
	
	
	
	
 
 
	
	
	
		
	Posts: 12,239
	Threads: 144
	Joined: Dec 2002
	
	
 
	
	
		set offsets of each member, like
type TYPENAME [0]byte'b [1]int'i
What is full definition of EXPORT_INFO_111?
	
	
	
	
	
 
 
	
	
	
		
	Posts: 35
	Threads: 7
	Joined: Sep 2009
	
	
 
	
	
		...
#ifdef __cplusplus
extern "C" {
#endif
#pragma pack(push,1)
...
	typedef struct tag_EXPORT_INFO_111
	{
		int flag ;//flag
		float total;
		float	num1;
		float	num2;
		float	num3;
		float	numall;
		//float	num9;
	}EXPORT_INFO_111;
...
#pragma pack(pop)
...
DllExport void WINAPI Function1(int *nNum, void *pData); //pData-->EXPORT_INFO_111[x]
...
	
	
	
	
	
 
 
	
	
	
		
	Posts: 35
	Threads: 7
	Joined: Sep 2009
	
	
 
	
	
		I try these conditions:
1.type EXPORT_INFO_111 flag FLOAT'total FLOAT'num1
out "%i %.2f %.2f" flag total num1
0 0.00 0.00
2.type EXPORT_INFO_111 flag double'total double'num1
0 0.00 1234.56 (num1 was wrong)
3.type EXPORT_INFO_111 flag total num1
0 0.00 5678.90 (num1 was wrong)
looks like "double" and "int" could return some wrong num... :?: 
any suggestions? Thanks!
	
	
	
	
	
 
 
	
	
	
		
	Posts: 35
	Threads: 7
	Joined: Sep 2009
	
	
 
	
	
		total was wrong too,it should be a float num like 3456.78,not 0.00
	
	
	
	
	
 
 
	
	
	
		
	Posts: 12,239
	Threads: 144
	Joined: Dec 2002
	
	
 
	
	
		There is no format field for FLOAT type. If need to display FLOAT, assign it to double.
Macro 
Macro1425 
FLOAT f=1.5
out f ;;OK
out "%.2f %.2f" f f ;;wrong. %f is only for double.
double d=f
out "%.2f %.2f" d d ;;OK
__________
EXPORT_INFO_111 would be the same with or without pragma pack 1.
	
 
 
	
	
	
		
	Posts: 35
	Threads: 7
	Joined: Sep 2009
	
	
 
	
	
		yeah,it works!!! 
 
   
   
 
Thanks a lot!!!  :lol:  :lol:  :lol:
	
 
 
	
	
	
		
	Posts: 35
	Threads: 7
	Joined: Sep 2009
	
	
 
	
	
		In some stru,looks like have some problems:
type EXPORT_222 byte'code[8] byte'name[10] int'total int'...
I can get "code" and "name" with right numbers,but "total" was wrong,seems should swap the first byte to second one,I don't know the cause,so I have to do this:
type EXPORT_222 byte'code[8] byte'name[10] byte'total[4] byte'...
and add a function:
function byte*p
int* pi=p;_i=*pi
ret _i
Any helps?thanks!
	
	
	
	
	
 
 
	
	
	
		
	Posts: 12,239
	Threads: 144
	Joined: Dec 2002
	
	
 
	
	
		Probably in C it is declared with pragma pack 1 or 2.
Then in QM you have to explicitly set offsets.
You should set offsets of all members to make sure that size of type is correct.
Macro 
Macro1377 
type EXPORT_222 byte'code[8] byte'name[10] int'total int'next
EXPORT_222 e222
out "%i %i %i"  &e222.total-&e222  &e222.next-&e222  sizeof(EXPORT_222)
;-------------------
type EXPORT_223 byte'code[8] byte'name[10] [+10]int'total [+4]int'next
EXPORT_223 e223
out "%i %i %i"  &e223.total-&e223  &e223.next-&e223  sizeof(EXPORT_223)
;-------------------
type EXPORT_224 [0]byte'code[8] [+8]byte'name[10] [+10]int'total [+4]int'next
EXPORT_224 e224
out "%i %i %i"  &e224.total-&e224  &e224.next-&e224  sizeof(EXPORT_224)
Recommended reading: "Structure member alignment; unions" in QM Help.
This explicit offset setting feature is good for unions, but not convenient for types like this. I'll probably add something like pragma pack in next QM. Maybe #opt pack 1 or similar.
	
 
 
	
	
	
		
	Posts: 35
	Threads: 7
	Joined: Sep 2009
	
	
 
	
	
		20 24 28
18 22 28
18 22 26
looks like case 3 was the best,case 2 works too
This solution is better than using a function, the stru vars could be used directly,thanks!  :lol:  :lol:  :lol: