Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Out of memory error on call to Graphics.FromHdcInternal

Posted on 2006-06-29
7
Medium Priority
?
847 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
[X]
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
  • 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

715 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