I'm working on a proprietary code base, so I have to abstract this.
I'm trying to set the value of DataType_T*** myData in MyApplication. I'm using a shared c++ library (which I denote library A) to set the value. The shared c++ library is just a simple wrapper class around a C API.The C API is included in library A as a shared library (which I denote library B).
So MyApplication calls GetData(myData) in A which calls GetData(myData) in B.
MyApplication has the following code:
void OnButtonPress(){
const DataType*** myData;
GetData(myData);
DataTypeVal1 val1 = (*myData)[0]->val1; // just grabbing some info.
}
GetData(myData): works, and properly sets myData.
Me: types some new code
void OnButtonPress(){
const DataType*** myData;
GetData(myData);
const void* strData = (*myData)[0]->strData; // just grabbing some info now that we have the pointer.
//Add lots more new code that does this over and over for each member of myData
String^ str = gcnew String(static_cast<const char*>(strData));
}
GetData(myData): throws a write access violation.
Me: ". . . . . . .what."
Could the exception be getting thrown because of some sort of dll unloading?
Is there a possibility that the linking process changes when I type new code?
I haven't encountered an issue like this before, so I don't really know how to debug this.
Got suggestions?
Thanks.
Solved. I found my undefined behavior.
I think you want something like this:
Because in the original code you're just passing a pointer by value; an uninitialized pointer, and then accessing that same uninitialized value.
ed: fixed up the third line