473,732 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing parameters between form classes - C#

I'm a rookie at C# and OO so please don't laugh! I have a form
(fclsTaxCalcula tor) that contains a text box (tboxZipCode) containing a zip
code. The user can enter a zip code in the text box and click a button to
determine whether the zip code is unique. If the zip code is not unique,
another form/dialog is displayed (fclsLookup) - lookup form/dialog. The zip
code is passed to the lookup form/dialog by reference. I then load a
datagrid with the possible matches (i.e. zip, city, county, state, zipid).
When the user clicks the row in the datagrid, I want to pass the zipid back
to the original form/dialog and run a stored procedure. My problem is I do
not know how to get the ZipId back to the fclsTaxCalculat or form/dialog.
I've search for examples of this and I've not been able to track one down -
please help!!!
Nov 17 '05 #1
8 4414
"Johnny" <Jo****@discuss ions.microsoft. com> wrote in message
news:8E******** *************** ***********@mic rosoft.com...
I'm a rookie at C# and OO so please don't laugh!


We won't. This is a C++ group. Try posting in

microsoft.publi c.dotnet.langua ges.csharp

Regards,
Will
Nov 17 '05 #2
Hello !

There are no stupid questions.

The forms you define in C# always consist of a class. A single form is a
single class. Thus, your problem comes from the interaction between classes.
You already knew this, however.

So, in addition to passing a reference variable to the zip code the user has
entered (the one which you wish to check), pass in another reference to the
ACTUAL zip code returned by the lookup form. Now, when the lookup form is
launched, you use the first reference to pass in the zipcode and initialize
the datagrid to show possible values, and the second reference to pass back
the value which the user clicked on in the datagrid.

Here's the most simplest example I can think of. It's written in C++, but
the language syntax is pretty much similar in C#.

class MyForm1
{
public:
int m_nUsersZipCode ;
int m_nDatagridResu lt;
MyForm2* m_pLookupForm;
};

class MyForm2
{
public:
DWORD ValidateZipCode (int& nRefSource, int& nRefSelected);
};

int main(void)
{
MyForm1 form1;
MyForm2 form2;
form1.Show();
}

// In the ShowLookupForm handler of MyForm1
..
m_pLookupForm->ValidateZipCod e( m_nUsersZipCode ,
m_nDatagridResu lt );
..

This would be the most simplistic way to accomplish it. The problem itself
is not C# related by nature, thus it's quite easy to answer it.

-Antti Keskinen

"Johnny" <Jo****@discuss ions.microsoft. com> wrote in message
news:8E******** *************** ***********@mic rosoft.com...
I'm a rookie at C# and OO so please don't laugh! I have a form
(fclsTaxCalcula tor) that contains a text box (tboxZipCode) containing a
zip
code. The user can enter a zip code in the text box and click a button to
determine whether the zip code is unique. If the zip code is not unique,
another form/dialog is displayed (fclsLookup) - lookup form/dialog. The
zip
code is passed to the lookup form/dialog by reference. I then load a
datagrid with the possible matches (i.e. zip, city, county, state, zipid).
When the user clicks the row in the datagrid, I want to pass the zipid
back
to the original form/dialog and run a stored procedure. My problem is I
do
not know how to get the ZipId back to the fclsTaxCalculat or form/dialog.
I've search for examples of this and I've not been able to track one
down -
please help!!!

Nov 17 '05 #3
Antti,

I really appreciate the feedback. I should have stated the fact that I am
passing two variables by reference but I don't know how to set the variable
that I pass to the second form to the value selected in the second form.
When I try to set the variable. I get a message from the compiler that
states the varaible does not exist in the namespace. My code is below.

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Data.Sql Client;

