Re: I have a managed DLL code written in C#

Tech-Archive recommends: Fix windows errors by optimizing your registry



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.


.



Relevant Pages

  • Re: I have a managed DLL code written in C#
    ... DLL code into a managed code. ... public static extern void delete_tuner; ... There is no way this code can compile, as dllName doesn't exist in your ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: I have a managed DLL code written in C#
    ... unmanaged DLL code into a managed code. ... DLL code into my own test application I get an error message saying the ... There is no way this code can compile, as dllName doesn't exist in your ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: DllRegisterServer entry point was not found!!!
    ... Dllname was loaded, but the DllRegisterServer or DllUnregisterServer entry point was not found. ... Dllname is not a .dll or .ocx file. ... typing regsvr32 wjview.exe generates this error message. ...
    (microsoft.public.windowsxp.general)
  • Re: Dubugger goes to code of .net DLL
    ... I looked in the various parameters available for the DLL and cannot see ... Before I used menu Build/Build <DLLName> ... Anthony Jones - MVP ASP/ASP.NET ...
    (microsoft.public.dotnet.general)
  • Re: C# newbie trying to debug AutoCAD API-function
    ... DLL is being initialized (presumably the AutoCAD DLL). ... Without knowing how you get into managed code while the loader lock is being held, I can't offer advice as to how to avoid that. ... Basically, these are exceptions that don't occur without the debugger; the debugger is monitoring the execution of your process, and generating an exception when it notices something is potentially wrong. ...
    (microsoft.public.dotnet.languages.csharp)