Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2004

Tip: Looking for answers? Try searching our database.

SendMessage and WM_GETTEXT

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dennis C. Drumm - 17 Nov 2004 21:27 GMT
I am programming in C# and am not sure how to supply the last parameter
(LPSTR) in the SendMessage function with the WM_GETTEXT option.

Do I need to use unsafe code and how do I get the pointer and pass it to the
SendMessage function to get the text that it contains?

Thanks,

Dennis
Dennis C. Drumm - 17 Nov 2004 23:24 GMT
Sorry, I forgot to mention, I'm trying to get the text from an Edit control.

Thanks,

Dennis
"Peter Huang" - 18 Nov 2004 02:38 GMT
Hi

Here is a link you may take a look.

http://groups.google.com/groups?hl=zh-CN&lr=&c2coff=1&threadm=547d53de.04012
12016.19c70890%40posting.google.com&rnum=1&prev=/groups%3Fq%3DSendMessage%25
20WM_GETTEXT%2520%2522C%2523%2522%26hl%3Dzh-CN%26lr%3D%26c2coff%3D1%26sa%3DN
%26tab%3Dwg

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Dennis C. Drumm - 18 Nov 2004 22:28 GMT
Peter:

Thanks and I should have did the same thing on Google first.

One question: when I use CharSet = CharSet.Ansi in the dllImport statements
everything works fine, but when I switch to CharSet.Unicode or Auto it
doesn't. How come?

I haven't looked into this yet, but I think if the application is going to
be distrubuted in ohter languages, we must use Unicode.

Dennis

> Hi
>
[quoted text clipped - 13 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
"Peter Huang" - 19 Nov 2004 05:44 GMT
Hi

Usually win32 API has two versions. ansi version or unicode version.
e.g.
SendMessageA is Ansi version
SendMessageW is unicode version.

Because the declare in the google link has define the entrypoint as
SendMessageA, that means to use the ansi version.
For detailed information you may try to take a look at the
DllImportAttribute Class and the DllImportAttribute.CharSet Field
DllImportAttribute.ExactSpelling Field.

Specifying a Character Set
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconcharsetobjectfield.asp

[DllImport("user32.dll")]
   public static extern int MessageBoxA(int hWnd, String text,
       String caption, uint type);
[DllImport("user32.dll", CharSet=CharSet.Unicode)]
   public static extern int MessageBoxW(int hWnd, String text,
       String caption, uint type);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
   public static extern int MessageBox(int hWnd, String text,
       String caption, uint type);

The example above will tell you what is the default conversion when using
CharSet.

Charset.Auto
Automatically marshal strings appropriately for the target operating
system. The default is Unicode on Windows NT, Windows 2000, Windows XP, and
the Windows Server 2003 family; the default is Ansi on Windows 98 and
Windows Me.

        [DllImport("user32.dll",CharSet=CharSet.Auto)]
        private static extern int SendMessage(IntPtr _WindowHandler, int
            _WM_USER, int wParam, [Out] StringBuilder windowText);
        private const int WM_GETTEXT = 0xD;
        private void button1_Click(object sender, System.EventArgs e)
        {
            int textSize = 1024;
            StringBuilder buffer = new StringBuilder ( textSize );
            SendMessage ( this.textBox1.Handle , WM_GETTEXT, textSize,
                buffer );
            MessageBox.Show(buffer.ToString());
        }

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Dennis C. Drumm - 19 Nov 2004 12:17 GMT
Thanks Peter,

By the way, when I search the MSDN docs (unfiltered) for SendMessageGetText
or SendMessageSetText it does not come up with anything. How is one
suppoesed to know about these functions and are they something that might
not be supported in the next version of ...?

Dennis

> Hi
>
[quoted text clipped - 54 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
"Peter Huang" - 22 Nov 2004 01:57 GMT
Hi

Actually there is no such function, it is just a customized name( we can
change to other), the really function it is called is determined by
EntryPoint attribute. If we did not use that attribute the CLR will try to
find the function based on the function name we define, but once we have
define it, it does not matter what function name we define, because the CLR
will try to find the function in the DLL based on the EntryPoint.

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

"Peter Huang" [MSFT] - 24 Nov 2004 03:09 GMT
Hi

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Dennis C. Drumm - 26 Nov 2004 12:14 GMT
Thanks Peter,

You responses were greatly appreciated, I'm all set now!

Dennis

> Hi
>
[quoted text clipped - 8 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.