Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing parameters to DLL function

Status
Not open for further replies.

mensud

Programmer
Jul 22, 2001
51
US
Hello,

I want to use a function from DLL which was developed in VC++. This function receive two parameters (SHORT data type) as hexadecimal numbers. I don't know how to pass the next sequence of characters "^XA,P,P,P,^FS" to this function, as one of parameters. I mean, how to convert this sequence as an array of hexadecimal numbers?

By the way, I can't pass the whole char sequence to this function. Instead, I have to pas char by char.

Thanks in advance

Mensud
 
?Right(Transform(Asc('^'), '@0x'), 2)
Will give you a hex representation of the "^" character, if that is what you need.
?ASC('^') will give you the ascii value, which may be what the function actually requires.

To pass it, you may need to do something like:
DECLARE INTEGER MyDLL IN 'SomeLib' SHORT @Parm1

Then call it using:
Parm1 = Right(Transform(Asc('^'), '@0x'), 2)
?MyDLL(@Parm1)

-or-

Parm1 = Asc('^')
?MyDLL(@Parm1)



-Dave S.-
[cheers]
Even more Fox stuff at:
 
Thanks Dave for your response.

What I am trying is to print to parallel port (windows 2000)
I declared my function Out32 as:

declare integer Out32 in "spports32.dll" as "Out32" short @PortAddress, short @PortString

The first parameter is hex address of the parallel port (0x378), and second parameter is "some" string (hexadecimal).
Here is how I call the function:

...
cString='^XA^PRA,A,A'
parm1=right(transform(asc(substr(cString,1)),'@0x'),2)
*-- For now I take only first character '^' which is 5E hex
*-- now I call function as:

=out32(378,@parm1)

But I get error message: Data type mismatch. Why?

 
Normally you only need the @ in the Declare and call if you are returning values through these paramaters. SHORT and a character string longer than two bytes doesn't make sense - a SHORT is only 16 bits long.

Note: 0x378 isn't the same as 378.

I'd try something like:
Code:
declare integer Out32 in "spports32.dll" as "Out32" short PortAddress, short PortChar

= out32(0x378, 0x5E)
Rick
 
mensud,

As an addition to Rick's comment, when you declare it short, you must pass in a numeric value. You cannot pass in STRING into SHORT. That's the reason you get data type mismatch.

-- AirCon --
 
OK, I made stupid mistake.

But how to convert character '^' (0x5E) to hexadecimal and pass it into function. If I use parm1 as Dave suggested, I obviously get an error because of mismatched types, but how to pass hex value, not integer.
I am totally confused.

Anyway thanks for your help.

Mensud
 
mensud,

But how to convert character '^' (0x5E) to hexadecimal and pass it into function

Sorry, I don't eaxactly sure what do you want.
- If you want to pass it as a numeric (SHORT). You can just pass 0x5E or 94.
- If you want to pass it as a char/string just pass it chr(0x5E) but you have to declare as STRING in the declaration
- If you want to pass it as hex but in form of string use what Dave's had suggested. Also you have to declare as STRING


-- AirCon --
 
There is no hex data type in VFP, only a character representation of hex, as in 0x0000005E. Simply because VFP doesn't see an 'E' as a value. It sees it as a character.
You can get the value of it like this:
?VAL('0x0000005E')
But, if you pass ASC('^'), you should get the value you need passed.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
Dave,
All these are equivalent:
Code:
? VAL('0x0000005E') && Actually INT(VAL('0x0000005E'))
? 0x5e
? asc('^')
? 94
Each has the same "value", they are just different ways of representing the concept of ninty-four.

As my partner has often said "Bits is Bits"!

Rick
 
Problem solved.

Thanks to everybody.

Mensud
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top