Erix
Erix

Reputation: 7105

Best practices for copying DLLs with DllImport in Visual Studio?

I have a solution which contains 2 projects. One is a C++ wrapper for an external, third party library which is contained withing a series of Dll fies. The other is a C# project which references the C++ project via [DllImportAttribute].

What is the proper way to copy these Dlls so that they are found upon execution of the C# project? Are the typically registered with the system? Are all Dlls (both the external library and the C++ project) copied into the C# output folder?

How is this usually done? In a post-build step?

I'm sure there are a few ways to accomplish this, I just want to use the most common, trouble free approach. thanks.

Upvotes: 0

Views: 513

Answers (2)

Jack J Jun- MSFT
Jack J Jun- MSFT

Reputation: 5986

Based on your description, you want to call c++ dll in c# app.

I write the detailed steps in the following link, you could have a look.

how to call c++ dll in c# app

Upvotes: 0

shingo
shingo

Reputation: 27021

Generally Windows searches a dll in the same directory of the executable file first: https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order , so copy every dll files into this directory (the C# output folder in the case).

Upvotes: 1

Related Questions