Re: String between unmanaged and managed

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



What are you trying to do? Get some text from a button and send it to another process?

I'm trying to do just that

Just get and pass the string.

I have tried, the problem is that I always receive an invalid string,
even if TB_GETBUTTONTEXT return the correct length, so I pass to the
next process an invalid and always random string (I'm sure that the
problem is a related to the text format, non at all, because of
randomness on vaues received.

Andrea

<ctacke/> ha scritto:

Why not back up and tell us the big picture. What are you trying to do?
Get some text from a button and send it to another process? If that's the
case, I have no idea why you're trying any of these crazy, completely
invalid steps. Just get and pass the string.

-Chris


<andrerus@xxxxxxxxx> wrote in message
news:1159015719.315767.112980@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm not able to use debugger, because the function that contain the
code will be executed by a process different from test application
(don't forget that it's a DLL, and it is used to inoculate wndproc to
another application), and breakpoints in that portion of code are
ignored. A test that I made was instead to post different messages if
received text was equal or not to a constant string, (I tried using
LPWSTR and LPSTR): the received string is always different from
constant one. Also the length is different from expected: the
sendmessage result is 6, that is correct, but the length of receiving
buffer is 1 or 2, always random, this means for me that the button
responds reading wrong memory (fact that could explain the random
value), and that the passing from unmanaged to managed is correct.
I tried also using TB_GETBUTTONINFO, but nothing change.

Any other idea?

Thank you for your precious help,

Andrea


Paul G. Tobey [eMVP] ha scritto:

Look at the string (as char[]), in the debugger. If every other byte is
a
zero, it's Unicode. If that's the case, don't do anything to it; just
pass
it to PostMessage.

You're doing crazy stuff there. Why would you shift the first value by
16
bits? Let's fix the real problem, which is at the point where the string
is
extracted from the toolbar, then worry about the next step.

Paul T.

<andrerus@xxxxxxxxx> wrote in message
news:1158942075.713385.154630@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I supposed that, but the documentation of TB_GETBUTTONTEXT talk about
LPSTR, not LPWSTR.

However, I also tried to not convert it, and to declare text (the
buffer) as LPWSTR, but nothing changes.
The last test I make was to declare text as wchar_t*, and to post the
first four chars as int
obtaining WPARAM as (text[0]<<16) + text[1] and so on with LPARAM.
Reading them from managed side I obtain different and random values,
why this?

Andrea

Paul G. Tobey [eMVP] ha scritto:

Getting the text for a button, a window, or practically anything else
in
Windows CE returns a Unicode string, *not* an ASCII string. You need
to
learn about what that means. Then you'll see that your message sent
to
the
toolbar window returns a Unicode string, which you then damage
severely
by
running it through your conversion function before using PostMessage
to
send
it.

Paul T.

<andrerus@xxxxxxxxx> wrote in message
news:1158939440.935261.261600@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,
Some were I found this function:

LPCWSTR LPCSTR_2_LPCWSTR(const char* inString)
{
int len = strlen(inString) + 1;
wchar_t *outString = new wchar_t[len];
mbstowcs(outString, inString, len);
return (LPCWSTR) outString;
}

Now I have to post a message containing text (as wParam) from an
unmanaged part to a managed one.
I do something like this:

#unmanaged1
PostMessage(destHwnd, myMsg, (WPARAM) LPCSTR_2_LPCWSTR("string"),
0);

#unmanaged2
...
LPSTR text = new char[256];
SendMessage(toolbarHwnd, TM_GETBUTTONTEXT, wID, text);
PostMessage(destHwnd, myMsg, (WPARAM) LPCSTR_2_LPCWSTR(text), 0);


#managed
...
string s = Marshal.PtrToStrUni(m.WParam);

In case unmanaged1 I always receive correct string, instead in case
unmanged2 never.

I'm becoming crazy!!!

Andrea




.


Quantcast