U
uny ternally
I was experimenting in Visual C++ and ran into the following problem.
I have the struct listed below. I also have a function that passes a
variable of the struct type by reference and set the values. When I
access the struct in the global space after calling the function the
integer value is correcty, however the LPTSTR value is empty. Help.
Below is the code I'm playing with.
Thanks.
typedef struct conf
{
LPTSTR entry1;
int entry2;
};
bool GetConf(conf& config)
{
CString value;
DWORD dwSize = MAX_PATH;
DWORD val2;
LPTSTR val = value.GetBuffer(1000);
// code setting val and val2
config.entry1 = val2;
config.entry2 = val;
std::cout << "inside: " << config.entry2 << "\n";
// config.entry2 dispalys properly here
return TRUE;
}
.... inside of main
bool returnval;
conf cony;
returnval = GetConf(cony);
std::cout << "outside: " << cony.entry2 << "\n";
\\here cony.entry2 is empty. Note if both cout's are changed from
entry2 to entry they work correctly both inside and outside.
thanks again
I have the struct listed below. I also have a function that passes a
variable of the struct type by reference and set the values. When I
access the struct in the global space after calling the function the
integer value is correcty, however the LPTSTR value is empty. Help.
Below is the code I'm playing with.
Thanks.
typedef struct conf
{
LPTSTR entry1;
int entry2;
};
bool GetConf(conf& config)
{
CString value;
DWORD dwSize = MAX_PATH;
DWORD val2;
LPTSTR val = value.GetBuffer(1000);
// code setting val and val2
config.entry1 = val2;
config.entry2 = val;
std::cout << "inside: " << config.entry2 << "\n";
// config.entry2 dispalys properly here
return TRUE;
}
.... inside of main
bool returnval;
conf cony;
returnval = GetConf(cony);
std::cout << "outside: " << cony.entry2 << "\n";
\\here cony.entry2 is empty. Note if both cout's are changed from
entry2 to entry they work correctly both inside and outside.
thanks again