简体   繁体   English

从未管理的项目(C / C ++ VS2005)调用托管代码(C#/ Visual Basic VS2010)

[英]Calling managed code (C#/Visual Basic VS2010) from an unmanagened project (C/C++ VS2005)

Short Version: 简洁版本:

Have: DLL's Managed Code (C#/Visual Basic) from Brüel & Kjær SDK 拥有:来自Brüel&KjærSDK的DLL托管代码(C#/ Visual Basic)

Need: Communicate with the DLL's in our old Project Un-Managed Code (C++ Visual Studio 2005) 需要:在我们的旧项目非托管代码(C ++ Visual Studio 2005)中与DLL进行通信

Long Version: 长版:

We have a project written in C/C++ ( Visual Studio 2005 ). 我们有一个用C / C ++编写的项目( Visual Studio 2005 )。 Now I have to implement a communication with a new device. 现在,我必须实现与新设备的通信。 ( Brüel & Kjær 2250SDK Noice ). Brüel&Kjær2250SDK Noice )。

The problem is, Brüel & Kjær only supports you with Libraries for C# or Visual Basic ( Managed-Code ) ( Visual Studio 2010 and higher ), but our project is an old unmanaged C/C++ code . 问题是, Brüel&Kjær仅支持C#或Visual Basic( 托管代码 )( Visual Studio 2010及更高版本 )的库,但是我们的项目是旧的非托管C / C ++代码

So, the question is, how can I work with the DLL's in my old C++ Code? 因此,问题是,如何在旧的C ++代码中使用DLL? I don't have the source of the DLL's, I only have the DLLs. 我没有DLL的源,我只有DLL。

I hope someone out there can help me with that problem. 我希望那里的人可以帮助我解决这个问题。 Thanks in advance! 提前致谢!

What you want is probably C++/CLI (Common Language Infrastructure). 您想要的可能是C ++ / CLI(通用语言基础结构)。 It basically enables you to use .NET types in C++. 它基本上使您可以在C ++中使用.NET类型。 With this you could call a C# DLL and use the data which is provided by the DLL as the .NET type. 这样,您可以调用C#DLL并将DLL提供的数据用作.NET类型。 Since you already have you application in C++ code, I guess you don't want to rewrite it completely. 由于您已经使用C ++代码编写了应用程序,所以我想您不想完全重写它。 You'd than have to convert the managed types to unmanaged types, which is possible with C++/CLI. 您将不得不将托管类型转换为非托管类型,这在C ++ / CLI中是可能的。

If you want to know more about it, here is a lengthy MSDN article about it and here is a useful little quick tutorial. 如果您想了解更多, 这里是一篇冗长的MSDN文章, 这里是一个有用的快速入门教程。

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

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