CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  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.

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

    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

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Problem while exporting Values from DLL

    Quote Originally Posted by maverick786us View Post
    It is working fine but the value of CStringList lValue is coming out to be Garbage when its reverted back into host application.

    So "working fine" or it fails because of "to be Garbage"?

    Some questions:
    1. How did you built your exe and dll: ANSI or UNICODE?
    2. What is the reason to declare the CaptureWindows as extern "C"?
    3. Why not just link your MFC exe to your MFC dll rather than using LoadLibrary/GetProcAddress?
    4. 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.
    Victor Nijegorodov

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

    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

  5. #5
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: Problem while exporting Values from DLL

    can you tell how did you change the Host Application into Multi-Byte?

  6. #6
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Problem while exporting Values from DLL

    Quote Originally Posted by vcdebugger View Post
    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)

  7. #7
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    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

    Anyways.. if Ascii is multibyte then what about UNICODE which takes more space/bytes or whatever to represent?
    Last edited by vcdebugger; December 22nd, 2010 at 05:39 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