0

I built up a module that creates a window with an edit box from windows' EDIT windowclass. It is designed to only work with ansi character set and not using any unicode.

I make use of EM_GETHANDLE to recieve the buffer to the edit control.

Now here is my problem: (quoted from link above)

Note For Comctl32.dll version 6, the buffer always contains an array of WCHARs, regardless of whether an ANSI or Unicode function created the edit control. For more information on DLL versions, see Common Control Versions.

So when my module gets loaded by an application that has comctl32 initialized, my whole code breaks.

My Question: Is there a way to prevent CreateWindowA to use comclt32 or does anyone have an idea to fix this problem?

Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
typ1232
  • 5,535
  • 6
  • 35
  • 51
  • Your answer for prevention is in the quoted text. What's so problematic with Unicode, especially if you're not going to support it in full anyway? Just throw away or ignore what you cannot handle or better yet give the user an error message when they enter something that you don't want to handle, e.g. non-ASCII chars. – Alexey Frunze Feb 11 '13 at 12:26

1 Answers1

1

The application uses COMCTL32.DLL if it is specified in the app's manifest as described e.g. here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb773175%28v=vs.85%29.aspx

If your module is DLL, then you might try use some isolation technique so it does not rely on what version of COMCTL32.DLL the .exe decided to use, but that might bring many other drawbacks.

I recommend to use WM_GETTEXTA or GetWindowTextA() instead, which will copy converted string into your buffer. Designing a module which requires old version of a DLL to work correctly is simply bad idea.

mity
  • 2,299
  • 17
  • 20
  • Thanks for your answer. I need to use `EM_GETHANDLE`, because I use that handle to access the control's buffer directly and also write to it (I know that I may not do this!). I guess I need to use CreateWindowW for the edit control to resolve my problem. – typ1232 Feb 11 '13 at 12:37
  • Alternatively, use `IsWindowUnicode()` to determine whether the Edit window was created by `CreateWindowA()` or `CreateWindowW()` and then adjust your buffer logic to use `CHAR` or `WCHAR` accordingly. – Remy Lebeau Feb 11 '13 at 18:13