namespace EnspireUtilitie s
{
/// <summary>
/// Summary description for Lookup.
/// </summary>
public class fclsLookup : System.Windows. Forms.Form
{
private System.Data.Sql Client.SqlDataA dapter sqlDataAdapter1 ;
private System.Data.Sql Client.SqlComma nd sqlSelectComman d1;
private System.Data.Sql Client.SqlConne ction sqlConnection1;
private EnspireUtilitie s.dsLookup dsLookup1;
private System.Windows. Forms.DataGrid dataGrid1;
private System.Windows. Forms.Button btnLoad;
private System.Windows. Forms.TextBox tboxLookupZipCo de;
private System.Windows. Forms.Label lblLookupParame ter;
private System.Windows. Forms.Button btnOK;
private System.Windows. Forms.Button btnCancel;
//private string strZipCode = string.Empty;
private System.Windows. Forms.DataGridT ableStyle dataGridTableSt yle1;
private System.Windows. Forms.DataGridT extBoxColumn dataGridTextBox Column1;
private System.Windows. Forms.DataGridT extBoxColumn dataGridTextBox Column2;
private System.Windows. Forms.DataGridT extBoxColumn dataGridTextBox Column3;
private System.Windows. Forms.DataGridT extBoxColumn dataGridTextBox Column4;
public string strZipCode = String.Empty;
public string strZipCodeDtlId = String.Empty;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public fclsLookup(ref string ZipCode, ref string ZipCodeDtlId)
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//
//tboxLookupZipCo de.Text = ZipCode;
sqlSelectComman d1.Parameters["@zip"].Value = ZipCode;
dsLookup1.Clear ();
sqlDataAdapter1 .Fill(dsLookup1 );
strZipCode = ZipCode;
strZipCodeDtlId = ZipCodeDtlId;
tboxLookupZipCo de.Text = strZipCode;
this.dataGrid1. MouseDown += new
System.Windows. Forms.MouseEven tHandler(this.d ataGrid1_MouseD own);

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.sqlDataAda pter1 = new System.Data.Sql Client.SqlDataA dapter();
this.sqlSelectC ommand1 = new System.Data.Sql Client.SqlComma nd();
this.sqlConnect ion1 = new System.Data.Sql Client.SqlConne ction();
this.dsLookup1 = new EnspireUtilitie s.dsLookup();
this.dataGrid1 = new System.Windows. Forms.DataGrid( );
this.dataGridTa bleStyle1 = new System.Windows. Forms.DataGridT ableStyle();
this.dataGridTe xtBoxColumn1 = new
System.Windows. Forms.DataGridT extBoxColumn();
this.dataGridTe xtBoxColumn2 = new
System.Windows. Forms.DataGridT extBoxColumn();
this.dataGridTe xtBoxColumn3 = new
System.Windows. Forms.DataGridT extBoxColumn();
this.dataGridTe xtBoxColumn4 = new
System.Windows. Forms.DataGridT extBoxColumn();
this.btnLoad = new System.Windows. Forms.Button();
this.tboxLookup ZipCode = new System.Windows. Forms.TextBox() ;
this.lblLookupP arameter = new System.Windows. Forms.Label();
this.btnOK = new System.Windows. Forms.Button();
this.btnCancel = new System.Windows. Forms.Button();
((System.Compon entModel.ISuppo rtInitialize)(t his.dsLookup1)) .BeginInit();
((System.Compon entModel.ISuppo rtInitialize)(t his.dataGrid1)) .BeginInit();
this.SuspendLay out();
//
// sqlDataAdapter1
//
this.sqlDataAda pter1.SelectCom mand = this.sqlSelectC ommand1;
this.sqlDataAda pter1.TableMapp ings.AddRange(n ew
System.Data.Com mon.DataTableMa pping[] {
new System.Data.Com mon.DataTableMa pping("Table",
"p_getZipCodeDa ta", new System.Data.Com mon.DataColumnM apping[] {
new
System.Data.Com mon.DataColumnM apping("zip", "zip"),
new
System.Data.Com mon.DataColumnM apping("city", "city"),
new
System.Data.Com mon.DataColumnM apping("county" , "county"),
new
System.Data.Com mon.DataColumnM apping("state", "state"),
new
System.Data.Com mon.DataColumnM apping("zip_cod e_dtl_id",
"zip_code_dtl_i d")})});
//
// sqlSelectComman d1
//
this.sqlSelectC ommand1.Command Text = "[p_getZipCodeDat a]";
this.sqlSelectC ommand1.Command Type =
System.Data.Com mandType.Stored Procedure;
this.sqlSelectC ommand1.Connect ion = this.sqlConnect ion1;
this.sqlSelectC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .ReturnValue,
false, ((System.Byte)( 0)), ((System.Byte)( 0)), "",
System.Data.Dat aRowVersion.Cur rent, null));
this.sqlSelectC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@zip", System.Data.Sql DbType.VarChar,
10));
//
// sqlConnection1
//
this.sqlConnect ion1.Connection String = "workstatio n id=CENGENXP2;pa cket
size=4096;user id=sa;data source=cengenxp 2;persis" +
"t security info=True;initi al catalog=src;pas sword=cocacola" ;
//
// dsLookup1
//
this.dsLookup1. DataSetName = "dsLookup";
this.dsLookup1. Locale = new System.Globaliz ation.CultureIn fo("en-US");
//
// dataGrid1
//
this.dataGrid1. DataMember = "p_getZipCodeDa ta";
this.dataGrid1. DataSource = this.dsLookup1;
this.dataGrid1. HeaderForeColor = System.Drawing. SystemColors.Co ntrolText;
this.dataGrid1. Location = new System.Drawing. Point(0, 40);
this.dataGrid1. Name = "dataGrid1" ;
this.dataGrid1. Size = new System.Drawing. Size(568, 288);
this.dataGrid1. TabIndex = 0;
this.dataGrid1. TableStyles.Add Range(new
System.Windows. Forms.DataGridT ableStyle[] {
this.dataGridTa bleStyle1});
this.dataGrid1. Navigate += new
System.Windows. Forms.NavigateE ventHandler(thi s.dataGrid1_Nav igate);
//
// dataGridTableSt yle1
//
this.dataGridTa bleStyle1.DataG rid = this.dataGrid1;
this.dataGridTa bleStyle1.GridC olumnStyles.Add Range(new
System.Windows. Forms.DataGridC olumnStyle[] {
this.dataGridTe xtBoxColumn1,
this.dataGridTe xtBoxColumn2,
this.dataGridTe xtBoxColumn3,
this.dataGridTe xtBoxColumn4});
this.dataGridTa bleStyle1.Heade rForeColor =
System.Drawing. SystemColors.Co ntrolText;
this.dataGridTa bleStyle1.Mappi ngName = "p_getZipCodeDa ta";
//
// dataGridTextBox Column1
//
this.dataGridTe xtBoxColumn1.Fo rmat = "";
this.dataGridTe xtBoxColumn1.Fo rmatInfo = null;
this.dataGridTe xtBoxColumn1.He aderText = "Zip Code";
this.dataGridTe xtBoxColumn1.Ma ppingName = "zip";
this.dataGridTe xtBoxColumn1.Wi dth = 75;
//
// dataGridTextBox Column2
//
this.dataGridTe xtBoxColumn2.Fo rmat = "";
this.dataGridTe xtBoxColumn2.Fo rmatInfo = null;
this.dataGridTe xtBoxColumn2.He aderText = "City";
this.dataGridTe xtBoxColumn2.Ma ppingName = "city";
this.dataGridTe xtBoxColumn2.Wi dth = 75;
//
// dataGridTextBox Column3
//
this.dataGridTe xtBoxColumn3.Fo rmat = "";
this.dataGridTe xtBoxColumn3.Fo rmatInfo = null;
this.dataGridTe xtBoxColumn3.He aderText = "County";
this.dataGridTe xtBoxColumn3.Ma ppingName = "county";
this.dataGridTe xtBoxColumn3.Wi dth = 75;
//
// dataGridTextBox Column4
//
this.dataGridTe xtBoxColumn4.Fo rmat = "";
this.dataGridTe xtBoxColumn4.Fo rmatInfo = null;
this.dataGridTe xtBoxColumn4.He aderText = "State";
this.dataGridTe xtBoxColumn4.Ma ppingName = "state";
this.dataGridTe xtBoxColumn4.Wi dth = 75;
//
// btnLoad
//
this.btnLoad.Lo cation = new System.Drawing. Point(472, 8);
this.btnLoad.Na me = "btnLoad";
this.btnLoad.Ta bIndex = 2;
this.btnLoad.Te xt = "Load";
this.btnLoad.Cl ick += new System.EventHan dler(this.btnLo ad_Click);
//
// tboxLookupZipCo de
//
this.tboxLookup ZipCode.Locatio n = new System.Drawing. Point(136, 8);
this.tboxLookup ZipCode.Name = "tboxLookupZipC ode";
this.tboxLookup ZipCode.Size = new System.Drawing. Size(200, 20);
this.tboxLookup ZipCode.TabInde x = 1;
this.tboxLookup ZipCode.Text = "";
//
// lblLookupParame ter
//
this.lblLookupP arameter.Locati on = new System.Drawing. Point(24, 8);
this.lblLookupP arameter.Name = "lblLookupParam eter";
this.lblLookupP arameter.Size = new System.Drawing. Size(100, 20);
this.lblLookupP arameter.TabInd ex = 3;
this.lblLookupP arameter.Text = "Zip Code";
this.lblLookupP arameter.TextAl ign =
System.Drawing. ContentAlignmen t.MiddleRight;
//
// btnOK
//
this.btnOK.Dial ogResult = System.Windows. Forms.DialogRes ult.OK;
this.btnOK.Loca tion = new System.Drawing. Point(378, 352);
this.btnOK.Name = "btnOK";
this.btnOK.TabI ndex = 3;
this.btnOK.Text = "OK";
this.btnOK.Clic k += new System.EventHan dler(this.btnOK _Click);
//
// btnCancel
//
this.btnCancel. DialogResult = System.Windows. Forms.DialogRes ult.Cancel;
this.btnCancel. Location = new System.Drawing. Point(472, 352);
this.btnCancel. Name = "btnCancel" ;
this.btnCancel. TabIndex = 4;
this.btnCancel. Text = "Cancel";
this.btnCancel. Click += new System.EventHan dler(this.btnCa ncel_Click);
//
// fclsLookup
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(568, 390);
this.Controls.A dd(this.btnCanc el);
this.Controls.A dd(this.btnOK);
this.Controls.A dd(this.lblLook upParameter);
this.Controls.A dd(this.tboxLoo kupZipCode);
this.Controls.A dd(this.btnLoad );
this.Controls.A dd(this.dataGri d1);
this.Name = "fclsLookup ";
this.Text = "Lookup";
((System.Compon entModel.ISuppo rtInitialize)(t his.dsLookup1)) .EndInit();
((System.Compon entModel.ISuppo rtInitialize)(t his.dataGrid1)) .EndInit();
this.ResumeLayo ut(false);

}
#endregion
private void btnLoad_Click(o bject sender, System.EventArg s e)
{
sqlSelectComman d1.Parameters["@zip"].Value = tboxLookupZipCo de.Text;
dsLookup1.Clear ();
sqlDataAdapter1 .Fill(dsLookup1 );
}

