Solved

How to pass strings from C++ to C#

Posted on 2011-02-28
2
252 Views
Last Modified: 2012-05-11
Here is what I am trying to do:

I have a C# application that contains an unmanaged C++ project.  The C++ project is responsble for collecting messages from a "server" via ethernet then firing an event so that the C# knows that there is a new message. Then the C# reads the message.  

I have the event working, but I am seeing issues with getting the string to the C# code.  In the C++ dll the message is available as a wstring.  What is the best way to do this?  
0
Comment
Question by:efryevt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 34999571
This method probably would be the easiest approach: http://www.codeproject.com/KB/cs/wm_copydata_use.aspx ("Use WM_COPYDATA to send data to/from C++ and C# Windows processes")
0
 

Author Closing Comment

by:efryevt
ID: 35001788
I would not of thought to do it this way, but it works like a charm...once I got it to compile in my project.  Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question