I've just upgraded HtmlRenderer from version 1.4 to the latest 1.5.0.5. I immediately got the problem that instances of HtmlLabel rendered wrong all over my application when I run it in debug mode through Visual Studio 2010. If I run the application outside (still the debug build), it works fine. I traced this down to the an issue in the layout, where the method Win32Utils.GetTextMetrics (in GraphicsAdapter.MeasureString) throws an exception.
Looking at the declarations in Win32Utils, I made the following changes, which solved my problems:
```
[DllImport("gdi32.dll", EntryPoint = "GetTextMetricsW", CharSet = CharSet.Unicode)]
public static extern bool GetTextMetrics(IntPtr hdc, out TextMetric lptm);
```
```
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct TextMetric
{
public int tmHeight;
...
```
I did try to make a small test application to illustrate the problem, but that did however not exhibit this behavior. Also, I 'only' did the test on one computer, running Windows 7, 64 bit.
I hope this makes sense to you and that these or similar changes can be incorporated in the official build of HtmlRenderer.
Last, but not least, thanks for a great library. I look forward to working with all the new features.
Comments: Indeed strange. Thanks for including the fix even though it may only affect very few. Being curious, I tried a simple test declaring the TextMetric 4 times. One without the CharSet set, one with CharSet.Auto, one with CharSet.Ansi and one with CharSet.Unicode. I then used Marshall.SizeOf to get the size of each structure and with the following results: None: 56 bytes Auto: 60 bytes Ansi: 56 bytes Unocode: 60 bytes So it seems that leaving out the CharSet parameter will make the structure default to Ansi rather than Auto, which I would have imagined. The test were done on a Windows 7, 64 bit, and gave the same results debugging from within VS2010 and running outside VS.
Looking at the declarations in Win32Utils, I made the following changes, which solved my problems:
```
[DllImport("gdi32.dll", EntryPoint = "GetTextMetricsW", CharSet = CharSet.Unicode)]
public static extern bool GetTextMetrics(IntPtr hdc, out TextMetric lptm);
```
```
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct TextMetric
{
public int tmHeight;
...
```
I did try to make a small test application to illustrate the problem, but that did however not exhibit this behavior. Also, I 'only' did the test on one computer, running Windows 7, 64 bit.
I hope this makes sense to you and that these or similar changes can be incorporated in the official build of HtmlRenderer.
Last, but not least, thanks for a great library. I look forward to working with all the new features.
Comments: Indeed strange. Thanks for including the fix even though it may only affect very few. Being curious, I tried a simple test declaring the TextMetric 4 times. One without the CharSet set, one with CharSet.Auto, one with CharSet.Ansi and one with CharSet.Unicode. I then used Marshall.SizeOf to get the size of each structure and with the following results: None: 56 bytes Auto: 60 bytes Ansi: 56 bytes Unocode: 60 bytes So it seems that leaving out the CharSet parameter will make the structure default to Ansi rather than Auto, which I would have imagined. The test were done on a Windows 7, 64 bit, and gave the same results debugging from within VS2010 and running outside VS.