tags:

views:

306

answers:

3

I'm having problems with external native DLL.

I'm working on ASP.NET 1.1 web application and have this DLL which I load through DLLImport directives.

This is how I map DLL functions:

    [DllImport("somedllname",  CallingConvention=CallingConvention.StdCall)] 
    public static extern int function1(string lpFileName,string lpOwnerPw,string lpUserPw);

    [DllImport("somedllname",  CallingConvention=CallingConvention.StdCall)] 
    public static extern int function2(int nHandle);

I call the dll methods and all works great, but I have problems with this DLL crashing my web site on some cases, so I would like an option to unload the dll after I use it.

I found a solution at this link, but I don't have 'UnmanagedFunctionPointer' attribute in .NET 1.1 available.

http://blogs.msdn.com/jonathanswift/archive/2006/10/03/Dynamically-calling-an-unmanaged-dll-from-.NET-_2800_C_23002900_.aspx

Is there a way I can achieve what this guy did with his example?

+1  A: 

I'm not sure if there's an easier way, but you could always load in a dll that dynamically loads/unloads the other dll that is causing you problems.

Brian R. Bondy
You mean that I should create another .net 1.1 dll which does that? If so, how is that different from the initial approach in my question? Or, maybe I'm not following you right.
Goran
@Goran: I meant C++ dll that can call LoadLibrary and FreeLibrary on the other one.
Brian R. Bondy
A: 

Maybe you could wrap the dll with COM and then take advantage of the COM infrastructure to load and unload the DLL... You can then interact with the dll from it's Com Callable Wrapper which is generated when you add a reference to the COM dll. If you really want to get specific about when to unload, after getting a reference to the object, you can specifical call Marshal.ReleaseComObject to release it's reference.

For more information see here... COM Wrappers

Steve Sheldon
A: 

For whom it may concern, I found the solution on the following link...

http://www.codeproject.com/KB/cs/dyninvok.aspx?fid=2892&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=3436363&fr=26#xx0xx

It takes a bit of assembler coding... and it WORKS:)))

Goran