简体   繁体   English

在C#项目中使用cpp dll

[英]Using cpp dll in c# project

I have a win32 cpp dll, and ac# project (PROJ_1), that use dllimport to call win32 dll functions. 我有一个win32 cpp dll和一个ac#项目(PROJ_1),它们使用dllimport调用win32 dll函数。 This dll included into project PROJ_1 and has build action as copy to output dir. 该DLL包含在项目PROJ_1中,并具有复制到输出dir的生成动作。

Another c# project (PROJ_2) references PROJ_1 and PROJ_3 references PROJ_2. 另一个c#项目(PROJ_2)引用PROJ_1,PROJ_3引用PROJ_2。

So, now we have something like this PROJ_3->PROJ_2->PROJ_1(dll) 所以,现在我们有了这样的东西PROJ_3-> PROJ_2-> PROJ_1(dll)

So, when i make build in VS 2010: 1. In bin of PROJ_1 i have win32 dll. 因此,当我在VS 2010中进行构建时:1.在PROJ_1的bin中,我有win32 dll。 2. In bin of PROJ_2 too 3. But in PROJ_3 - no win32 dll exists 2.也在PROJ_2的bin中3.但是在PROJ_3中-不存在win32 dll

What is the problem a how to resolve it? 有什么问题以及如何解决?

If the projects are in one VS solution, do you have dependencies between projects correctly defined (right click project -> Project dependencies)? 如果项目在一个VS解决方案中,那么您在正确定义的项目之间是否存在依赖关系(右键单击项目->项目依赖关系)? Are all the projects built for the same target architecture (64/86)? 是否所有项目都针对相同的目标体系结构(64/86)构建?

As side question - Did you consider writing C++/CLI wrapper? 附带问题-您是否考虑编写C ++ / CLI包装器?

我建议您将非托管DLL添加到PROJ3解决方案中,并在属性中将“复制到输出目录”设置为“始终复制”

You could check the 'Copy Local' property of the reference to PROJ_2. 您可以检查对PROJ_2的引用的“本地复制”属性。 In PROJ_1, add the win32 dll to your solution (no reference, just add it as a file just like a class in your solution) and set the properties Build Action = Content, Copy to Output Directory = Copy always. 在PROJ_1中,将win32 dll添加到您的解决方案中(无参考,只需将其添加为文件即可,就像解决方案中的类一样),并设置属性Build Action = Content,复制到Output Directory = Always复制。

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

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