Consuming a library with CObArray throwing "Invalid address specified to RtlValidateHeap"

  • Thread starter Thread starter A Cpp Dev
  • Start date Start date
A

A Cpp Dev

Guest
Hi,

I want to develop a library using latest C++ features. For this I am using VS2017 version. This library will export a method and its output argument is CObArray as shown below:

#ifdef EXPORT
#define EXPORT_API __declspec(dllexport)
#else
#define EXPORT_API __declspec(dllimport)
#endif

class EXPORT_API CTestClass : public CObject

{

public:

CString m_strName;

int m_iID;

CTestClass(){m_strName = ""; m_iID = 0;}

~CTestClass(){}

}

class EXPORT_API CTestMe

{

public:


BOOL TestMe(int x, CObArray& myArr);

}


BOOL CTestMe::TestMe(int x, CObArray& myArr)

{

CTestClass obj;

obj.m_strName = "Hello";

obj.m_iID = x;

myArr.Add(obj);

return TRUE;

}

The DLL was built successfully and ready to use.

Now I have a client application developed in Visual Studio 2008. I want to use this newly created DLL functionality.

CTestMe myTestObj;

CObArray myArr;

BOOL bRet= myTestObj.TestMe(1, myArr);
for(int i = 0; i < myArr.GetSize(); i++)
{
CTestClass * temp_obj = (CTestClass *)myArr.GetAt(i);
if (temp_obj != NULL)
{
AfxMessageBox(temp_obj->m_strName);
}
}
I am able to get the data from the DLL. But receiving the heap corruption error such as "Invalid address specified to RtlValidateHeap". Is it because of different compilers? Can someone clarify me on this.

Should we not use libraries developed with latest compilers in older clients?

Error Received: _CrtlsValidHeapPointer(pUserData) in the main window, and Invalid address specified to RtlValidateHeap in the TRACE window.


Thanks

Continue reading...
 
Back
Top