private void btnOK_Click(obj ect sender, System.EventArg s e)
{

Close();
}

private void btnCancel_Click (object sender, System.EventArg s e)
{
Close();
}

private void dataGrid1_Navig ate(object sender,
System.Windows. Forms.NavigateE ventArgs ne)
{

Close();
}

protected void dataGrid1_Mouse Down(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
string strMessage = "TEST";

//strMessage = "Row: " + dataGrid1.HitTe st(e.X,e.Y).Row .ToString();
int x = dataGrid1.HitTe st(e.X, e.Y).Row;

strZipCode = dataGrid1[x, 0].ToString();
strZipCodeDtlId = dataGrid1[x, 3].ToString();
MessageBox.Show (strZipCode);
MessageBox.Show ("I still don't know what I'm doing, but I'm at " +
strMessage + ". I need to send back " + strZipCode);
}

}
}

"Antti Keskinen" wrote:
Hello !

There are no stupid questions.

The forms you define in C# always consist of a class. A single form is a
single class. Thus, your problem comes from the interaction between classes.
You already knew this, however.

So, in addition to passing a reference variable to the zip code the user has
entered (the one which you wish to check), pass in another reference to the
ACTUAL zip code returned by the lookup form. Now, when the lookup form is
launched, you use the first reference to pass in the zipcode and initialize
the datagrid to show possible values, and the second reference to pass back
the value which the user clicked on in the datagrid.

