Hi.

In my C# application I use functions from an unmanaged C++ DLL. In
this DLL a mutex controls how often it is loaded by different
applications. If the DLL has already been loaded by another app, the
DLLMain -> DLL_PROCESS_ATTACH returns false, otherwise true.

In C++ I was able to check if the import succeeded:

** Code begin **
HMODULE hScanLib = NULL;
hScanLib  = LoadLibrary("myDLL");
if (hScanLib) { <import functions with GetProcAddress()> }
else { <controlled end of app> }
** Code end **

In C# my code looks like this:

** Code begin **
internal class InterfaceImport
{
        ...
        [DllImport("myDLL.dll")]
        public static extern Int32 QueryDevices();
        ....
}

public class myDLLInterface
{
        ...
        public Int32 QueryDevices()
        {
            Int32 RC;
            try
            {
                RC = InterfaceImport.QueryDevices();
            }
            catch
            {
                <controlled end of app>
            }
        }
        ...
}
** Code End**

What happens is a LoaderLock inside the try statement that cannot be
caught, causing the app to end unexpectedly. The DLLImport failed, but
I don't know how to get informed about that.

Is it possible to validate the return code of the DLLMain function or
the state of the import as with LoadLibrary? Is DLLImport the one and
only way in C#? The documentation I found in books, the MSDN and other
forums was quite unsatisfying.

Please help, and thanks for reading,
Heiko

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web 
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---

Reply via email to