Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Out of memory error on call to Graphics.FromHdcInternal

Posted on 2006-06-29
7
Medium Priority
?
860 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
4 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

824 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