Here's the most simplest example I can think of. It's written in C++, but
the language syntax is pretty much similar in C#.

class MyForm1
{
public:
int m_nUsersZipCode ;
int m_nDatagridResu lt;
MyForm2* m_pLookupForm;
};

class MyForm2
{
public:
DWORD ValidateZipCode (int& nRefSource, int& nRefSelected);
};

int main(void)
{
MyForm1 form1;
MyForm2 form2;
form1.Show();
}

// In the ShowLookupForm handler of MyForm1
..
m_pLookupForm->ValidateZipCod e( m_nUsersZipCode ,
m_nDatagridResu lt );
..

This would be the most simplistic way to accomplish it. The problem itself
is not C# related by nature, thus it's quite easy to answer it.

-Antti Keskinen

"Johnny" <Jo****@discuss ions.microsoft. com> wrote in message
news:8E******** *************** ***********@mic rosoft.com...
I'm a rookie at C# and OO so please don't laugh! I have a form
(fclsTaxCalcula tor) that contains a text box (tboxZipCode) containing a
zip
code. The user can enter a zip code in the text box and click a button to
determine whether the zip code is unique. If the zip code is not unique,
another form/dialog is displayed (fclsLookup) - lookup form/dialog. The
zip
code is passed to the lookup form/dialog by reference. I then load a
datagrid with the possible matches (i.e. zip, city, county, state, zipid).
When the user clicks the row in the datagrid, I want to pass the zipid
back
to the original form/dialog and run a stored procedure. My problem is I
do
not know how to get the ZipId back to the fclsTaxCalculat or form/dialog.
I've search for examples of this and I've not been able to track one
down -
please help!!!


