Background. I am writing a managed c++ wrapper for legacy unmanaged code. I created a test application in C# to create the legacywrapper and I am attempting to get some value returned from legacy.
I am receiving a System.AccessViolationException at the end of this function...
Expand|Select|Wrap|Line Numbers
- void LegacyWrapper::LegacyWrap::GetValue(String^ dataPath, Object^% pValue)
- {
- // This stuff is just used to build up the correct legacy database
- // to query information based on a the passed in data path.
- LegacyDatabaseInfo^ dbInfo = gcnew LegacyDatabaseInfo();
- GetDbInfo(dataPath, dbInfo);
- // The Application Controller is simply a entrance into the legacy code
- ApplicationController* appCntrl =
- m_legacyCtrl->GetApplicationController(dbInfo->dbID);
- string tmp;
- appCntrl->GetValue(dbInfo->fieldID, dbInfo->recordIndex, &tmp);
- String^ pValueStr = gcnew String(tmp.c_str());
- if(pValueStr != nullptr)
- {
- pValue = pValueStr;
- }
- else
- {
- pValue = String::Empty;
- }
- // **********************************************
- // This is where I get the AccessViolationException
- // **********************************************
- }
LegacyWrapper.dll!<Module>.CStdStr<wchar_t>.{dtor} () + 0x18 bytes
LegacyWrapper.dll!<Module>.string.{dtor}() + 0x19 bytes
LegacyWrapper.dll!LegacyWrapper::LegacyWrap::GetVa lue(System::String^ dataPath = "DB_REG_MANAGERID:F_RegDTCSizeID:0", System::Object^ pValue = {System::String^}) Line 884 + 0x9 bytes C++
TestLegacy.exe!TestLegacy.Program.Main(string[] args = {Dimensions:[0]}) Line 17 + 0x12 bytes C#
It looks as if the exception is being thrown when the function is destroying the tmp string...I do not know why...Any suggestions? Thanks in advance...