As if my last question didn't demonstrate my lack of C++ expertise, I will now try to outdo myself.
in cdxuattqr.cpp I have the following code:
if(m_pUAS->GetAndSetSpecs(1, text) > 0)
m_szUAQRHelp = m_pUAS->m_szHelp;
in cdxuattspecs.h I have the follwing code:
public:
int GetAndSetSpecs(int, char *);
CString m_szHelp;
in cdxuattspecs.cpp I have the following code:
char CdxUAttSpecs_path[24]="C:\\tempDBspecfile.txt";
FILE *CdxUAttSpecs_key;
char *CdxUAttSpecs_data=0;
.
.
.
int CCdxUAttSpecs::GetAndSetSpecs(int iopt, char *string)
{
int knt=0, len=0, ichk=0, m, rc;
char *ptr, *ptr2, *ptr3;
rc = -1;
if(iopt)
{
m_szHelp = "No help message";
}
if((CdxUAttSpecs_key=fopen(CdxUAttSpecs_path, "r")))
{
len = filelength(fileno(CdxUAttSpecs_key));
ichk = len + 4;
CdxUAttSpecs_data = (char *) setalloc(&zero, CdxUAttSpecs_data, &ichk);
if(CdxUAttSpecs_data)
{
rc = 0;
knt = fread(CdxUAttSpecs_data, len, 1, CdxUAttSpecs_key);
fclose(CdxUAttSpecs_key);
.
.
.
}
}
}
When the code in cdxuattqr.cpp
if(m_pUAS->GetAndSetSpecs(1, text) > 0)
m_szUAQRHelp = m_pUAS->m_szHelp;
gets executed, I abend as soon as I try to initialize the public variable m_szHelp in GetAndSetSpecs.
If I comment out the line
m_szHelp = "No help message";
everything works fine. Why the problems with the "public" variable and not any of the others?
This is the text of the abend:
First-chance exception at 0x6129a1a3 (mfc90d.dll) in cdx.exe: 0xC0000005: Access violation reading location 0xf8245b20.
First-chance exception at 0x772a47db in cdx.exe: 0xC015000F: The activation context being deactivated is not the most recently activated one.
First-chance exception at 0x77259dc1 in cdx.exe: 0xC0000005: Access violation reading location 0xfeeefefe.
Unhandled exception at 0x77259dc1 in cdx.exe: 0xC0000005: Access violation reading location 0xfeeefefe.
The program '[1156] cdx.exe: Native' has exited with code -1073741819 (0xc0000005).
This is the disassembly of the failing code. The variable "this" is zero. That seems wrong to me.
m_szHelp = "No help message"
100384B0 push offset __real@40c3880000000000+0CCh (10C17F84h)
100384B5 mov ecx,dword ptr [this]
100384B8 add ecx,0ECh
100384BE call dword ptr [__imp_ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > >::operator= (10C0224Ch)]