Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
This is where I start having my problems...

C#
public Card()
{
  int width = DefaultWidth;
  int height = DefaultHeight;
  mode = (int)CardMode.RankCollated;
  NativeMethods.cdtInit(ref width, ref height);
}
#region Implementation: IDisposable & Finaliser
/// <summary>
/// Instance finaliser for the class for unmanaged resources.
/// </summary>
~Card ()
{
  Dispose(false);
}
/// <summary>
/// Called by caller's when the instance is finished with.
/// </summary>
public void Dispose()
{
  Dispose(true);
  GC.SuppressFinalize(this);
}
/// <summary>
/// Internal dispose function which release managed and unmanaged resources.
/// </summary>
/// <param name="disposing">true iff managed and unmanaged are being disposed of else unmanaged only.</param>
private void Dispose( bool disposing )
{
  // Check to see if Dispose has already been called.
  if(!this.disposed)
  {
    // Call the appropriate methods to clean up
    // unmanaged resources here.
    // If disposing is false,  only the following code is executed.
    if( this.graphicsSurface != null && this.graphicsDC != IntPtr.Zero)
    {
      this.graphicsSurface.ReleaseHdc( this.graphicsDC );
      this.graphicsDC = IntPtr.Zero;
    }
    NativeMethods.cdtTerm();
    // If disposing equals true, dispose all managed
    // and unmanaged resources.
    if(disposing)
    {
      // Dispose managed resources.
      if( graphicsSurface != null )
      {
        graphicsSurface.Dispose();
      }
    }
  }
  this.disposed = true;
}
#endregion
Posted
Updated 4-Jan-11 21:49pm
v3
Comments
Hiren solanki 5-Jan-11 3:28am    
@CPallini : it's in that programme, you need to find that out, it's test for us.
CPallini 5-Jan-11 3:28am    
And what are your problems (should we guess?)?
Sandeep Mewara 5-Jan-11 3:31am    
What problem?
james mcwalters 5-Jan-11 3:38am    
im trying to change card.dll to CardGames.dll in this code so that the program builds the cards from the microsoft CardGames.dll in windows vista. when i debug i have no error but it tells me Unable to load DLL 'cards.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Dalek Dave 5-Jan-11 3:49am    
Minor Edir for Grammar.

You did not explain the problem, but you should not dispose from destructor. The moment of the destruction is uncertain (because of GC).
In your case, don't use destructor at all. (In .NET writing destructors is much less typical.)

The disposal should be built from the Form (or Windows) Dispose calling all children in chain.

[EDITED IN NEW VERSION]

Please explain your problem to get further advice.

Thanks to Question clarification by James I can see this advice is unrelated to his immediate problem. Still this advice is valid.

I'll post a separate Answer to help sorting out of the problem with "Cards.DLL", please see.

[END EDITED IN NEW VERSION]
 
Share this answer
 
v2
Comments
Dalek Dave 5-Jan-11 3:50am    
I think you are right in working out what his problem is.
A shame the OP didn't say! :)
james mcwalters 5-Jan-11 3:59am    
I don't have time for grammar after all I didn't graduate from high school, but I read and teach myself daily and I sure don't worry about what anyone else thinks. All I know is that I type with one finger and I get the job done.!!!
Sergey Alexandrovich Kryukov 5-Jan-11 11:32am    
Sorry James, now you don't have time to ask questions with wrong grammar.
"Getting job done" is questionable. I can see it is not done.

However, you grammar is not so bad. Thank you for extra explanation.
Perhaps you just need more fingers. :-)
Sergey Alexandrovich Kryukov 5-Jan-11 12:03pm    
Ok, this answer is updated -- still valid. My new answer addresses the problem of "Cards.DLL"; please see.
Thanks to additional explanation of the problem by James, another problem is missing "Cards.DLL".

James, first of all, you never gave us a piece of code where "Cards.DLL" is attempted to load. It's very easy to make a mistake in it.

As far as I can see, "Cards.dll" is a native library, not .NET assembly.
As your Question has a tag "C#", you want to use this library in your assembly.

It can be loaded and accessed via System.Runtime.InteropServices http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.aspx[^].

You need to know entry points of every function you want to export from "Cards.DLL", exact name (non-mangled, as it appears in DLL dump) complete profile of each one (translated into C#). You also need to have a correct path to the DLL, relative to your starting assembly location (or absolute).

If you have all that, you need to apply the attribute System.Runtime.InteropServices.DllImportAttribute (http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx[^]) to each function to be imported.

As the function may contain parameter or return types different from .NET types, each such parameter may need application of the attribute
System.Runtime.InteropServices.MarshalAsAttribute (http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshalasattribute.aspx[^]).

In some cases, default marshalling works (such as marshalling between System.String and null-terminated strings, either Unicode or ANSI), so such parameters require no attribute. In other cases, System.Runtime.InteropServices.MarshalAsAttribute is needed (see its constructor [^]) and the type System.Runtime.InteropServices.UnmanagedType, http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.unmanagedtype.aspx[^]).

In more complex cases, creation of custom Marshalling may be required.

For further advice, exact profiles of the functions is needed. It can be very easy to export them (more typical case), very difficult (not very typical case) or somewhere in between (fairly typical case).

My first advice about the use of Dispose is unrelated to the problem of "Cards.DLL", but still valid -- you should change the schema of disposal. That's why I'm posting a second answer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900