Nov 17 '05 #4
If I have some C++ code and I can successfully call a C# assembly but cannot
access the variables in the C# assembly, would I post my question here or in
the C# forum? :D
--
Thanks,

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

"William DePalo [MVP VC++]" wrote:
"Johnny" <Jo****@discuss ions.microsoft. com> wrote in message
news:8E******** *************** ***********@mic rosoft.com...
I'm a rookie at C# and OO so please don't laugh!


We won't. This is a C++ group. Try posting in

microsoft.publi c.dotnet.langua ges.csharp

Regards,
Will

May 8 '06 #5
"RedJoy" <Re****@discuss ions.microsoft. com> wrote in message
news:61******** *************** ***********@mic rosoft.com...
If I have some C++ code and I can successfully call a C# assembly but
cannot
access the variables in the C# assembly, would I post my question here or
in
the C# forum? :D


I don't think that anyone is going to bite your head off over where to place
an interop question.

I'd suggest you post a _small_ amount of code that exhibits your problem. Is
it a simple issue of data member visibility?

Regards,
Will


May 8 '06 #6
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# Main GUI I was
creating a C# Windows Form:

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

Here is my 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_SERIA L (COpenSysbusIMD O, CIMDO, 1)
MIRAgEProcType COpenSysbusIMDO ::m_nDest = user_defined;
struct OpenStruct
{
ConnectMethod CM;//defined in sysbsock.h
MIRAgEProcType nDest;
char szDestHostName [16];
};

COpenSysbusIMDO ::COpenSysbusIM DO()
{
}

COpenSysbusIMDO ::~COpenSysbusI MDO() {}

int COpenSysbusIMDO ::RetrieveData( BOOL bEditFlag)
{
//COpenSysbusDlg dlg;
//I replaced the above line with the following line
DialogLibrary:: OpenSysbusSocke t *dlg = new
DialogLibrary:: OpenSysbusSocke t;

int nResult;

OpenStruct* pData = (OpenStruct*)m_ sData.GetBuffer SetLength(sizeo f
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;
}
}

// set remaining member variables to indicate a Open SYSBUS Socket
command
m_dwParam = OpenSysbus;
m_nDest = pData->nDest;
m_sData.Release Buffer(sizeof OpenStruct);
return nResult;
}

---------------------------------------------------------------------
Here is part of my C# class"

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;

