How to release an object created from GdipCreateBitmapFromHBITMAP?

I'm writing a C application and in my code I'm calling the constructor GdipCreateBitmapFromHBITMAP.

I know the constructor should not be called from C, but I used a "hack" from here "How can I take a screenshot and save it as JPEG on Windows?"

I'm not sure how to release resources that were allocated during the call to GdipCreateBitmapFromHBITMAP.

I tried finding help in the documentation but found nothing.

ULONG *pBitmap = NULL; lGdipCreateBitmapFromHBITMAP = (pGdipCreateBitmapFromHBITMAP)GetProcAddress(hModuleThread, "GdipCreateBitmapFromHBITMAP"); lGdipCreateBitmapFromHBITMAP(hBmp, NULL, &pBitmap);

How to I release pBitmap?

Thanks a lot.

-------------Problems Reply------------

What you are doing is not a "hack". Although GDI+ is primarily designed to be used in C++, it does expose a flat API for use in C. Your code is using that API. GdipCreateBitmapFromHBITMAP() is not a constructor, it is a flat C function that is called by the Bitmap.Bitmap(HBITMAP, HPALETTE) constructor.

That being said, GdipCreateBitmapFromHBITMAP() returns a pointer to a GpBitmap object (which is wrapped by the Bitmap class in C++). GdipDisposeImage() is the correct way to release that object (which is called by the Image destructor in C++).

struct GpImage {};
struct GpBitmap {};
typedef GpStatus (WINGDIPAPI *pGdipCreateBitmapFromHBITMAP)(HBITMAP, HPALETTE hpal, GpBitmap**);
typedef GpStatus (WINGDIPAPI *GdipDisposeImage)(GpImage *image);

GpBitmap *pBitmap = NULL;
lGdipCreateBitmapFromHBITMAP = (pGdipCreateBitmapFromHBITMAP) GetProcAddress(hModuleThread, "GdipCreateBitmapFromHBITMAP");
lGdipDisposeImage = (pGdipDisposeImage) GetProcAddress(hModuleThread, "GdipDisposeImage");
lGdipCreateBitmapFromHBITMAP(hBmp, NULL, &pBitmap);

Category:c# Views:3 Time:2018-04-13

