troubleshooting Question

Passing strings to a managed C++ Dll from C#

Avatar of 10goto20
10goto20 asked on
Fonts TypographyC#
5 Comments1 Solution682 ViewsLast Modified:

I'm trying to make a managed C++ Dll to wrap a standard C Dll but run into some problems when I want to pass strings from my C# application to the managed dll.

My question is which way is the easiest to pass strings from my C# application to the managed Dll?

The code for the wrapper is listed below.

C# code:

MTP1Wrapper.Class1 cl = new MTP1Wrapper.Class1();

C++ Wrapper:

namespace MTP1Wrapper


public __gc class Class1
      int Open(char* strPort)
            string test("test");
            int status = MTP1_Open(&hMTP1,
      return status;

      int Send(int man, unsigned char* data, int length)
            int status = MTP1_Send(hMTP1, man, 1, data, length);
            return status;

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros