Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to pass parameters to H file?
#1
I am confused. What is the compiler trying to do?

I try to pass a parameter of type INT or Float and it keeps telling me that the conversion from type INT* to INT and from Float to Float* cannot be performed - what does this mean? Here is a sample code to QB64PE and below that the contents of the H file. It should be fine (but it would have to work) - what did I do wrong?

QB64 code:
Code: (Select All)
Declare Library "plus"
    Function calc_plus% (a As Integer, b As Integer)
End Declare

c% = calc_plus(5, 6)
Print c%

plus.h file code:
Code: (Select All)
int calc_plus (int a, int b)
{
    int c = a + b;
    return c;
}


I'm not big friends with the C language...


Reply
#2
Petr, try this
Code: (Select All)
Function calc_plus& (Byval a As Long byval b As Long)
because QB64 passes by reference by default
Reply
#3
note
QB64 Integer is 16-bit, so either change the QB64 declaration to long or change the C int to short
Reply
#4
The point is that no matter what data types I put there, I tried changing it on both sides, nothing compiles, it always ends up with an error message.


Reply
#5
Petr, I get the impression that you didn't try my suggestion
Code: (Select All)
Declare Library "plus"

    Function calc_plus% (byval a As Integer, byval b As Integer)

End Declare



c% = calc_plus(5, 6)

Print c%
Code: (Select All)
short calc_plus (short a, short b)

{

    short c = a + b;

    return c;

}
Reply
#6
Declare Library "plus"
    Function calc_plus% (a As Integer, b As Integer)
End Declare


In the above, QB64 will attempt to pass the _OFFSETs of the two parameters for you, and I don't think that's what you're looking for.   To pass the value of those Integers, use BYVAL as Jack as suggested above.

Declare Library "plus"
    Function calc_plus% (BYVAL a As Integer, BYVAL b As Integer)
End Declare




Point 2 that you might try is to DECLARE DYNAMIC LIBRARY or DECLARE CUSTOMTYPE LIBRARY and see if that corrects the issue.  You're trying to send and receive INTEGER values (16-bit) and the C-code you've written is actually looking to use 32-bit LONG values.  DECLARE DYNAMIC and DECLARE CUSTOMTYPE aren't as particular about 100% type matching, so swapping to those might solve the issue for you.  I'll test exactly what all is needed later, when I get back home from physical therapy and give you a 100% working example then.  Wink
Reply
#7
Petr
your original declaracion
Code: (Select All)
Function calc_plus% (a As Integer, b As Integer)

passes a and b by reference or in C-speak as pointers, you need to specify Byval otherwise it's passed as reference
Reply
#8
From some quick testing via remote connection to my Windows desktop, all you really seem to need is the BYVAL for both those a and b parameters.  Try that and then see if it won't work for you.  If not, then give it a shot with DECLARE CUSTOMTYPE and see how it goes.  Wink
Reply
#9
Thank you very much. I feel like an ox. But I'm glad to have a working example to lean on. Actually yes, yes, the biggest mistake was the missing word BYVAL. I tried to figure it out myself first....everything seemed logical....Thanks a lot guys!  Rolleyes


Reply




Users browsing this thread: 1 Guest(s)