Search code examples
c#c++unmanagedmanaged

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

Need: Communicate with the DLL's in our old Project Un-Managed Code (C++ Visual Studio 2005)

Long Version:

We have a project written in C/C++ (Visual Studio 2005). Now I have to implement a communication with a new device. (Brüel & Kjær 2250SDK 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.

So, the question is, how can I work with the DLL's in my old C++ Code? I don't have the source of the DLL's, I only have the DLLs.

I hope someone out there can help me with that problem. Thanks in advance!


Solution

  • What you want is probably C++/CLI (Common Language Infrastructure). It basically enables you to use .NET types in C++. With this you could call a C# DLL and use the data which is provided by the DLL as the .NET type. Since you already have you application in C++ code, I guess you don't want to rewrite it completely. You'd than have to convert the managed types to unmanaged types, which is possible with 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.