Solved

Out of memory error on call to Graphics.FromHdcInternal

Posted on 2006-06-29
7
804 Views
Last Modified: 2012-08-13
I'm working on an application that is passed an HDC from a COM method (the HDC is passed in as a 32-bit long integer.  When I call the static method Graphics.FromHdcInternal method while debugging I get an out of memory error thrown (this works fine when running compiled code).  I'm using C# with .net 2.0 (I found there was a bug in .net 1.1 but I assume they fixed it for 2.0).  Has anyone seen this and do they know a way around it?  Is there some setting I need to change?  

SSB
0
Comment
Question by:SideShowBob233
  • 2
  • 2
7 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 17015708
Please show your code.
BTW, why don't you use Graphics.FromHdc?
0
 

Author Comment

by:SideShowBob233
ID: 17018582
It's fairly complex code I don't want to post....but here's a simplified summary (after making the change to use FromHdc -- I'm not very familiar with the graphics classes and I chose the wrong function -- the docs say not to call FromHdcInteral) -- but when I change to FromHdc I get the same error.  As a note the HDC passed in is from a different process (I'm making a call into an out of process ActiveX EXE in VB which is calling my C# class via COM interop).  Is it not possible to use the HDC
from another process (and maybe that's the problem)?  

[ComVisible(true)]
public void MyFunction(int HDC, bool reTry)
{
    Graphics g = Graphics.FromHdc((IntPtr)HDC); //<-- this triggers an out of memory error
}

0
 

Author Comment

by:SideShowBob233
ID: 17018638
It looks like the out of process component is the problem -- I did some googling and it looks like HDCs are not marshaled by COM so you can't use them.  Although if you can confirm this that would be great (or if you know of any way to work around this).

SSB
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 17018867
I don't think that it is possible to pass HDC between processes. Try HWND and Graphics.FromHwnd.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now