Hello, I am trying to call GetTextOut from C#, and am having problems. When the code below runs, only the first character is drawn, and I eventually get a stack exception:
ArrayList oWidths = _getCharSpacing( p_hDC, sOutput, p_iMaxWidth, bIsMulti );
IntPtr hPtr = Marshal.AllocHGlobal( oWidths.Count );
for( int iIndex = 0; iIndex < oWidths.Count; iIndex++ )
{
Marshal.WriteInt32( hPtr, iIndex, (int)oWidths[iIndex] );
}
// ExtTextOut declared as IntPtr, int, int, int, IntPtr, string, int, IntPtr
GDI.ExtTextOut( p_hDC, oRect.Left, oRect.Top, 0, IntPtr.Zero, sOutput, sOutput.Length, hPtr );
Marshal.FreeHGlobal( hPtr );
Can anyone out there help me?
Thanks in advance,
- Ken
Christian Ehlscheid - 07 Jun 2005 22:06 GMT
Hello,
i think your Marshal code is incorrect ..
> IntPtr hPtr = Marshal.AllocHGlobal( oWidths.Count );
this will allocate oWidths.Count bytes .. but i think you'll want
oWidths.Count * 4 (size of an integer)
> Marshal.WriteInt32( hPtr, iIndex, (int)oWidths[iIndex] );
the second paramter is a byte offset, not an index into a Int32 array
change it to
Marshal.WriteInt32(hPtr,iIndex*4,(int)oWidths[iIndex]);
you'll got the exception cause your previous code did write past the buffer
you've allocated ..
Regards
Christian
Christian Ehlscheid - 07 Jun 2005 22:11 GMT
> you'll got the exception cause your previous code did write past the buffer
> you've allocated ..
past, presence and future all messed up in one sentence ... *G* ...