| |
| Publicado el 23,junio 2015 - 12:45 |
Hi,
My requirement is to convert below C code into WinDev
unsigned char ch = 0xFF
In WinDev I tried "ch is character = 0xFF" which stores 2 in ch instead of 0xFF.
I also used byte in WinDev but internally it is getting converted to 4 byte instead of 1 byte.
Any help how to solve this?
Thanks and Regards, Naveen Rathan |
| |
| |
| | | |
|
| | |
| |
| Publicado el 23,junio 2015 - 14:04 |
Hi Naveen,
0xFF is a hex representation often used in C-programming.
Converted to an integer that would be the number 255.
I am not sure about the context of your application but probably you want to convert this into WX as the character stored on position 255 in the ASCII table. You can find out which one this is by doing trace(charact(255)) ==> s is character = charact(255) OR s is string = charact(255).
Regarding your second question: To declare an unsigned 1 byte integer in WX just do: x is unsigned int on 1 byte.
Cheers,
Peter H. |
| |
| |
| | | |
|
| | |
| |
| Publicado el 23,junio 2015 - 14:24 |
Hi Peter,
Thanks for the reply. Actually my 'ch' is a structure variable. I have to fill 1 byte 'ch' with 0xFF and make a API call.
I used "x is unsigned int on 1 byte", but WinDev is internally converting it to 4 bytes which is creating problem since I am passing 'ch' to an external library.
In C it is an unsigned char which easily holds 0xFF. Any help how to solve this?
Thanks and Regards, Naveen Rathan |
| |
| |
| | | |
|
| | |
| |
| Publicado el 23,junio 2015 - 14:44 |
Hi Naveen,
Try the following: c is character = 0xff
Best regards, Alexandre Leclerc
Edit 1: Sorry, I saw that you already tried that. |
| |
| |
| | | |
|
| | |
| |
| Publicado el 23,junio 2015 - 15:00 |
Hi,
IT`s ibyte is 1-byte unsigned int if I recall right.
ibyte is 1-byte unsigned int = 0xFF
Cheers Tor-Bjarne |
| |
| |
| | | |
|
| | |
| |
| Publicado el 23,junio 2015 - 15:57 |
Hi Tor-Bjarne,
I tried that too. WinDev converts it to 4 byte integer which I don't want.
Any help how to make it stick to 1 byte variable?
Thanks and Regards, Naveen Rathan |
| |
| |
| | | |
|
| | |
| |
| Publicado el 23,junio 2015 - 16:07 |
Quote Naveen
I tried that too. WinDev converts it to 4 byte integer which I don't want.
Well it does not happen here, I use "1-byte unsigned int" to do my bit-fiddling.
Perhaps it`s not supported in a structure hence the conversion.
Try to do a : n is 1-byte unsigned int = mystructure.FieldByte CallMyCode(n) Also, are you shure you are not suppose to send the address of your byte variable to your external call?
Cheers Tor-Bjarne |
| |
| |
| | | |
|
| | |
| |
| Publicado el 23,junio 2015 - 16:19 |
Hi Tor-Bjarne,
I have to pass my structure to an external library like below:
status = API("LIB_NAME", "API_NAME", &mystructure)
So your suggestion doesn't help me. Any help how to solve in my case?
Thanks and Regards, Naveen Rathan |
| |
| |
| | | |
|
| | |
| |
| Publicado el 23,junio 2015 - 16:37 |
Hi Naveen,
Have you tried to do as Peter suggested? c is character = Charact(0xFF)
Because the character is really what you want and doing will work. You can verify with Asc(c).
Best regards, Alexandre Leclerc |
| |
| |
| | | |
|
| | |
| |
| Publicado el 24,junio 2015 - 07:31 |
Hi Alexandre,
I have tried that option but no result. It sends some other character which is not equal to 0xFF.
Thanks and Regards, Naveen Rathan |
| |
| |
| | | |
|
| | |
| |
| Publicado el 24,junio 2015 - 07:45 |
Hi
How about this:
MyBuffer is Buffer on 1 MyBuffer = 0xFF info(MyBuffer) // length is 1
HTH
King |
| |
| |
| | | |
|
| | |
| |
| Publicado el 24,junio 2015 - 09:30 |
Hi Naveen,
If your API is expecting a structure then you need to... declare a structure... When you need strings, for API calls you can't use WL strings. You need to declare these as ASCIIZ strings with the given length.
structDef is structure x is character //WATCH OUT: if your project is unicode this will be 2 bytes instead of 1 -> Use is string ASCIIZ on 1 instead y is string ASCIIZ on 12 z is unsigned 1-byte int end myStruct is structDef myStruct.x = charact(255) //will set it to character 255 of the ACII code page myStruct.y = "blabla" myStruct.z = 1 API(DLL,Function,&myStruct) I use this syntax allover my programs to interface with external modules and it works fine.
Probably you are passing a wrong structure definition to the API.
Cheers,
Peter H. |
| |
| |
| | | |
|
| | |
| |
| Publicado el 24,junio 2015 - 15:18 |
Hi King,
Using buffer solves the problem.
Thanks and Regards, Naveen Rathan |
| |
| |
| | | |
|
| | |