hello guys I was plc programmer just trying to start C programmer
I am trying to convert to this code to function
m_file.Open(posText[7], CStdioFile::modeRead);
m_file.ReadString(posValue[7]);
UpdateData(TRUE);
dlg.s_PostionZ2 = posValue[7];
UpdateData(FALSE);
m_file.Close();
and this my function but it didn't work
void mainDial::opeFile(CString path, CString value, CString location)
{
slaveDialog dlg;
m_file.Open(path, CStdioFile::modeRead);
m_file.ReadString(value);
AfxMessageBox(location);
UpdateData(TRUE);
location = value;
UpdateData(FALSE);
m_file.Close();
}
what I am trying to do is just open a file and save to value and change location value
the problem is the location is in the other dialog (SlaveDialog dlg;)
it is ok by just simply enter dlg.S_position
but if I want it to do with using a function to pass the location like this
opeFile(posText[0], posValue[0], _T("dlg.s_PostionX1"));
or
opeFile(posText[0], posValue[0], dlg.s_PostionX1);
it didn't work both way so how can I change to my function work
thank you for reading
CodePudding user response:
what I am trying to do is just open a file and save to value and change location value
You are passing in the function's output parameters by value, so they make copies of the caller's values. Any changes the function makes to the parameters is done to the copies and not reflected back to the caller.
To do what you want, you need to pass in the output parameters by reference instead, eg:
void mainDial::opeFile(CString path, CString& value, CString& location)