Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / June 2005

Tip: Looking for answers? Try searching our database.

ExtTextOut interop question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kenneth larson - 07 Jun 2005 20:41 GMT
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* ...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.