The Artima Developer Community
Sponsored Link •

C# Answers Forum
Win API HELP passing a text ref

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Marl Atkins

Posts: 1
Nickname: matkins
Registered: May, 2006

Win API HELP passing a text ref Posted: May 17, 2006 5:20 PM
Reply to this message Reply
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;
		}

Topic: mdi parent form Previous Topic   Next Topic Topic: C# Code Converter

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use