calling a C# Windows Form from C++

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: calling a C# Windows Form from C++

  1. #1
    Join Date
    May 2006

    Question calling a C# Windows Form from C++

    I have inherited a huge multi project VS2003 .NET solution:
    Two of the projects call the same dialog boxes but have differences within
    the classes.
    For maintainability and future conversion to VS2005 C# for the Main GUI, I was
    creating C# Windows Forms:

    1) I finally managed to call the Windows Form.
    2) I receive error C2039: 'm_nConnType' : is not a member of
    'DialogLibrary::OpenSysbusSocket': see declaration of
    'DialogLibrary::OpenSysbusSocket' when I build the solution.

    Here is my condensed portion of C++ code:

    #include "stdafx.h"
    #include "genui.h"
    #include "opensysb.h"
    #include "genuidlg.h"
    #include "cmdid.h"
    #include "SysArray.h"
    //I added the #using statements
    #using <System.Windows.Forms.dll>
    #using <system.dll>
    #using <mscorlib.dll>
    #using <DialogLibrary.dll>
    MIRAgEProcType COpenSysbusIMDO::m_nDest = user_defined;
    struct OpenStruct
         ConnectMethod CM;//defined in sysbsock.h
         MIRAgEProcType nDest;
         char szDestHostName [16];
    COpenSysbusIMDO::~COpenSysbusIMDO() {}
    int COpenSysbusIMDO::RetrieveData(BOOL bEditFlag)
        //COpenSysbusDlg     dlg;
        //I replaced the above line with the following line
         DialogLibrary::OpenSysbusSocket *dlg = new DialogLibrary::OpenSysbusSocket;
         int nResult;
         OpenStruct* pData = (OpenStruct*)m_sData.GetBufferSetLength(sizeof OpenStruct);
         if (bEditFlag)
              if (m_mpDest != scmt)
                   // processing open sysbus socket
                   //dlg.m_nSim = (int)m_mpDest;
                   //I changed the notation from '.' to '->'
                   dlg->m_nConnType = (int)(pData->CM) - 1; //Here is were I get the error
         // set remaining member variables to indicate a Open SYSBUS Socket command
         m_dwParam = OpenSysbus;
         m_nDest = pData->nDest; 
         m_sData.ReleaseBuffer(sizeof OpenStruct);
         return nResult;
    Here is part of my C# class: (builds correctly and can be called from a C#

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    namespace DialogLibrary
         /// <summary>
         /// Summary description for Class1.
         /// </summary>
         public class OpenSysbusSocket : Form
              // private members
              int m_nSim;
              int m_nConnType;
              int m_nDest;
              int m_nDestPort;
              int m_nPortNumber;
              // empty constructor
              public OpenSysbusSocket()
                   this.m_nSim = 0;
                   this.m_nConnType = 0;
                   this.m_nDest = 0;
                   this.m_nDestPort = 0;
              // full constructor
              public OpenSysbusSocket ( int nSim, 
                                                   int nConnType,
                                                   int nDest, 
                                                   int nDestPort, 
                                                   int nPortNumber)
                   this.m_nSim = nSim;
                   this.m_nConnType = nConnType;
                   this.m_nDest = nDest;
                   this.m_nDestPort = nDestPort;
              // public accessors
              public int nSim
                   get { return m_nSim;}
                   set { m_nSim = value; }
              public int nConnType
                   get { return m_nConnType;}
                   set { m_nConnType = value; }
              public int nDest
                   get { return m_nDest;}
                   set { m_nDest = value; }
              public int nDestPort
                   get { return m_nDestPort;}
                   set { m_nDestPort = value; }
              public int nPortNumber
                   get { return m_nPortNumber;}
                   set { m_nPortNumber = value; }

    Michael S. Wells
    Software Engineer

  2. #2
    Join Date
    May 2006

    Solved by myself

    Besides the mistake of trying to access the private variables instead of the accessor methods, I added my DialogLibrary class as a reference to the project that uses the Windows Form and it compiled/executed and updated the variables.

Similar Threads

  1. Calling Procedure in Child Form
    By mkt in forum .NET
    Replies: 1
    Last Post: 02-15-2003, 07:07 AM
  2. Replies: 0
    Last Post: 04-11-2002, 07:48 PM
  3. VB form on top of all windows on desktop
    By Sam Bright in forum VB Classic
    Replies: 1
    Last Post: 03-26-2002, 12:41 PM
  4. Moving a Windows Form...Plz Help
    By John in forum .NET
    Replies: 0
    Last Post: 10-04-2001, 11:07 AM
  5. Windows Form Bug
    By Beginner in forum .NET
    Replies: 4
    Last Post: 08-11-2001, 11:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center