Re: SendMessage and WM_GETTEXT

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Peter Huang (v-phuang_at_online.microsoft.com)
Date: 11/19/04

  • Next message: DotNetFundoo: "system.runtime.interopservices.comexception"
    Date: Fri, 19 Nov 2004 05:44:11 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

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


  • Next message: DotNetFundoo: "system.runtime.interopservices.comexception"

    Relevant Pages

    • Re: VC++ and WinNT Problem
      ... >>ANSI vs. Unicode API calls is determined by the compiler, ... didn't think it was worth mentioning - i.e. any decent Windows ... otherwise they resolve to ANSI functions. ... > It's very possible to do so with any Win32 compiler. ...
      (comp.lang.cpp)
    • Re: Determining entry point (Unicode or ANSI) chosen at runtime
      ... >Platform invoke chooses between ANSI and Unicode formats at run time, ... >on the target platform. ... The default is Unicode on Windows NT, Windows 2000, Windows XP, and ... tell elsewhere in my code whether the ANSI or Unicode version of the function ...
      (microsoft.public.dotnet.framework.interop)
    • Re: Need help with CABWIZ
      ... Even if you're not sure whether the Japanese versions of Windows Mobile 5 and Windows XP and Visual Studio 2005 give me Japanese glyph support or not, I already quoted some of the registry keys in the device and provided a screenshot. ... ANSI code page 932 has been used by Microsoft in this country for more than 20 years. ... characters - it can support them, but having Unicode doesn't simply give you Japanese glyph support. ...
      (microsoft.public.pocketpc.developer)
    • Re: Lazarus vs. Delphi
      ... AFAIK machen andere Plattformen keine Unterscheidung zwischen Unicode und Ansi, so wie Windows das macht. ...
      (de.comp.lang.delphi.misc)
    • Re: Call C DLL from VB.net-problem..array gains 4 bytes!
      ... No, Unicode strings don't, by definition, have a header with the size. ... you're writing code in C++, for example, the only difference between an ANSI ... which take an array of bytes. ... > Remember the DLL declaration... ...
      (microsoft.public.windowsce.app.development)