Page 1 of 2

PokeS questions

Posted: Tue Feb 23, 2010 5:44 pm
by SFSxOI
I have this:

Code: Select all

*pwzExeName = AllocateMemory(#MAX_PATH)
PokeS(*pwzExeName, ExeName$, name_length, #PB_Unicode)
I'm using it to convert an ascii file name to unicode for some stuff for API in an application that operates on 32 bit and 64 bit systems.

1. Does PokeS operate any differently in 64 bit then it does in 32 bit? (just trying to verify something)
2. How do you verify that the conversion from ascii to unicode was actually done without looking at the result, that the conversion actually took place? (is that possible?)
3. How do you detect if the original ExeName$, before it was placed in the PokeS procedure, was indeed ascii to begin with?

Re: PokeS questions

Posted: Tue Feb 23, 2010 6:15 pm
by srod
1. Unsure what you mean exactly?

2. Providing you have a memory buffer of the correct length, is PokeS() ever going to fail?

3. Well PokeS() assumes that the given source string is Ascii encoded if you are running without the Unicode switch and Unicode encoded otherwise. The question of whether ExeName$ is Ascii encoded, within the context of the code you posted, is thus irrelevant and not really appropriate. I mean, how can it contain an Ascii string if running in Unicode etc? The answer is that it cannot. :)

Seems to me that this last question is really only appropriate if using memory buffers as opposed to PB strings etc. In which case compare the original buffer with the newly created Unicode string. That will tell you if the original buffer held a Unicode string or not. Other than that, determining whether an arbitrary buffer contains a Unicode string is notoriously difficult.

Re: PokeS questions

Posted: Tue Feb 23, 2010 6:57 pm
by SFSxOI
srod wrote:1. Unsure what you mean exactly?

2. Providing you have a memory buffer of the correct length, is PokeS() ever going to fail?

3. Well PokeS() assumes that the given source string is Ascii encoded if you are running without the Unicode switch and Unicode encoded otherwise. The question of whether ExeName$ is Ascii encoded, within the context of the code you posted, is thus irrelevant and not really appropriate. I mean, how can it contain an Ascii string if running in Unicode etc? The answer is that it cannot. :)

Seems to me that this last question is really only appropriate if using memory buffers as opposed to PB strings etc. In which case compare the original buffer with the newly created Unicode string. That will tell you if the original buffer held a Unicode string or not. Other than that, determining whether an arbitrary buffer contains a Unicode string is notoriously difficult.

Just wanted an assurance there was no differences in operation between 64 bit and 32 bit here. I found my answer though, there isn't.

The app can be compiled as ascii and not unicode. So if I feed it something for ExeName$, how do I ensure that ExeName$ was ascii to begin with if i don't know to begin with? Its not the complillation thats the question, the app is compiled ascii, but the ExeName$ can vary between ascii and unicode, so how does one determine which it is? The API still requires a unicode string regardless of the compillation, but the input to the program can contain either ascii or unicode. If I feed it unicode I don't need the conversion, if its fed ascii then the conversion is needed. So I need to determine at the beginning if its being fed ascii or unicode.

Re: PokeS questions

Posted: Tue Feb 23, 2010 7:18 pm
by srod
Your question does not make sense to me. If you are compiling in Ascii mode then ALL Purebasic strings can really only hold Ascii strings. If you attempt to place a Unicode character array into such a string variable and that array happens to contain an Ascii character, then the string will terminate at that character (because the high byte will be zero and this zero will terminate an Ascii string variable).

If you are compiling in Ascii and the api function requires a Unicode string - then make the conversion. If you are compiling in Unicode; don't make the conversion. Conditional compilation can sort this out.

Re: PokeS questions

Posted: Tue Feb 23, 2010 7:25 pm
by SFSxOI
srod wrote:Your question does not make sense to me. If you are compiling in Ascii mode then ALL Purebasic strings can really only hold Ascii strings. If you attempt to place a Unicode character array into such a string variable and that array happens to contain an Ascii character, then the string will terminate at that character (because the high byte will be zero and this zero will terminate an Ascii string variable).

If you are compiling in Ascii and the api function requires a Unicode string - then make the conversion. If you are compiling in Unicode; don't make the conversion. Conditional compilation can sort this out.

The app its self can hold only ascii strings internally to the app. But its just not the app its self, the app receives input from external sources and this input can be either ascii or unicode. So I wanted to determine if what the app was being fed was either ascii or unicode.

Re: PokeS questions

Posted: Tue Feb 23, 2010 7:44 pm
by SFSxOI
Nevermind, got it figured out sort of. The main difference between ASCII and Unicode is that ASCII uses one byte to represent each character and the Unicode format uses 2 bytes. So based upon that, i'm going to test the characters for size (1 or 2 bytes)

Re: PokeS questions

Posted: Tue Feb 23, 2010 7:55 pm
by djes

Re: PokeS questions

Posted: Tue Feb 23, 2010 7:59 pm
by SFSxOI
well, i was wrong, can't do it that way after all.

Re: PokeS questions

Posted: Tue Feb 23, 2010 8:00 pm
by djes
You are the faster reader I've ever met! :shock: :mrgreen:

Re: PokeS questions

Posted: Tue Feb 23, 2010 8:05 pm
by Demivec
Why not transfer strings always in UTF8? This should allow you to test their contents for Unicode or Ascii when they are translated.

Re: PokeS questions

Posted: Tue Feb 23, 2010 9:35 pm
by srod
The app its self can hold only ascii strings internally to the app. But its just not the app its self, the app receives input from external sources and this input can be either ascii or unicode. So I wanted to determine if what the app was being fed was either ascii or unicode.
Well, even so, you cannot stuff a Unicode string into a PB string variable when compiling in Ascii mode for the aforementioned reasons. For this you should work with memory buffers and not PB string variables.

Re: PokeS questions

Posted: Tue Feb 23, 2010 10:40 pm
by SFSxOI
djes wrote:You are the faster reader I've ever met! :shock: :mrgreen:
actually i was already reading it and almost finished by the time of your post.

Re: PokeS questions

Posted: Tue Feb 23, 2010 10:42 pm
by SFSxOI
Demivec wrote:Why not transfer strings always in UTF8? This should allow you to test their contents for Unicode or Ascii when they are translated.
because these are other third paty applications and items sending the data and i don't control how they send it.

Re: PokeS questions

Posted: Tue Feb 23, 2010 10:43 pm
by SFSxOI
srod wrote:
The app its self can hold only ascii strings internally to the app. But its just not the app its self, the app receives input from external sources and this input can be either ascii or unicode. So I wanted to determine if what the app was being fed was either ascii or unicode.
Well, even so, you cannot stuff a Unicode string into a PB string variable when compiling in Ascii mode for the aforementioned reasons. For this you should work with memory buffers and not PB string variables.
Yes, thats what i'm going to do.

Re: PokeS questions

Posted: Thu Feb 25, 2010 1:29 pm
by Trond
You cannot know whether a memory buffer is unicode or ascii. So you'll simply have to find out once and for all how the other program sends its data.