Passing binary data as a (unicode) string to API is converted and doesn't work 
Author Message
 Passing binary data as a (unicode) string to API is converted and doesn't work

I'm using VB5.

I'm trying to pass binary data to the waveOutPrepareHeader function. This
function takes a WAVEHDR structure which contains an element which is a
pointer to a block of memory.

I have this block of memory set up as a variable-length string member of
the structure. The VB manual says that this will make a pointer to the
string be passed in the structure. Exactly what I want.

Well, that's what happens, except that VB takes it upon itself to convert
this string from Unicode to ASCII when it is passed to the API, and since
most of the byte-pairs are > 255, I wind up passing the string
"??????????????????????..." since VB converts these byte-pairs to question

Okay, so I thought "I'll stick a zero between every pair." Now I get the
correct translation, but unfortunately VB sticks the translation in the
*second half* of the passed string, but *sends something else in the first
half of the string.* The string is as long as the unicode string was, but
twice as long as it should be using ASCII.

In other words, I try to pass:

 65 0 66 0 67 0

but what is actually passed is:

 <> <> <> 65 66 67

where <> <> <> is part of the original string I think. (But I'm not sure. I
suspect that it is the second half of the original string, the 0 67 0,
because it sounds like it (since I am playing this data through my
speakers.)) But the pointer to this string VB *actually* passes doesn't
point to the 65 66 67, it points to the whole <> <> <> 65 66 67!!! VB is
not passing the correct pointer to the un-unicoded string. The correct data
is always in exactly the second half of the string that is actually passed.

Unfortunately I can't send a byte array because the structure member needs
to be a pointer, and I can't pass a reference to something as a structure
member, although in can be done with regular parameters.

Has anyone experienced this before; does anyone have a workaround for it?
It seems to be a bug. Am I just simply screwed? I've racked my brain and
can't seem to make it work in any way at all. How can I get VB to send the
correct string?

Michael Baldwin

Sun, 09 Jan 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. convert binary data to string data

2. Converting an unicode string to ascii code string

3. Converting Binary data to String???

4. Unicode string to unicode coded string?

5. BinaryRead - howto convert binary string back to string array

6. combobox doesn't work w/Unicode

7. saving unicode string with fileput converts it to 8bit

8. Convert unicode string from latin to cyrilic

9. Convert Unicode String to Hex

10. HOW TO: Convert string between UNICODE and ANSI

11. convert a unicode string to a single byte

12. Unicode doesn't seem to be supported in VB5 controls


Powered by phpBB® Forum Software