Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

SharpDX.Windows.RenderForm is not Unicode compatibility #185

Closed
ngocnl opened this issue Oct 27, 2013 · 5 comments
Closed

SharpDX.Windows.RenderForm is not Unicode compatibility #185

ngocnl opened this issue Oct 27, 2013 · 5 comments
Labels

Comments

@ngocnl
Copy link

ngocnl commented Oct 27, 2013

If I change game window title with a Unicode string "Tiếng Việt", the window title will become "Ti?ng Vi?t" (this error occurs after game is initialized).
Beside, if I handle Key_Press event of the window form, I will never get KeyChar with a Unicode character.

I think the problem comes from MessageFilterHook.cs when SharpDX call Win32Native.SetWindowLong to change WndProc of the window with a non-Unicode one.

In Win32Native.cs, the following DllImport lines:
[DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Ansi)]
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Ansi)]
should be modified CharSet = CharSet.Auto instead of CharSet.Ansi.

All other Win32Native functions should use CharSet.Auto too.

@ArtiomCiumac
Copy link
Contributor

Can you, please, post a project where the issue can be reproduced? I've tried to modify the MiniCube.Desktop sample to reproduce - but it works correctly as shown in this screenshot.

The DllImport.CharSet field specifies how the strings parameters are passed between unmanaged and managed code and it doesn't influence the RenderForm title.

I suppose you have a different usage scenario, so please provide more details about it.

@ngocnl
Copy link
Author

ngocnl commented Nov 2, 2013

Thanks for your comment. I am explaining in more details as below...

Method Update(GameTime gameTime) is called the first time before game run (see code). At this time, the statement { Window.Title = "Tiếng Việt"; } can change the window title correctly because the WndProc hasn't been changed.

Then, after WndProc is hooked, RenderForm becomes non-Unicode, but in next Update() calls, the statement { Window.Title = "Tiếng Việt"; } won't change the window title (see code) and you won't see the error in your sample.

If you modify the code of MiniCube.Desktop as following, you will reproduce the bug:

if (gameTime.TotalGameTime.TotalSeconds > 2) // change window title after 2 seconds
    { Window.Title = "Tiếng Việt"; }

ArtiomCiumac added a commit that referenced this issue Nov 2, 2013
@ArtiomCiumac
Copy link
Contributor

Thank you for explanation. It should be fixed now. Once the changeset above will get into master branch - it will be integrated into latest dev package.

@ngocnl
Copy link
Author

ngocnl commented Nov 3, 2013

Thanks for your update but I see that the bug won't be fixed if Win32Native.CallWindowProc is still using Ansi version.

I think all other classes, structs, functions... mapped from Win32 API with 2 versions Unicode & Ansi should use CharSet.Auto or CharSet.Unicode also.

For examples:
class Win32Native.LogFont is mapped from struct LOGFONTA / LOGFONTW (lfFaceName can be a Unicode string)
struct Win32Native.TextMetric is mapped from struct TEXTMETRICA / TEXTMETRICW (SharpDX is using CharSet.Unicode for this struct)
function Win32Native.CallWindowProc is imported from CallWindowProcA / CallWindowProcW
function Win32Native.GetModuleHandle is imported from GetModuleHandleA / GetModuleHandleW (lpModuleName can be a Unicode string)

Function GetFocus does not require CharSet, then we can delete this attribute.

@ArtiomCiumac
Copy link
Contributor

While it is a good idea to fix these, I am not sure if it is worth to make these changes blindly without a good test case. Thank you for pointing out these issues, I will look into them as soon as will find some time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants