简体   繁体   English

如何静态链接C ++ DLL到.NET库(用c ++ dll构建到net wrapper dll来获取一个dll)

[英]How to link statically C++ dll to .NET library (build in c++ dll to net wrapper dll to get one dll)

I have C++ dll. 我有C ++ DLL。 Than I wrote .NET Wrapper to this C++ dll, and I can attach .NET wrapper to my project and use C++ library in it. 比我给这个C ++ dll编写.NET Wrapper,我可以将.NET包装器附加到我的项目中并在其中使用C ++库。 But now I have two files: c++.dll and wrapper.dll. 但现在我有两个文件:c ++。dll和wrapper.dll。 The problem is with c++.dll, someone can replace c++.dll and inject its code to my application through wrapper.dll. 问题在于c ++ .dll,有人可以替换c ++ .dll并通过wrapper.dll将其代码注入我的应用程序。 How can I embed c++.dll to .net wrapper to get one .net wrapper dll? 如何将c ++。dll嵌入到.net包装器中以获取一个.net包装器dll?

Thanks 谢谢

Simple: Don't. 简单:不要。

You could bundle the C++ DLL into the .NET Assembly as a resource - but then these malicious users could just use ILDASM or Reflector or whatever to pull resources out of your .NET assembly - or decompile your .NET wrapper and recompile it with whatever code they want. 可以将C ++ DLL作为资源捆绑到.NET程序集中 - 但是这些恶意用户可以只使用ILDASM或Reflector或其他任何东西从.NET程序集中提取资源 - 或者反编译.NET包装器并使用任何代码重新编译它他们要。

Bottom line is, you're really barking up a tree you can't climb (you can do things to dissuade people, but you're not going to stop them from messing with your app if they really want to) - and somehow merging your DLLs into one file really isn't going to give you any meaningful benefit. 最重要的是,你真的吠叫了一棵你无法攀爬的树(你可以做一些事情来劝阻别人,但如果他们真的想要,你就不会阻止他们搞乱你的应用) - 并且以某种方式合并你的DLL到一个文件真的不会给你任何有意义的好处。

You could try merging them (with ILmerge, for instance), though I'm not sure how useful that would be. 您可以尝试合并它们(例如,使用ILmerge),但我不确定它会有多大用处。 Then again, if you merge as many files as possible into one single file, that could help your security at least a bit. 然后,如果您将尽可能多的文件合并到一个文件中,这可能至少有助于您的安全性。 This might help: http://weblogs.asp.net/ralfw/archive/2007/02/04/single-assembly-deployment-of-managed-and-unmanaged-code.aspx 这可能会有所帮助: http//weblogs.asp.net/ralfw/archive/2007/02/04/single-assembly-deployment-of-managed-and-unmanaged-code.aspx

Hopefully that helps. 希望这会有所帮助。

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

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