How to use same filename DLLs in a Exe?(One is)

  • Thread starter Thread starter kinghuangz
  • Start date Start date
K

kinghuangz

Everyone:
I want to use a DLL(FileName:PubFunction.Dll) built with VS.Net(C#) in a
unmanaged Program .But there was a Dll just has the same filename,it was
built with VC++(6.0).The unmanaged was loaded by LoadLibrary function
firstly,and it would be free until the Program's end.How can I Load the
managed Dll?
 
Hi,

Firstly, you cannot have two files having the same name (probably only with
differences in character case) in the same folder (may be NTFS allows this
but FAT32 definitely not). Therefore, you will have to store these DLLs in
separate folders.

Secondly, while managed DLLs CAN be loaded with LoadLibrary, there is little
sense in doing so. The simplest way to expose a managed library to unmanaged
code is by making the managed library COM-visible.
Hence, the .NET Interop subsystem will take care of the DLL location - your
only responsibility would be to register the managed DLL with the
appropriate tool (regasm.exe). Provided it is stored in a separate folder,
this will ensure the framework will be able to successfully locate and load
the managed DLL.

Does this answer your question?
 
I called the Managed Dll successfully when the Managed Dlls and the
Unmanaged Dlls have not the same filename;
The method was introduced on
http://www.codeproject.com/dotnet/bridge.asp?target=call|managed.
The Dlls have the same filename in separate folders.It's impossible to
change the filename whether Managed Dll or
UnManaged Dll.

When run the program(unmanaged),firstly,load the unmanaged file
'Pubfunction.dll' by LoadLibrary;And when call the
function implement in managed Dll,I used a Bridge to call managed Dll.The
managed Project static reference the managed Dll named Pubfuncion.It will be
failed to load managed file Pubfunction.dll.The system first scan the
filelist which have been
Loaded.
Dmitriy Lapshin said:
Hi,

Firstly, you cannot have two files having the same name (probably only with
differences in character case) in the same folder (may be NTFS allows this
but FAT32 definitely not). Therefore, you will have to store these DLLs in
separate folders.

Secondly, while managed DLLs CAN be loaded with LoadLibrary, there is little
sense in doing so. The simplest way to expose a managed library to unmanaged
code is by making the managed library COM-visible.
Hence, the .NET Interop subsystem will take care of the DLL location - your
only responsibility would be to register the managed DLL with the
appropriate tool (regasm.exe). Provided it is stored in a separate folder,
this will ensure the framework will be able to successfully locate and load
the managed DLL.

Does this answer your question?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

kinghuangz said:
Everyone:
I want to use a DLL(FileName:PubFunction.Dll) built with VS.Net(C#)
in
a
unmanaged Program .But there was a Dll just has the same filename,it was
built with VC++(6.0).The unmanaged was loaded by LoadLibrary function
firstly,and it would be free until the Program's end.How can I Load the
managed Dll?
 
Back
Top