lapucca
asked on
How do I get the Variant result to wstring variable?
Hi, Expert,
I have several calls to get different data into a VARIANT var. I need to assign the result of the var to a few different wstring variables. I'm not very famililar with wstring usage and I wonder what's the best way to do this. I currently have a buffer set up to used as a receiveing buffer parameter:
wchar_t *syDataBuffer = new WCHAR[ONE_K];
wstring syData = syDataBuffer;
numCharCopy = GetDlgItemText(hwndDlg, IDC_Indep_Name, syData, ONE_K);
but I feel wrong to just use assignment operator each time for different wstring vaiables. Does the wstring maks a copy of syData using its own allocated memory space? Thanks.
bool CUserPage::SaveSyUserData( HWND hwndDlg, int index)
{
//This method saves the currently display user data of the
//selected context and push into the vector queue
int numCharCopy, size;
wchar_t *syDataBuffer = new WCHAR[ONE_K];
wstring syData = syDataBuffer;
CUserContextData newUserData;
//CString csSyShell;
bool setRet=true, noData=true, validated=false;
if(ListView_GetCheckState( hwndListVi ew, index))
newUserData.symarkEnabled= true;
else
newUserData.symarkEnabled= false;
newUserData.LoginName = NULL;
newUserData.UID = NULL;
......
numCharCopy = GetDlgItemText(hwndDlg, IDC_Indep_Name, syData, ONE_K);
if((numCharCopy <= 0) && (newUserData.symarkEnabled ))
{
::MessageBox(NULL, L"Independent Name is required when you select to use it as the Login Name.", L"Unity - DialogProc", MB_OK);
setRet = false;
goto CleanUp;
}
else if(numCharCopy >0)
{
newUserData.LoginName = syData;
}
}
else
newUserData.bWinLogOn = true;
numCharCopy = GetDlgItemText(hwndDlg, IDC_SHELL, syData, ONE_K);
if((numCharCopy <= 0) && (newUserData.symarkEnabled ))
{
::MessageBox(NULL, L"Shell specification is mandatory.", L"Unity - SaveSyUserData", MB_OK);
setRet = false;
goto CleanUp;
}
else if(numCharCopy > 0)
{
newUserData.shell = syData
noData = false;
}
I have several calls to get different data into a VARIANT var. I need to assign the result of the var to a few different wstring variables. I'm not very famililar with wstring usage and I wonder what's the best way to do this. I currently have a buffer set up to used as a receiveing buffer parameter:
wchar_t *syDataBuffer = new WCHAR[ONE_K];
wstring syData = syDataBuffer;
numCharCopy = GetDlgItemText(hwndDlg, IDC_Indep_Name, syData, ONE_K);
but I feel wrong to just use assignment operator each time for different wstring vaiables. Does the wstring maks a copy of syData using its own allocated memory space? Thanks.
bool CUserPage::SaveSyUserData(
{
//This method saves the currently display user data of the
//selected context and push into the vector queue
int numCharCopy, size;
wchar_t *syDataBuffer = new WCHAR[ONE_K];
wstring syData = syDataBuffer;
CUserContextData newUserData;
//CString csSyShell;
bool setRet=true, noData=true, validated=false;
if(ListView_GetCheckState(
newUserData.symarkEnabled=
else
newUserData.symarkEnabled=
newUserData.LoginName = NULL;
newUserData.UID = NULL;
......
numCharCopy = GetDlgItemText(hwndDlg, IDC_Indep_Name, syData, ONE_K);
if((numCharCopy <= 0) && (newUserData.symarkEnabled
{
::MessageBox(NULL, L"Independent Name is required when you select to use it as the Login Name.", L"Unity - DialogProc", MB_OK);
setRet = false;
goto CleanUp;
}
else if(numCharCopy >0)
{
newUserData.LoginName = syData;
}
}
else
newUserData.bWinLogOn = true;
numCharCopy = GetDlgItemText(hwndDlg, IDC_SHELL, syData, ONE_K);
if((numCharCopy <= 0) && (newUserData.symarkEnabled
{
::MessageBox(NULL, L"Shell specification is mandatory.", L"Unity - SaveSyUserData", MB_OK);
setRet = false;
goto CleanUp;
}
else if(numCharCopy > 0)
{
newUserData.shell = syData
noData = false;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much.
ASKER
numCharCopy = GetDlgItemText(hwndDlg, IDC_Indep_Name, syData, ONE_K);
and change it to something like this?
numCharCopy = GetDlgItemText(hwndDlg, IDC_Indep_Name, &(newUserData.LoginName), ONE_K);
Would this be OK to do? Thanks.