PATCHWISE.COM
The Creative Development Company
  Log in to check your private messagesLog in to check your private messages   Log inLog in 
  PatchWise Software Community ...................................................................................................................
FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile 

LocWise to add language packs to MFC Extension DLL

 
Post new topic   Reply to topic    PatchWise Software Community Forum Index -> LocWise Multilingual SDK Support
View previous topic :: View next topic  
Author Message
cecker



Joined: 18 Mar 2003
Posts: 4

PostPosted: Mar 18, 2003 3:29 am    Post subject: LocWise to add language packs to MFC Extension DLL Reply with quote

I want to use LocWise to add language packs to a MFC extension DLL. The DLL has just a string table I want to put into the language pack. Are there instructions available how to do this? I just saw examples for complete applications.

Thanks!
Back to top
View user's profile Send private message
Support
Site Admin


Joined: 03 Nov 2002
Posts: 118

PostPosted: Mar 18, 2003 3:50 am    Post subject: Reply with quote

Open the dll as resource in Visual C++, then save as resource script(.rc). Launch LangGen for LocWise, to generate language pack from .rc.
_________________
At Your Service
The PatchWise Software Support Team
Back to top
View user's profile Send private message Visit poster's website
cecker



Joined: 18 Mar 2003
Posts: 4

PostPosted: Mar 18, 2003 12:24 pm    Post subject: Reply with quote

The question was more like where to put LocWise init and exit routines. Could you give me some instructions?

Thanks!
Back to top
View user's profile Send private message
Support
Site Admin


Joined: 03 Nov 2002
Posts: 118

PostPosted: Mar 18, 2003 5:57 pm    Post subject: Reply with quote

There are two ways, if you like to generate an individual language pack for you dll, you can put LocWise init and exit routines in the DllMain function like this:
Code:

BOOL WINAPI DllMain(
  HINSTANCE hinstDLL,  // handle to the DLL module
  DWORD fdwReason,     // reason for calling function
  LPVOID lpvReserved   // reserved
)
{
   switch (fdwReason)
   {
   // When process starts, do initialize jobs
   case DLL_PROCESS_ATTACH:
      ...
      LcwInitLocalization(ID_LANGUAGE_FIRST, MAX_LANGUAGES);
      LcwLoadLangs(strLangPath, _T("LXX???.lng"), _T(""));
      LcwSetDefaultLang();
      ...
      break;
   case DLL_THREAD_ATTACH:
   case DLL_THREAD_DETACH:
      break;

   // When process terminates, free any remaining menory
   case DLL_PROCESS_DETACH:
      ...
      LcwPurgeLangs();
      LcwExitLocalization();
      ...
      break;
   }
   return TRUE;
}


If you don't need an individual language pack for you dll, you don't need do any init and exit routines in the dll. Let the main exe do it.
_________________
At Your Service
The PatchWise Software Support Team
Back to top
View user's profile Send private message Visit poster's website
cecker



Joined: 18 Mar 2003
Posts: 4

PostPosted: Mar 18, 2003 11:12 pm    Post subject: Reply with quote

Thanks a lot! This is the info I needed.
Back to top
View user's profile Send private message
cecker



Joined: 18 Mar 2003
Posts: 4

PostPosted: Mar 24, 2003 9:33 am    Post subject: Reply with quote

Hi!
I bought LocWise and started adding the Locwise API into my MFC Extension DLL. Did not work well for me, I want to share my experience with you.

