Solved

Interop between C# and C++

Posted on 2013-11-02
6
366 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
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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