Solved

Interop between C# and C++

Posted on 2013-11-02
6
360 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 32

Accepted Solution

by:
sarabande earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Satisfied with explanation
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

6 Experts available now in Live!

Get 1:1 Help Now