Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Out of memory error on call to Graphics.FromHdcInternal

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best resource to learn entity framework 2 47
Printing 1 58
updating order of the rows, N+1 query issue, C#, asp.net, MVC, SQL Server 3 34
Hey!!!! 1 26
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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