Re: I have a managed DLL code written in C#
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 18 Oct 2007 10:54:07 -0400
Par,
I am curious why you have this line:
public DllImportAttribute My_dll = new DllImportAttribute(dllName);
There is no way this code can compile, as dllName doesn't exist in your
class definition. Also, decaring the attribute like that does nothing for
you.
Also, for the name of the dll, you need to give it a DLL name/path which
will be searched by the LoadLibrary API. Using
"\obj\Release\MLibTuners.dll" is probably not a good idea, since that is
probably not where the dll is going to be when you distribute the program.
Can you create just a console program which makes the call to the static
method, and does it work?
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Par" <Par@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:6E12C8AC-2EF2-4805-A89D-6B38D404A436@xxxxxxxxxxxxxxxx
Hi
I have a managed DLL code written in C#, which is calling / importing an
unmanaged DLL function. The function in the undamaged DLL code looks like
- Void delete_tuner (short tuner_number)
I create one class that shall contain a set of related unmanaged DLL
functions. The class I created looks like
public class Dll_Pool
{
public DllImportAttribute My_dll = new DllImportAttribute(dllName);
[DllImport(@"\\obj\\Release\\MLibTuners.dll")]
public static extern void delete_tuner(Int16 tuner_number);
public string GetDllName()
{
string dllName;
dllName = My_dll.Value;
return dllName;
}
public Dll_Pool()
{
}
public static void DllMain()
{
Int16 tuner_number = 0;
---> delete_tuner(tuner_number); <--- // The executing of the
code is stoped here and I got an error message
}
}
I have even a simple C# test code which is calling the imported function
according to
Dll_Pool.DllMain();
I have no problem to build the code and start running it in the debug
mode.
As I show between the arrows in the code above the executing of the code
is
stopped with error message saying.
"Loader Lock Was detected Attempting managed execution inside OS Loader
lock. Do not attempt to run managed code inside a DllMain or
image initialization function since doing so can cause the application to
hang."
I found information, under help documentation which describes what Loader
Lock means and the reasons of it but I did not find documentation in how
to
solve the problem. I really hope someone could help me to solve the
problem.
.
- Follow-Ups:
- References:
- I have a managed DLL code written in C#
- From: Par
- I have a managed DLL code written in C#
- Prev by Date: XmlIgnore an inherited attribute
- Next by Date: Re: invoke vs begininvoke, mdi/child and showdialog
- Previous by thread: I have a managed DLL code written in C#
- Next by thread: Re: I have a managed DLL code written in C#
- Index(es):
Relevant Pages
|