473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

C# How can I implement iDisposable for P/Invokde?

Hi,

I'm using a third party C based DLL for some image manipulation.
I've noticed that my original wrapper class doesn't implement iDisposable, thus I cannot dispose the utility class at will.

I've trying to find a sample that will help me put this last piece in it's place but I'm unable to find any reference.

This is how this DLL is defined and used

Expand|Select|Wrap|Line Numbers
  1.  
  2. public sealed class ManipulateImageWrapper: IDisposable {
  3.  
  4. [DllImport("manipulateImage.dll", EntryPoint="ManipulateBitmap")]
  5. static extern Byte ManipulatrBitmap(IntPtr Bitmap1);
  6.  
  7. public string ImageManipulate(Bitmap iImage1) {
  8.     return (ManipulatrBitmap(iImage1.GetHbitmap()).ToString(); 
  9. }
  10.  
  11. #region IDisposable Members
  12.  
  13. public void Dispose() {
  14.     Dispose(true);
  15.     GC.SuppressFinalize(this);
  16. }
  17.  
  18. private void Dispose(bool disposing) {
  19. [This is the part I'm missing, how to dispose "manipulateImage.dll"]
  20. }
  21.  
  22. ~ImageCompareWrapper() {
  23.     Dispose(false);
  24. }
  25.  
  26. #endregion
  27.  
Thanks in advance

Dror
Feb 8 '06 #1
1 1971
System.Runtime.InteropServices.Marshal.ReleaseComO bject([Object of that Com])
May 13 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rich | last post by:
I notice that lots of the GDI+ objects implement IDisposable: SolidBrush, FontFamily, Font, etc. If I don't explicitly call Dispose() on these guys after I'm done with them, what is the...
1
by: wh | last post by:
I have a class which when instatiated creates a new XmlDocument object and loads an xml file into it. It is used as follows: MyObject obj = new MyObject("books.xml"); If I later have obj =...
2
by: Billy Porter | last post by:
Greetings, I got a class that wraps the System.Data.SqlClient.SqlConnection class (no COM interaction). I'm not sure if I'm supposed to implement the IDisposable pattern for this wrapper or not....
15
by: Sam Sungshik Kong | last post by:
Hello! A disposable object's Dispose() method can be called either explicitly by the programmer or implicitly during finalization. If you call Dispose, the unmanaged resources are released...
1
by: Billy | last post by:
Hello... I'm trying to make a database access class for an asp.net application. When I run my application, the Garbage Collecter doesn't seems to unload the memory attributed to my...
3
by: kalamantina | last post by:
How to rewrite this snippet if you must implement IDisposable private static void OpenConnection() { string connectionString = GetConnectionString(); StringBuilder errorMessages = new...
13
by: Carl Johansson | last post by:
Being quite new to C#, I may have misunderstood this. If so please bear with me! As far as I can understand, any instances of a class that implements the IDisposable interface must call the...
4
by: cgarcia0117 | last post by:
For any class I write in C# that has a member variable that implements IDisposable my class implements the IDisposable pattern. I do this to guarantee the reference to the member is explicitly...
19
by: rbrowning1958 | last post by:
Hello, I am confused by dispose etc. and hope someone can set me right. 1. The Dispose(Bool) the IDE generates for a form has nothing to do with IDisposable, right? 2. So when is this called?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.