I did initialization and exit stuff as previously posted, that worked fine.
Then I replaced my calls like e.g. description.LoadString((UINT)m_ErrorNumber) where description is CString into LcwLoadString(UINT,CString&), however this did no work (Got no string back).
Then I started digging ......
Looking at the source code of LocWise and saw that internally LcwLoadStringEx(AfxGetApp()->m_hInstance, .... is called. My understanding is that this means that the wrong hInstance is used.
Looking to the MFC source code, internally AfxLoadString is used.
According to the docu LcwLoadString is MFC compatible.
So I used the second form of LcwLoadString passing the hInstance of the MFC Extension DLL.
Took me quite a time to figure this out.

So my summary is the following, please correct me if I'm wrong:
LcwLoadString(UINT,CString&) is not MFC compatible.
LcwLoadString(UINT,CString&) should be improved.

Best regards

Chris
Back to top
View user's profile Send private message
Support
Site Admin


Joined: 03 Nov 2002
Posts: 118

PostPosted: Mar 24, 2003 9:46 am    Post subject: Reply with quote

Yes, you are right, it should be
LcwLoadStringEx(AfxGetInstanceHandle(), nID, ...
to get the string resource from the extern DLL, it's fixed, the new release with other improvements and a new tool LangSync for language updating is coming in days. We are doing final document checking.
_________________
At Your Service
The PatchWise Software Support Team
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Mar 24, 2003 11:18 am    Post subject: Reply with quote

During investigation I also tried AfxGetInstanceHandle(), however it also did not work.
I had to put in: ExtensionDLL.hResource
Maybe should build a little MFC Extension DLL and try it out yourself.

Best regards

Chris
Back to top
Support
Site Admin


Joined: 03 Nov 2002
Posts: 118

PostPosted: Mar 24, 2003 11:28 am    Post subject: Reply with quote

Ok, we'll test it, but according to the explain from MSDN, If called from within a DLL linked with the USRDLL version of MFC, an HINSTANCE to the DLL will be returned by AfxGetInstanceHandle().
_________________
At Your Service
The PatchWise Software Support Team
Back to top
View user's profile Send private message Visit poster's website
Support
Site Admin


Joined: 03 Nov 2002
Posts: 118

PostPosted: Mar 24, 2003 1:27 pm    Post subject: Reply with quote

Remarks from MSDN:
The AfxGetInstanceHandle function allows you to retrieve the instance handle of the current application. AfxGetInstanceHandle always returns the HINSTANCE of your executable file (.EXE) unless it is called from within a DLL linked with the USRDLL version of MFC. In this case, it returns an HINSTANCE to the DLL.

Our test result came out: If the LcwLoadString(UINT,CString&) function(the fixed version) is called from the (.EXE) file it cannot get the string from the resource of the DLL. If it is called from within the MFC DLL and the DLL is derived from CWinApp, it can load the string resource into
the CString object successfully. and the macro AFX_MANAGE_STATE(AfxGetStaticModuleState()); must be added at the very beginning of the function.

The MFC extension DLL is not derived from CWinApp, so you cannot get the right HINSTANCE to the DLL by calling AfxGetInstanceHandle. The regular MFC DLL generated by AppWizard is linked with the USRDLL version of MFC, and is derived from CWinApp, you can get the right HINSTANCE to the DLL by calling AfxGetInstanceHandle from within the DLL.

The LcwLoadString(UINT, CString&) behaves exactly like CString::LoadString(UINT). Please try the CString::LoadString(UINT) too.
_________________
At Your Service
The PatchWise Software Support Team
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Mar 24, 2003 1:53 pm    Post subject: Reply with quote

Not sure whether I understood correctly. I think you are saying that CString::LoadString() should fail too, if called from the MFC Extension DLL.

Below code is from my MFC Extension DLL, just the code inside the #ifdef was added. You still see the old code, that was working.

Greetings,

Chris

Code:

int CErrorCodes::GetErrorNumber(CString &description)
{
#ifdef   LWLANGPACK
   if(LcwGetCurrentLangNode()!=NULL)   
   {      
      if(LcwLoadStringMFCExtDll((UINT)m_ErrorNumber,description)==true)
      {
         //Success
         return(m_ErrorNumber);
      }
      else
      {
         TRACE("LcwLoadStringMFCExtDll() did not load resource id: %d\n",m_ErrorNumber);
         
      }
      //else use the standard resource
   }
   else
   {
      TRACE0("No language pack set!\n");
      
   }
   TRACE0("Using default resource.\n");
   //else use the standard resource
#endif
   if(!description.LoadString((UINT)m_ErrorNumber))
   {   
      //No error description available
      description.Empty();
   }
   return(m_ErrorNumber);
}

bool CErrorCodes::LcwLoadStringMFCExtDll(UINT nID,CString &strBuffer)
{
#ifdef LWLANGPACK
   int ret;
   
   ret=LcwLoadString(KTDauLibDLL.hResource,nID,strBuffer.GetBuffer(1024),1024);
   strBuffer.ReleaseBuffer();
   if(ret==0)
   {
      return false;
   }
   return true;
#else
   strBuffer="LWLANGPACK is not defined!";
   return false;
#endif
}
Back to top
Support
Site Admin


Joined: 03 Nov 2002
Posts: 118

PostPosted: Mar 25, 2003 10:25 am    Post subject: Reply with quote

We apologize for our careless mistake. After fully test, we found CString::LoadString(UINT) behaves diffrent in MFC extension DLL, regular DLL with static MFC link and regular DLL using shared MFC DLL. So we rewrite the code of LcwLoadString(UINT, CString&), now it behaves exactly like CString::LoadString(UINT).
_________________
At Your Service
The PatchWise Software Support Team
Back to top
View user's profile Send private message Visit poster's website
Support
Site Admin


Joined: 03 Nov 2002
Posts: 118

PostPosted: Apr 10, 2003 9:09 am    Post subject: Reply with quote

The new version of LocWise is released, this bug is fixed. Please check it out.
_________________
At Your Service
The PatchWise Software Support Team
Back to top
View user's profile Send private message Visit poster's website
Develop



Joined: 21 Jan 2003
Posts: 26

PostPosted: Jul 09, 2004 8:07 am    Post subject: MFC extension DLL with LocWise support sample Reply with quote

The source code for MFC extension DLL with LocWise support sample can be found at http://www.patchwise.com/forums/viewtopic.php?p=282#282
_________________
We need your feedback
The PatchWise Software Develop Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    PatchWise Software Community Forum Index -> LocWise Multilingual SDK Support All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Powered by phpBB © 2001, 2002 phpBB Group
 
©  2002 Hanmen Software, Inc. All rights reserved.  | Terms of Use | Privacy Statement