Calling C# Windows Form from C++

G

Guest

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>

IMPLEMENT_SERIAL (COpenSysbusIMDO, CIMDO, 1)
MIRAgEProcType COpenSysbusIMDO::m_nDest = user_defined;
struct OpenStruct
{
ConnectMethod CM;//defined in sysbsock.h
MIRAgEProcType nDest;
char szDestHostName [16];
};

COpenSysbusIMDO::COpenSysbusIMDO()
{
}

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#
app)

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()
{
InitializeComponent();

this.m_nSim = 0;
this.m_nConnType = 0;
this.m_nDest = 0;
this.m_nDestPort = 0;
this.CalcPort();
}

// 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;
this.CalcPort();
}

// 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; }
}
}
}


--
Thanks,

Michael S. Wells \|/
Software Engineer ^O-O^
---------------------------o00o--(_)--o00o----------------------------
 
G

Guest

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.
--
Thanks,

Michael S. Wells \|/
Software Engineer ^O-O^
---------------------------o00o--(_)--o00o----------------------------



RedJoy said:
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>

IMPLEMENT_SERIAL (COpenSysbusIMDO, CIMDO, 1)
MIRAgEProcType COpenSysbusIMDO::m_nDest = user_defined;
struct OpenStruct
{
ConnectMethod CM;//defined in sysbsock.h
MIRAgEProcType nDest;
char szDestHostName [16];
};

COpenSysbusIMDO::COpenSysbusIMDO()
{
}

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#
app)

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()
{
InitializeComponent();

this.m_nSim = 0;
this.m_nConnType = 0;
this.m_nDest = 0;
this.m_nDestPort = 0;
this.CalcPort();
}

// 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;
this.CalcPort();
}

// 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; }
}
}
}


--
Thanks,

Michael S. Wells \|/
Software Engineer ^O-O^
---------------------------o00o--(_)--o00o----------------------------
 
Top