简体   繁体   English

在 C#(WPF) 中使用 C++ dll

[英]Use C++ dll in C#(WPF)

I had one C++ project written in MFC and some of the project are of DLL type.我有一个用 MFC 编写的 C++ 项目,其中一些项目是 DLL 类型的。 I wanted to use those dll in my C# code(using DllImport ).我想在我的 C# 代码中使用这些 dll(使用DllImport )。

I tried to add as a reference but could not able to and getting an error.我尝试添加作为参考,但无法添加并出现错误。 Do i need to copy those dll's in any of particular location?我需要在任何特定位置复制这些 dll 吗? How my code is going to link those dll's?我的代码将如何链接这些 dll?

You can't add a reference to a native DLL.您不能添加对本机 DLL 的引用。 In DllImport you just import the DLL at runtime so be careful with the path to the DLL if it is not in the same directory as your managed application.DllImport您只需在运行时导入 DLL,因此,如果 DLL 的路径与托管应用程序不在同一目录中,请注意 DLL 的路径。

A problem with C++-DLLs is, that the function names in that DLLs can be decorated so you have to find out that decorated name before using it. C++-DLL 的一个问题是,该 DLL 中的函数名称可以被修饰,因此您必须在使用它之前找出该修饰名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM