how to protect an imported win32 dll into a .net application from memory issues
Posted
by Eric
on Stack Overflow
See other posts from Stack Overflow
or by Eric
Published on 2010-05-14T20:16:21Z
Indexed on
2010/05/14
20:24 UTC
Read the original article
Hit count: 197
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)]
© Stack Overflow or respective owner