I have created an MFC Extension DLL that exports some values in the form of CStringList.
Code:
extern "C" DllExport void CaptureWindows(CStringList &lValue);
--------------------------------------------
--------------------------------------------
--------------------------------------------
DllExport void CaptureWindows(CStringList &lValue)
{
::EnumWindows(EnumWindowsProc,NULL);
for (int nIndex = 0; nIndex <strList.GetCount(); nIndex++)
lValue.AddTail(strList.GetAt(strList.FindIndex(nIndex)));
}
Code:
void CHostApplicationDlg::LoadCaptureModule(void)
{
HMODULE hDLL = NULL;
if(hDLL == NULL)
{
CString szModule = _T("CaptureWindows.dll");
hDLL = LoadLibrary(szModule);
if( hDLL == NULL)
{
AfxMessageBox(_T("LoadLibrary Error !!"));
return;
}
typedef void (*lpCaptureWindows)(CStringList &lVaule);
lpCaptureWindows _CaptureWindows = (lpCaptureWindows)GetProcAddress(hDLL, "CaptureWindows");
if( _CaptureWindows == NULL)
{
AfxMessageBox(_T("Get API - Error !!"));
return;
}
CStringList lValue;
_CaptureWindows(lValue);
for (int nIndex=0; nIndex<lValue.GetCount(); nIndex++)
m_lstWindows.AddString(lValue.GetAt(lValue.FindIndex(nIndex)));
}
}
It is working fine but the value of CStringList lValue is coming out to be Garbage when its reverted back into host application. I mean there are 13 items that get stored in stringlist, but their string values (the value field of CStringList) are getting messed up thus showing Garbage.
Although in DLL its showing the correct string value. What could be the reason for this defect?
Thanks in Advance