Re: Problem with GetTextMetrics and Unicode

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

From: John Carson (donaldquixote_at_datafast.net.au)
Date: 01/07/05


Date: Fri, 7 Jan 2005 11:52:37 +1100


"Mark Hatsell" <mark.hatsell@btinternet.com> wrote in message
news:%23WnkRtD9EHA.3376@TK2MSFTNGP12.phx.gbl
> Hello
>
> I am in the process of converting one of my apps to Unicode and have
> run into a problem with GetTextMetrics. Whenever I call
> GetTextMetrics in my Paint function I get a runtime error when the
> function exits stating that the stack has been corrupted around the
> 'textmetrics' variable. This happens when running the app in the
> Visual Studio debugger. If I run the app outside of the debugger I
> get an 'Unhandled Exception' error and the app closes. The
> GetTextMetrics call returns with a sucessful return value. The
> offending code is very simple:
> TEXTMETRIC textmetrics;
> GetTextMetrics(hdc, &textmetrics);

So if you have a program that does nothing except call these two lines,
e.g., a window procedure of

LRESULT CALLBACK WndProc
(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    if(message == WM_PAINT)
    {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hwnd, &ps);

        TEXTMETRIC textmetrics;
        GetTextMetrics(hdc, &textmetrics);

        EndPaint(hwnd, &ps);
        return 0;
    }
    else
        return DefWindowProc (hwnd, message, wParam, lParam) ;
}

then you get corruption? I don't think so. The problem is elsewhere in your
program.

Two possibilities occur to me.

1. The problem is in the use you make of textmetrics.
2. The problem is that some other part of your program is writing where it
shouldn't (e.g., beyond the last element in an array) and the Unicode
version has problems simply because the Unicode version takes up more space
and is therefore more likely to overlap the area where the illegal writing
is taking place.

-- 
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead) 


Relevant Pages

  • Problem with GetTextMetrics and Unicode
    ... Whenever I call GetTextMetrics in my ... the stack has been corrupted around the 'textmetrics' variable. ... when running the app in the Visual Studio debugger. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Why C#? CPU independent?
    ... my app is very UI intensive. ... such as VB and MFC. ... his program's load time became four seconds. ... WinMo only supports Unicode. ...
    (microsoft.public.pocketpc.developer)
  • Getting UNICODE characters from wcin in a Console app
    ... Can anyone explain why I can't get Unicode code points out of what I ... type into a console app? ... Clearly that's because the console I'm running the app in is in the ...
    (microsoft.public.vc.language)
  • Unicode
    ... Can anyone please answer me the following questions on unicode apps? ... I'm building an application that needs to interact with BSTRs, ... functions I'm building to accept MBCS strings, i.e. it needs to convert them ... * my app would function ok if distributed as a whole, ...
    (microsoft.public.vc.language)
  • Re: Populating CString in Win32 dll interface that accepts LPCTSTR
    ... and I want a string to be populated by calling this inside a UNICODE ... CString str; ... If your app is Unicode, and your DLL returns 8-bit characters, you would declare ...
    (microsoft.public.vc.mfc)