I have a global function passed as a .dll to a client application:
Inside dll application, in RegSys.h:
__declspec(dllexport) CRegSysData* GetData();
In RegSys.cpp:
CRegSysData* GetData()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState( )
CRegSysData* pData = new CRegSysData(); // here memory is allocated, but where should I free it
pData->m_dllValue = 100; // sample code
return pData;
}
Then in the client application TestBench.cpp:
CRegSysData* pD = GetData();
m_clientValue = pD->m_dllvalue;
// compilor will complain if I delete pD here.
}
I also can't delete pData in a class or ExitInstance of RegSys Application, since it's a global function, pData doesn't belong to any class. If I make the dll function inside the RegSysApp, then I may delete it in the ExitInstance function of RegSysApp, but how can I import this class based .dll function to the client application
Any comments will be appreciated.

How to delete a pointer passed by a .dll
Benj78
TestBench error LNK2019: unresolved external symbol "public: __thiscall CRegSysData::~CRegSysData(void)" ( 1CRegSysData@@QAE@XZ) referenced in function "public: void * __thiscall CRegSysData::`scalar deleting destructor'(unsigned int)" ( _GCRegSysData@@QAEPAXI@Z)
TestBench fatal error LNK1120: 1 unresolved externals
It complains about the destructor.
Leaf.
Right. And what you had before is a linker error, not a compiler error.
class __declspec(dllexport) RegSysData { ... } will do it, as you noted.
PK2000
What's the compiler error
sascue
It has just been resolved by export "RegSysData" class as well, then no complaint for the destructor call.
Thanks!