Solved

How to pass strings from C++ to C#

Posted on 2011-02-28
2
244 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
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now