|
As others suggest, you need pointers, but if you really have common data shared between two structs then take it out of them and put it in a third struct.
==============================
Nothing to say.
|
|
|
|
|
A far better way of doing things than I suggested.
Cheers,
Ash
|
|
|
|
|
I suggest you go with the suggestion of Erudite_Erik. I took the liberty to put it into code:
struct testsub
{
float IV [300];
float NENTH [600];
};
struct test1
{
test1(float* iv, float* nenth)
: IV(iv), NENTH(nenth) {
}
float* IV;
char FAIL [200];
char FD [600];
float* NENTH;
float NKVAL [30][600];
float NLEVEL [600];
int COUNT;
int CTIME;
};
struct test2
{
test2(float* iv, float* nenth)
: RIV(iv), RNENTH(nenth) {
}
float* RIV;
float RXX [100];
char RFAIL [200];
char RFD [600];
float RTB [50];
float* RNENTH;
char GCD [200];
float RNKVAL [30][600];
char MTBD [600];
float RNLEVEL [600];
int RCOUNT;
int RCTIME;
};
void foo()
{
struct testsub * sub = new testsub();
struct test1 *sim1 = new test1(sub->IV, sub->NENTH);
struct test2 *sim2 = new test2(sub->IV, sub->NENTH);
delete sim2;
delete sim1;
delete sub;
}
|
|
|
|
|
hi,
i have developed console program in C language running fine. the program is used to communicate to a motor through serial port. now i wanted to build GUI in MFC vs2008 (some of which i have completed). i'm facing problem in opening serial port as i have done in console program. can any one tell how to implement console program for opening serial port. code below shows how i open serial port in console program.
int COMportNum, BaudRate;
char COMportName[256], tmpChar;
portstream_fd COMstream;
char COMportPrefix[10] = "COM";
COMportName[0] = ' ';
while (COMportName[0] == ' ') {
printf("\nEnter the %s port number the motor is attached to: ", COMportPrefix);
scanf("%d", &COMportNum);
printf("You selected %s%d. Is this OK? (enter 'y' or 'n'): ", COMportPrefix, COMportNum);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
if ( tmpChar == 'y' )
sprintf(COMportName, "%s%d", COMportPrefix, COMportNum);
}
tmpChar = 'f';
while (tmpChar != 'y') {
printf("\nEnter the baud rate the motor communicate at (default: 9600): ");
scanf("%d", &BaudRate);
printf("You selected %d. Is this OK? (enter 'y' or 'n'): ", BaudRate);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
}
set_baud_rate(BaudRate);
COMstream = open_host_port(COMportName);
if ( COMstream == PORT_NOT_OPENED )
{ printf("\nSerial Port setup error.\n");
goto abnormal_exit; }
printf("\nSerial port %s initialized\n", COMportName);
|
|
|
|
|
You would do exactly the same in the MFC program. You could make your comport handler into a class or add it to one of the existing classes. You then activate it by a menu selector or toolbar button.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
can you please send me some reference example sites?
|
|
|
|
|
References for what? If you do not understand MFC then a search of The CodeProject Articles[^], MSDN[^] or even Google, will help. Alternatively there are many books on the market.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
Compensated for the unwarranted univote.
|
|
|
|
|
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
I wish bleedin' univoters would tell people WHY they do it. Mucking Fuppets. How the hell are we supposed to learn if they won't tell us what we're doing wrong...
|
|
|
|
|
Univoters normally include the OP when someone doesn't actually write all their code for them. For some reason, CP forums seem to be seen as the source of free software where you post up a vague problem and miraculously someone will write all your code for you. For free.
|
|
|
|
|
|
I'm sure you are, still bloody irritating though...
|
|
|
|
|
You think Richard is irritating?
|
|
|
|
|
Yep, but don't tell him!
|
|
|
|
|
Ok, take my 1 .
I can't tell you why
I can't tell you why
Veni, vidi, vici.
|
|
|
|
|
In a rather rough approach you may let the user write the full name of the serial port into an edit box (say myEditBox ) and use that string as argument of open_host_port , that is as simple as (assuming a ANSI build):
CString portname;
myEditBox.GetWindowText(portname);
COMstream = open_host_port(portname);
Veni, vidi, vici.
|
|
|
|
|
but open_host_port () is defined as
portstream_fd open_host_port(char *portname)
|
|
|
|
|
Well, that is a open_host_port fault.
Why - the fresh Hell - the function needs a not-const string?
However
COMstream = open_host_port((LPSTR)(LPCSTR) testCStr);
should do the trick.
BTW I ask you once again (I'm curious): what library are you using?
Veni, vidi, vici.
|
|
|
|
|
thank you CPallini. that was really helpful.
|
|
|
|
|
You are welcome.
Veni, vidi, vici.
|
|
|
|
|
I have an dialog with two static methods :
static void StartSomething();
static void EndSomething();
void CMyDialog::StartSomething()
{
GetDlgItem(IDOK)->EnableWindow(FALSE); }
void CMyDialog::EndSomething()
{
GetDlgItem(IDOK)->EnableWindow(); }
How can I disable/enable dialog's OK button from static dialog methods ?
Thank you.
|
|
|
|
|
you will have to find a way to give the static methods a 'this' pointer for the dialog you want to control, or the HWND of the dlg.
|
|
|
|
|
When I've used class objects to represent windows in the past, that's just what I've done.
The way I implemented it was to use the following 3 lines of code:
SetWindowLong(mHwnd, GWL_USERDATA, (long)((void*)this));
mOldWndProc = (WNDPROC)GetWindowLong(mHwnd, GWL_WNDPROC);
SetWindowLong(mHwnd, GWL_WNDPROC, (long)stWinMsgHandler);
This allows the static method stWinMsgHandler to obtain the correct instance of the class that's being used to handle a particular window, as below:
LRESULT CALLBACK cStaticLink::stWinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
cStaticLink *pWnd;
pWnd = (cStaticLink*)GetWindowLong(hwnd, GWL_USERDATA);
if (pWnd)
return pWnd->WndProc(hwnd, uMsg, wParam, lParam);
else
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
|
|
|
|
|
Thank you all, I solve my problem, you are very kind. Got my 5 all of you !!!
|
|
|
|