how to protect an imported win32 dll into a .net application from memory issues
- by Eric
I have a c# application that needs to use a legacy win32 dll. The dll is almost its own app, it has dialogs, operations with hardware, etc. When this dll is imported and used, there are a couple of problems that occur:
Dragging a dialog (not a windows
system dialog, but one created by
the dll) across the managed code app
causes the UI to not repaint.
Further it generates a system out of
memory exception from various ui
controls.
The performance is incredibly
slow.
There seems to be no way to
unload the dll so the memory never
gets cleaned up. When we close our
managed app, we get another memory
exception.
At the moment we import each method call as such:
[DllImport("dllname.dll",
EntryPoint = "MethodName", SetLastError = true,
CharSet = CharSet.Auto, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]