Marl Atkins
Posts: 1
Nickname: matkins
Registered: May, 2006
|
|
Win API HELP passing a text ref
|
Posted: May 17, 2006 5:20 PM
|
|
|
Advertisement
|
Hi:
I'm trying to use the Win API SendMessage with WM_GETTEXT to get the text data filled into a string, in C# .NET
The code below doesn't work. I'm sure it's because the ref text argument is wrong.
How do I pass an IntPtr to an API function that is a pointer to a string so the function can fill it with data?
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint wMsg, IntPtr wParam, ref string lParam);
private static string GetControlText(int hwnd)
{
string text = "";
int strLen = SendMessage((IntPtr)hwnd, WM_GETTEXTLENGTH, (IntPtr)0, ref text);
if(strLen > 0)
{
string sBuff = new String('\0', strLen + 1);
strLen += 1;
int retVal = SendMessage((IntPtr)hwnd, WM_GETTEXT, (IntPtr)strLen, ref sBuff);
if(strLen == retVal)
{
text = sBuff;
}
}
return text;
}
|
|