Problem while exporting Values from DLL
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
Re: Problem while exporting Values from DLL
I am not sure if its garbage value, but it shows some Chinese Characters instead of actual strings
Re: Problem while exporting Values from DLL
Quote:
Originally Posted by
maverick786us
It is working fine but the value of CStringList lValue is coming out to be Garbage when its reverted back into host application.
:confused:
So "working fine" or it fails because of "to be Garbage"? :confused:
Some questions:
- How did you built your exe and dll: ANSI or UNICODE?
- What is the reason to declare the CaptureWindows as extern "C"?
- Why not just link your MFC exe to your MFC dll rather than using LoadLibrary/GetProcAddress?
- What is strList used in CaptureWindows? where and how is it declared?
Besides, using underline as a prefix in native VC++ looks like a bad style: underline is reserved by Microsoft.
Re: Problem while exporting Values from DLL
OK I changed the characterset of Host Application into Multi-Byte and it worked fine. Thanks. This DLL will be used with a JAVA Program
Re: Problem while exporting Values from DLL
can you tell how did you change the Host Application into Multi-Byte?
Re: Problem while exporting Values from DLL
Quote:
Originally Posted by
vcdebugger
can you tell how did you change the Host Application into Multi-Byte?
There is a setting 'Character Set' in the project properties where you can switch between MS UNICODE and MULTI-BYTE (ANSI)
Re: Problem while exporting Values from DLL
thanks :)
In fact if I would have hesitated to ask this question ( which i did.. of course ) then I would assumed that multi-byte is---> Unicode and Single Byte is --- > Ascii :D
Anyways.. if Ascii is multibyte then what about UNICODE which takes more space/bytes or whatever to represent?