Solved

Interop between C# and C++

Posted on 2013-11-02
6
364 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
  • 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 33

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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