Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

CreateManagedControl

Solved!
Go to solution

Since Measurement Studio for C++ is not supporting Unicode i tried to use the .net elements in my existing MFC code.

This is working fine with windows controls, so i tried with National Instruments Led but software is crashing in

OnInitDialog. I tried with Visual Studio 2008 with Measurement Studio 8.6. Does anyone knowns how to

solve the problem. 

 

#pragma once
#include "vcclr.h"

using namespace System;
using namespace System::Windows::Forms;

// CNiMfcNetGuiDlg dialog
class CMfcNetDlg : public CDialog
{
    ...

 public
    CWinFormsControl<System::Windows::Forms::Button> m_Btn;
    CWinFormsControl<NationalInstruments::UI::WindowsForms::Led> m_Led;
 
    ...
};


BOOL CMfcNetDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    ...
    // this works fine with microsoft control
    m_Btn.CreateManagedControl( WS_VISIBLE | WS_CHILD, IDC_BTN, this );
    m_Btn->Text = L"Hallo";
    m_Btn->BackColor = System::Drawing::Color::GreenYellow;
    m_Btn->Click += MAKE_DELEGATE( System::EventHandler, OnBtnClick );

    // this line is crashing !!
    m_Led.CreateManagedControl( WS_VISIBLE | WS_CHILD, IDC_LED, this );

    return TRUE;  // return TRUE  unless you set the focus to a control
}

0 Kudos
Message 1 of 5
(7,802 Views)

Hi Andreas,

 

If you create a new VC++ project with this LED control it works fine.

Can you try this on your side too?

Otherwise please attach your test project so I can check it here.

Regards
DianaS
Message 2 of 5
(7,763 Views)

Thank you for your advice.

 

I still cannot make it running.

 

I send you a sample project.

 

 

0 Kudos
Message 3 of 5
(7,686 Views)
Solution
Accepted by topic author Andreas6

Hello Andreas,

 

Hopefully a late response is better than no response at all... I've taken a look at your code, and I've found a workaround that I hope will be suitable for you.  The issue you've reported has been documented as a bug with ID 247775.  In order to work around the issue, you can host the Measurement Studio .NET controls in a UserControl.  Once you've done this, you should be able to display the controls on your MFC dialog with the CreateManagedControl API.

 

The main key to hosting the Measurement Studio controls in a user control is to create an assembly with one user control for each Measurement Studio control.  Drop the Measurement Studio control on the user control, and then configure the Anchor property to be Top, Left, and the Dock propert to be Fill.  Then modify the accessibility of the control to be public in the designer.cs file.

 

I've recreated the .NET example "PlotWaveforms" in Visual Studio 2008 MFC and attached it below.  I've also attached my C# UserControl project for creating the hosted Measurement Studio .NET controls.  Please take a look and let me know if you have any questions.

 

NickB

National Instruments

0 Kudos
Message 4 of 5
(7,093 Views)

Dear NickB,

Your solution comes just in time. We just stated a new project and we have still no solution.
I made some tests and it seems to work. We are very happy to have this solution!
Thanks for you great work. We really appreciate your help on that problem. Smiley Happy


Andreas6

0 Kudos
Message 5 of 5
(7,071 Views)