[C#] Unmanaged DLL and Marshalling

Joined
Sep 11, 2009
Messages
17
Reaction score
0
Hello,

I'm writing DLL in C# for C++ application. I need to move structure from C# into C++:
PHP:
StructType structobject = new StructType();
  /*
  I'm filling the struct field's
  */
  IntPtr  ptr = Marshal.AllocHGlobal(Marshal.SizeOf(structobject)); // Allocating memory
  Marshal.StructureToPtr(structobject, ptr, false); // Structure to Pointer
  return ptr; //return pointer for struture

And after "work":
PHP:
Marshal.FreeHGlobal(ptr); // Free memory

And now is problem, something isn't frees memory and i can't delete library file when C++ application running. What I'm doing wrong?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top