08-15-2004, 11:49 PM
Hello,
I wrote small routine in C(borland Turbo C/C++ 3.1). Made an .OBJ file from it and linked with VBDCL10E.LIB into funk.lib file, from what I made a .qlb file.
C function: (compiled using medium model(386 code generation)
In qb everything works just fine. Made even small test program to see wich is faster. Just in case here's qbasic code:
(C function completes test with smth of 12.xxx seconds and qb's function takes 20.xxx seconds :wink: )
Now the problem is when I compile it into exe. (using /g3 switch(it's VBDOS))
It compiles without errors. Everything is fine. But when I ran the test, it seems that C function doesn't return any value. It just returns 0 whenever function is called. Dunno why is it so. Did I compile smth wrong?
I wrote small routine in C(borland Turbo C/C++ 3.1). Made an .OBJ file from it and linked with VBDCL10E.LIB into funk.lib file, from what I made a .qlb file.
C function: (compiled using medium model(386 code generation)
Code:
int far ontarget(int mx, int my, int xpos, int ypos, int x1pos, int y1pos)
{
if (mx < xpos) return 0;
if (mx > x1pos) return 0;
if (my < ypos) return 0;
if (my > y1pos) return 0;
return -1;
}
In qb everything works just fine. Made even small test program to see wich is faster. Just in case here's qbasic code:
Code:
DEFINT A-Z
DECLARE FUNCTION ontarget CDECL (BYVAL mx, BYVAL my, BYVAL Xpos, BYVAL Ypos, X1pos, BYVAL Y1pos)
DECLARE FUNCTION OnTarget2 (BYVAL mx, BYVAL my, BYVAL Xpos, BYVAL Ypos, X1pos, BYVAL Y1pos)
CLS
PRINT "C function"
PRINT ontarget(100, 100, 50, 50, 150, 150)
PRINT ontarget(100, 10, 50, 50, 150, 150)
StartTest1! = TIMER
FOR i = 1 TO 32000
FOR m = 1 TO 1000
a = ontarget(100, 100, 50, 50, 150, 150)
NEXT m
NEXT
EndTest1! = TIMER
PRINT EndTest1! - StartTest1!
PRINT "qb function"
PRINT ontarget(100, 100, 50, 50, 150, 150)
PRINT ontarget(100, 10, 50, 50, 150, 150)
StartTest1! = TIMER
FOR i = 1 TO 32000
FOR m = 1 TO 1000
a = OnTarget2(100, 100, 50, 50, 150, 150)
NEXT m
NEXT
EndTest1! = TIMER
PRINT EndTest1! - StartTest1!
FUNCTION OnTarget2 (BYVAL mx, BYVAL my, BYVAL Xpos, BYVAL Ypos, X1pos, BYVAL Y1pos)
IF mx < Xpos THEN EXIT FUNCTION
IF my < Ypos THEN EXIT FUNCTION
IF mx > X1pos THEN EXIT FUNCTION
IF my > Y1pos THEN EXIT FUNCTION
OnTarget2 = -1
END FUNCTION
Now the problem is when I compile it into exe. (using /g3 switch(it's VBDOS))
It compiles without errors. Everything is fine. But when I ran the test, it seems that C function doesn't return any value. It just returns 0 whenever function is called. Dunno why is it so. Did I compile smth wrong?