CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Apr 2005
    Posts
    1,828

    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)));
    }
    Host Application
    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
    Last edited by maverick786us; December 22nd, 2010 at 02:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured