Qbasicnews.com

Full Version: Question about c++ ->qbasic
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello,
I have a problem, I made small routine in c++ (Borland C++ 3.0), created a library(lib) from it and linked to qbasic. Now when I want to use the function i get always only one value: -1

Here's the code, I know it's stupid, but I'm experimenting.
Code:
int 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;
}

And I try to read it with:
Code:
DEFINT A-Z
DECLARE FUNCTION ontarget CDECL (BYVAL mx, BYVAL my, BYVAL xpos, BYVAL ypos, BYVAL x1pos, BYVAL y1pos)
PRINT ontarget(100, 100, 50, 50, 150, 150)

The value I always -1
Looks like it works then, that makes sense doesnt it?

100 is not less than 50, or more than 150, so -1 is returned.

Try: PRINT ontarget(100, 100, 20, 50, 150, 150)
that should return 0.
I too tested it out and it works fine =P.
You have to tell the C++ compiler to use the BASIC calling convention of passing args from left to right instead of the standard right-to-left C calling convention. Try declaring the function as PASCAL. I forget exactly where the keyword goes, but it needs to look something like this:
Code:
PASCAL int ontarget(int mx, int my, int xpos, int ypos, int x1pos, int y1pos)
Some compilers have other synonyms for PASCAL, like MSVC's __stdcall.
Quote:You have to tell the C++ compiler to use the BASIC calling convention of passing args from left to right instead of the standard right-to-left C calling convention. Try declaring the function as PASCAL. I forget exactly where the keyword goes, but it needs to look something like this:
Code:
PASCAL int ontarget(int mx, int my, int xpos, int ypos, int x1pos, int y1pos)
Some compilers have other synonyms for PASCAL, like MSVC's __stdcall.

He's using CDECL in QB, so it is the same.

(at it's int PASCAL Wink )
Whoa! QB has CDECL? I totally missed that... :oops:
heya,

Tnx, but now I can't get it to work at all, no matter what I do, it always in qbasic says that funcion does not exist. I'll try to work it out later,

But no matter what I did (when it syill worked), it always returned value -1.

Oh well, btw what is best (qbasic friendly) c++/c compiler, and wich is the best method to compile(I mean like what Model to use and such) I'm really quite a newby to c++ :oops:
Make sure that your C/C++ compiler is making public names uppercase; QB uppercases all public names, and the linker won't be able to find the functions if one of them is lowercase and the other is uppercase.

I never use C or C++ with QB; I write everything in QB or ASM. C's not hardly worth it if you've using QB for part of the same project, and ASM can do anything. Smile
I'm not that good at asm, actually I'm not good at all in it.
But is there somewhere some good(and easy to understand) asm tutorial?
Pages: 1 2