Related post

  • Can I release an object (created in a method) in another method (without retaining) in objective C? 2010-11-23

    Can i release an object (created in a method) in another method (without retaining) in objective C ? My code is as follows -(NSMutableDictionary *)returnningMyMutableDictionary{ NSMutableDictionary *myDict = [[NSMutableDictionary alloc] init]; [myDic

  • PHP OOP: Iterate over all objects created from a class 2011-11-27

    I want to create a <select> field from all Gender objects. Is there a way to iterate over all the objects created from the class of Gender? class Gender { public static $counter = 0; public $id; public $gender; public function __construct($gend

  • How to call an object created in a module 2012-03-21

    I have a problem with class in Python. I'd like to know how to call an object created in a module in other python program. Let me show an example. I have these object in "" file def objectCase(): object1 = class_name("object1") object2

  • Error when trying to insert object, Create from file 2013-08-14

    Powerppint 14.1.2 (110505) I am attempting to link several powerpoints together by inserting objects, creating from file. Every time I try to insert the object, which is a powerpoint saved on my hard drive, i get the error: The server application, so

  • How do i access objects created in .cpp from the dialog.cpp and vice verse in mfc? 2011-07-18

    when i create a mfc app, the following 2 files are created there a calDlg.cpp (all the clickOK etc functions) and a cal.cpp (with its .h)(which i intend to create objects like timer and other stuff there) just wondering how can i access the objects c

  • how to release an object which use copy keyword in iOS program 2011-06-05

    In my program, I tried to set object in an dictionary. Values are coming from another class, so I copied those values before processing it. While analyzing the code I got leaks. -(void)giveInput:(NSString *)userInput ForPlaceholder:(NSString *)placeh

  • how to release cocos2d objects? 2011-06-21

    I am doing as follows -(void)Play { [CCDirector setDirectorType:kCCDirectorTypeDisplayLink]; CCDirector *director = [CCDirector sharedDirector]; //[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft]; [director setAnimationInterval:1.0/6

  • Retrieving key from new object created from create_object using Django generic views 2009-05-11

    My code looks as such: def add_cart(request): return create_object(request, form_class=CartForm, post_save_redirect=reverse('test.views.show_cart', kwargs=dict(object_id='%(key)s'))) Ideally, I would like it to look like so: def add_cart(request): ne

  • How to remove an object literals from an array of object literals by object 2011-09-05

    What is the most general methodology (possibly in javascript) to remove an "object literal" from an array of "objects literal", I mean how to determine what the index of the object to be removed is. The keys are the same, only the values can change.

  • how to release the object while after adding it as subview to the main view? 2011-11-16

    I am using two view controllers. On button action of first view controller i am adding the second view controller'sview as subview to the first view controller. I am not able to release the second view controller so i am getting memory leak for the s

  • How to detach an object graph from object context in Entity Framework without roundtrips to database? 2011-11-24

    The workflow of my app is quite simple: For a given bunch of scripts take a script parse it get corresponding object graph from db update it or create new if no graph found save changes detach graph from object context for GC could kill the graph The

  • I want to add new property to object created from array 2012-01-10

    I am creating response from objects return from MySQL result $q=mysql_query("SELECT userid,fullname FROM users"); while($r=mysql_fetch_objects($q)){ $ar[]=$r; } echo json_encode($ar); Here $r has two properties userid and fullname. Now I want to add

  • How to put the flyer created from word and spreadsheets from excel to powerpoint? 2012-10-06

    I made a flyer using my Microsoft Office Word 2007 and a spreadsheet using Excel 2007 and I would like to know how to put it on my Powerpoint 2007. Can anyone help? --------------Solutions------------- Open PowerPoint. Click on the Insert tab. Select

  • Cannot call COM object created from STAThread from oher STA threads 2010-02-01

    I am new to COM and trying to understand the difference between STA and MTA. I tried to create an example that would show that COM can manage calls to object created in STA that is not thread-safe. MyCalcServer class here is created using ATL Simple

  • How to dispose the objects created by factory pattern 2010-04-19

    I am using Factory pattern to create .NET objects of a class. I also need to make sure that all such objects should be disposed before application terminates. Where and How can I dispose the objects created by factory pattern? Shall I dispose in the

  • iphone: use Entity object created from Core Data? 2010-09-08

    I currently have a Video object created via Core Data defined as: Video .h #import <CoreData/CoreData.h> @interface Video : NSManagedObject { } @property (nonatomic, retain) NSString * title; @property (nonatomic, retain) NSString * urlImage; @

  • Serialization of Java object created from external API 2011-03-10

    I have an object passed from an API call. Now I tried to send this object using ObjectOutputStream, but the class does not implement Serializable. I can't edit the class to make it implement Serializable, since that API and class is not written by me

  • How to make a object create another object 2011-03-24

    As in the title how do I go about creating a object which creates another object? The object is simply supposed to replicate itself so like I call on this class to replicate itself the objects don't have to be different just that it creates another o

  • Django : How to retrieve latest object created 2011-10-12

    I want to retrieve the latest object created for a particular user. Say i have a model class LogBookPreTransaction(models.Model): person = models.ForeignKey(User) code = models.CharField(max_length=20) address = models.CharField(max_length=200,null =

  • Rails difference in object created from a .find(:id) and .where() methods 2011-11-08

    What is the difference in the objects created with these 2 methods: tec = Technique.find(6) tec2 = Technique.where(:korean => 'Jok Sul') The data returned for each is exactly the same, yet the first object will respond perfectly to an inherited me

  • Spotify List objects created from localStorage data come up blank 2012-03-15

    I'm working on a Spotify app and trying to create a views.List object from some stored information in our database. On initial load, a POST is made to get the necessary info. I store this in localstorage so each subsequent request can avoid hitting t

  • How to remove the object tag from my HTML using Java 2011-03-22

    Hi I am trying to remove the object tag from my HTML content using Java so that I can render the HTML in devices which do not support Flash <object classid="clsid:F08DF954-8592-11D1-B16A-00C0F0283628" id="Slider1" width="100" height="50"> <p

  • How do you manage releasing an object created in an instance method on iPhone without autorelease? 2010-02-11

    I'm fairly new to iPhone development and I've hit a roadblock in my understanding of memory management. I've read through the Memory Management Guide for Cocoa and have read many, many questions and answers on SO, but have not found a complete answer

  • How to remove whitespace from XElement object created from XElement.ReadFrom(XmlReader) 2010-02-17

    I am parsing a large xml file. So I am using an XmlReader in combination with XElement instead of XElement.Load(). I have created as XElement object from XmlReader as shown below and here. static IEnumerable<XElement> StreamRootChildDoc(string

  • How to release an object from an Array? 2011-01-11

    I am currently working on an demo app so I was a little sloppy how to get things done, however I run the "Build and Analyze" to see how many leaks I get,... well and there are a lot. Source of teh proble is that I have a NSMutableArray and I add some

Copyright (C), All Rights Reserved.

processed in 0.103 (s). 11 q(s)