I want to create a DLL that wraps the DLL created in C++.

Asked 1 years ago, Updated 1 years ago, 71 views

I would like to create a wrapper DLL with a C# embedded in the DLL I created in C++ for use with Windows OS.
If possible, I'd like to put it together as one DLL, but is this possible?

c# c++ windows

2022-09-30 21:32

2 Answers

As a minimum of manners when asking questions, be sure to provide detailed information about your development and target environment (OS, IDE, .NET Framework version, project type, etc.).

There are many ways to implement DLLs created in C++.

  • Do you use the C-language function format interface exported to the native DLL in P/Invoke (DllImport) from the C# management code?
  • Or do you create and publish a managed interface in C++/CLI?
  • Or do you create and publish the Windows Runtime interface in C++/CX?
  • Or COM Interoperations?

In any case, if you're simply using a native DLL (written in C/C++, etc.) from C# (.NET language), you don't have to embed it into the management assembly and wrap it.Place the DLL where you can resolve the DLL reference (for example, in the same folder hierarchy as EXE) and the loader will look for it.

In addition, there is a way to embed the native DLL (Unmanaged DLL) as a resource into the management assembly and specify it with the DllImport attribute.
DllImportAttribute Constructor (String) (System.Runtime.InteropServices) - MSDN

However, there are also case reports that it does not work well.
Embedding unmanaged dll into a managed C#dll-Stack Overflow

In the case of management code, reducing the number of assemblies can reduce overhead, so the use case of putting together multiple assemblies is taken into account, and a tool called ILMerge is provided (but all to be merged must be management assemblies).

On the other hand, even if you could embed a native DLL into the management assembly, the benefits probably wouldn't match the cost of effort or effort.


2022-09-30 21:32

PE32 DLLs In short, unmanage DLLs (C++) and
.NET Assembly DLL In short, manage DLL(C#) and
Then, the file format is different and I have never heard that it can be one.I haven't found any documents that clearly state that I can't, and it will prove to be a devil.

Even if it could be done
- Manage, or .NET Assembly, can be 32/64 bit common in AnyCPU. - The unmanage is different for PE32 (32bit) and PE32+ (64bit).
In order to support both 32-bit and 64-bit, I still have to prepare two files, so I think it doesn't taste very good.

If the reason you want to consolidate is distribution, or you don't want to copy two files, it's easiest to leave it to the installer instead of distributing the raw files, and it's more constructive to steer in that direction.If it's Oira, I'll do that.

If you can manage with ClickOnce...


2022-09-30 21:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.