Solved

Out of memory error on call to Graphics.FromHdcInternal

Posted on 2006-06-29
7
814 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

23 Experts available now in Live!

Get 1:1 Help Now