Solved

Interop between C# and C++

Posted on 2013-11-02
6
369 Views
Last Modified: 2013-11-06
I have a C# dialog with OK and Cancel button. Now this dialog is called from VC++ code.  I wanted to pass a string from C# dialog to C++ which will let us know if the user has clicked OK or Cancel button. I am able to access the defined string in C# to the C++ code but the values are coming as NULL instead of True or False as defined in C#. I wanted to know what could be going wrong and how to achieve this
0
Comment
Question by:rbhargaw
[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
  • 3
  • 2
6 Comments
 

Expert Comment

by:noodles_esa
ID: 39619567
Are you using a WPF or a WF Dialog?
In WPF the DialogResult is a System.Object. It is singalized through a nullable bool if there is a return value at all.
In Windows Forms the DialogResult is a enumeration of the clicked option. There are no string captions of the clicked buttons.
0
 

Author Comment

by:rbhargaw
ID: 39620454
It's a windows form dialog. However I have declared a string name buttonFlag and setting the value as "true" or "false" when the use clicks on the button. Now I need to transfer the button flag string value to C++ application. How can I achieve that?
0
 

Expert Comment

by:noodles_esa
ID: 39620803
Have you tried Setting the assembly's property COMVisible=true? This should make your application accessible through COM in C++. Just write the string captions to a reserved Memory (field) and Access it afterwards native.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 34

Accepted Solution

by:
sarabande earned 500 total points
ID: 39624078
I have a C# dialog with OK and Cancel button. Now this dialog is called from VC++ code.
 

can you post how you call the dialog from c++ ?

depending on the used method you would have a way to determine which of the two buttons closed the dialog.

a more general way is to pass the window handle of your c++ app to the c# dialog when it was created. the dialog could store the handle as a class member and the handlers in c# that would handle either button click would be able to send a (private) message back to the application.

Sara
0
 

Author Comment

by:rbhargaw
ID: 39625666
Thanks Sara, Basically there is  C++ Dialog Class To Host a C# control. The C++ host is configuring  the C# component by setting properties that it exposes. The C# class can expose events that are handled by the C++ host using the standard .NET event pattern. I am currently working to post a message back and see if that will work. I think thats what you are going into also.
0
 

Author Closing Comment

by:rbhargaw
ID: 39628381
Satisfied with explanation
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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