namespace DialogLibrary
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class OpenSysbusSocke t : Form
{
// private members
int m_nSim;
int m_nConnType;
int m_nDest;
int m_nDestPort;
int m_nPortNumber;

// empty constructor
public OpenSysbusSocke t()
{
InitializeCompo nent();

this.m_nSim = 0;
this.m_nConnTyp e = 0;
this.m_nDest = 0;
this.m_nDestPor t = 0;
this.CalcPort() ;
}

// full constructor
public OpenSysbusSocke t ( int nSim, int nConnType, int nDest, int
nDestPort, int nPortNumber)
{
this.m_nSim = nSim;
this.m_nConnTyp e = nConnType;
this.m_nDest = nDest;
this.m_nDestPor t = 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----------------------------

"RedJoy" wrote:
If I have some C++ code and I can successfully call a C# assembly but cannot
access the variables in the C# assembly, would I post my question here or in
the C# forum? :D
--
Thanks,

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

"William DePalo [MVP VC++]" wrote:
"Johnny" <Jo****@discuss ions.microsoft. com> wrote in message
news:8E******** *************** ***********@mic rosoft.com...
I'm a rookie at C# and OO so please don't laugh!


We won't. This is a C++ group. Try posting in

microsoft.publi c.dotnet.langua ges.csharp

Regards,
Will

May 8 '06 #7
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# Main GUI I was
creating a C# Windows Form:

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

Here is my 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_SERIA L (COpenSysbusIMD O, CIMDO, 1)
MIRAgEProcType COpenSysbusIMDO ::m_nDest = user_defined;
struct OpenStruct
{
ConnectMethod CM;//defined in sysbsock.h
MIRAgEProcType nDest;
char szDestHostName [16];
};

COpenSysbusIMDO ::COpenSysbusIM DO()
{
}

COpenSysbusIMDO ::~COpenSysbusI MDO() {}

int COpenSysbusIMDO ::RetrieveData( BOOL bEditFlag)
{
//COpenSysbusDlg dlg;
//I replaced the above line with the following line
DialogLibrary:: OpenSysbusSocke t *dlg = new
DialogLibrary:: OpenSysbusSocke t;

int nResult;

OpenStruct* pData = (OpenStruct*)m_ sData.GetBuffer SetLength(sizeo f
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;
}
}

// set remaining member variables to indicate a Open SYSBUS Socket
command
m_dwParam = OpenSysbus;
m_nDest = pData->nDest;
m_sData.Release Buffer(sizeof OpenStruct);
return nResult;
}

---------------------------------------------------------------------
Here is part of my C# class"

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;

namespace DialogLibrary
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class OpenSysbusSocke t : Form
{
// private members
int m_nSim;
int m_nConnType;
int m_nDest;
int m_nDestPort;
int m_nPortNumber;

// empty constructor
public OpenSysbusSocke t()
{
InitializeCompo nent();

this.m_nSim = 0;
this.m_nConnTyp e = 0;
this.m_nDest = 0;
this.m_nDestPor t = 0;
this.CalcPort() ;
}

// full constructor
public OpenSysbusSocke t ( int nSim, int nConnType, int nDest, int
nDestPort, int nPortNumber)
{
this.m_nSim = nSim;
this.m_nConnTyp e = nConnType;
this.m_nDest = nDest;
this.m_nDestPor t = 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----------------------------

"William DePalo [MVP VC++]" wrote:
"RedJoy" <Re****@discuss ions.microsoft. com> wrote in message
news:61******** *************** ***********@mic rosoft.com...
If I have some C++ code and I can successfully call a C# assembly but
cannot
access the variables in the C# assembly, would I post my question here or
in
the C# forum? :D


I don't think that anyone is going to bite your head off over where to place
an interop question.

I'd suggest you post a _small_ amount of code that exhibits your problem. Is
it a simple issue of data member visibility?

Regards,
Will


May 8 '06 #8
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" wrote:
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# Main GUI I was
creating a C# Windows Form:

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

Here is my 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_SERIA L (COpenSysbusIMD O, CIMDO, 1)
MIRAgEProcType COpenSysbusIMDO ::m_nDest = user_defined;
struct OpenStruct
{
ConnectMethod CM;//defined in sysbsock.h
MIRAgEProcType nDest;
char szDestHostName [16];
};

COpenSysbusIMDO ::COpenSysbusIM DO()
{
}

COpenSysbusIMDO ::~COpenSysbusI MDO() {}

int COpenSysbusIMDO ::RetrieveData( BOOL bEditFlag)
{
//COpenSysbusDlg dlg;
//I replaced the above line with the following line
DialogLibrary:: OpenSysbusSocke t *dlg = new
DialogLibrary:: OpenSysbusSocke t;

int nResult;

OpenStruct* pData = (OpenStruct*)m_ sData.GetBuffer SetLength(sizeo f
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;
}
}

// set remaining member variables to indicate a Open SYSBUS Socket
command
m_dwParam = OpenSysbus;
m_nDest = pData->nDest;
m_sData.Release Buffer(sizeof OpenStruct);
return nResult;
}

---------------------------------------------------------------------
Here is part of my C# class"

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;

namespace DialogLibrary
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class OpenSysbusSocke t : Form
{
// private members
int m_nSim;
int m_nConnType;
int m_nDest;
int m_nDestPort;
int m_nPortNumber;

// empty constructor
public OpenSysbusSocke t()
{
InitializeCompo nent();

this.m_nSim = 0;
this.m_nConnTyp e = 0;
this.m_nDest = 0;
this.m_nDestPor t = 0;
this.CalcPort() ;
}

// full constructor
public OpenSysbusSocke t ( int nSim, int nConnType, int nDest, int
nDestPort, int nPortNumber)
{
this.m_nSim = nSim;
this.m_nConnTyp e = nConnType;
this.m_nDest = nDest;
this.m_nDestPor t = 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----------------------------

"William DePalo [MVP VC++]" wrote:
"RedJoy" <Re****@discuss ions.microsoft. com> wrote in message
news:61******** *************** ***********@mic rosoft.com...
If I have some C++ code and I can successfully call a C# assembly but
cannot
access the variables in the C# assembly, would I post my question here or
in
the C# forum? :D


I don't think that anyone is going to bite your head off over where to place
an interop question.

I'd suggest you post a _small_ amount of code that exhibits your problem. Is
it a simple issue of data member visibility?

Regards,
Will


May 8 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
17355
by: zlatko | last post by:
There is a form in an Access Project (.adp, Access front end with SQL Server) for entering data into a table for temporary storing. Then, by clicking a botton, several action stored procedures (update, append) should be activated in order to transfer data to other tables. I tried to avoid any coding in VB, as I am not a professional, but I have found a statement in an article, that, unlike select queries, form's Input Property can't be...
3
14943
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
10
6649
by: Patrick Stinson | last post by:
What sort of operations can one do with classes? I know class A{}; typeid(A); works, but what else can you do? Is there a way to pass a class as a parameter to a function? class pointers? how does this relate to class A{}; void (A::*)();
7
2866
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID); xmlItems.TransformArgumentList = xsltArgList;
6
27026
by: Jared | last post by:
Hi Does anyone know how could I load a form from another and send some parameters to it? Is there a way to identify by name instances of same form? Thx
11
3183
by: Arsen Vladimirskiy | last post by:
Hello, If I have a few simple classes to represent Entities such as Customers and Orders. What is the proper way to pass information to the Data Access Layer? 1) Pass the actual ENTITY to the Data Access Layer method -or- 2) Pass some kind of a unique id to the Data Access Layer method
11
3479
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and click a button to determine whether the zip code is unique. If the zip code is not unique, another form/dialog is displayed (fclsLookup) - lookup form/dialog. The zip code and zipid are both passed to the lookup form/dialog by reference. I...
3
2684
by: Marc Castrechini | last post by:
First off this is a great reference for passing data between the Data Access and Business Layers: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/Anch_EntDevAppArchPatPrac.asp I use my own classes in the Business layer. I want to keep the Data Access layer from requiring these classes so I tried passing a Datarow between the layers and it seems to work good for me. Constructing the datarow in the Class...
12
3021
by: scottt | last post by:
hi, I am having a little problem passing in reference of my calling class (in my ..exe)into a DLL. Both programs are C# and what I am trying to do is pass a reference to my one class into a DLL function. When I try and compile the DLL I get "The type or namespace name "MyForm" could not be found. I think I have to reference the class but since the DLL needs to be built before the EXE it looks like I have a chicken and egg type problem....
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.