简体   繁体   English

将旧的C ++ DLL转换为C#

[英]Old C++ DLLs into C#

I have a C# project that requires me to use an SDK written in C++. 我有一个C#项目,要求我使用用C ++编写的SDK。 I have gotten a little unfamiliar with C++ but I managed to find all the important functions and classes that I will need. 我对C ++有点陌生,但是我设法找到了我需要的所有重要函数和类。

From what I learned, I guess C++/CLR is going to be my best bet. 据我了解,我猜C ++ / CLR将是我最好的选择。

The SDK itself mostly uses a DLL called "VssSDK.dll" that comes with multiple header files. SDK本身主要使用带有多个头文件的DLL“ VssSDK.dll”。

It's 2018 so I am hoping that there exists some way of converting that very large DLL into something I can use in my .NET application without spending 10s of hours creating headers and what not using CLR (is this what they mean by creating a wrapper?). 现在是2018年,所以我希望有一种方法可以将非常大的DLL转换为可以在.NET应用程序中使用的东西, 而无需花费10个小时的时间来创建标头并且不使用CLR是什么(这就是创建包装器的意思吗? )。

I want this thread to be useful for anyone that needs to undertake the same task: Importing old DLLs into a C# project. 我希望此线程对需要执行相同任务的任何人有用:将旧的DLL导入C#项目。

Any guideline and information will be helpful. 任何指南和信息都将有所帮助。

  • SDK compiles on visual studio 2010 SDK在Visual Studio 2010上编译
  • VssSdk.ddl is a shared library VssSdk.ddl是一个共享库
  • I need to re-use the classes contained inside of VssSdk.dll 我需要重新使用VssSdk.dll中包含的类
  • Needs to be compatible with .NET using 4.6.2 framework 需要使用4.6.2框架与.NET兼容
  • Hundreds of functions and classes needed from VssSdk.dll VssSdk.dll需要数百个函数和类
  • I have not managed to migrate the SDK demo into VS2017 我尚未将SDK演示迁移到VS2017

To use a native method from a native dll, you need to declare it using DllImport attribute and extern keyword. 要使用本机dll中的本机方法,您需要使用DllImport属性和extern关键字对其进行声明。 You may see extern documentation here . 您可能会在这里看到extern文档

To use classes and class methods you should create a wrapper dll first (to transform class methods to functions that takes a first parameter as pointer to an object of the class). 若要使用类和类方法,应首先创建一个包装dll(将类方法转换为以第一个参数作为指向类对象的指针的函数)。 You may use the Wrappit tool. 您可以使用Wrappit工具。

I hope this is helpful. 我希望这是有帮助的。

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

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