3
votes

I have a static function in dll which loads string from resource using LoadString(). When I call this function from that dll everything works OK. But, when I call this function from other module (activeX control) LoadString fails with error ERROR_RESOURCE_NAME_NOT_FOUND. I tried with AFX_MANAGE_STATE macro but it didn't help. Does anybody know what could be problem here and what is the solution?

3
Which module handle do you pass into LoadString()?sharptooth
I don't use module handle explicitly. For example: CString strTmp; strTmp.LoadString(IDS_TEMP);Aleksandar

3 Answers

6
votes

If the string is in a resource of the different dll then you have to set the resource handle from the other module to make it work. Try to set the resource handle using AfxSetResourceHandle method.

5
votes

If you do not pass handle to the instance of the module to LoadString then it uses default resource handle. Default resource handle by default is set to current module handle. So if you call LoadString from module that has required string then all works fine. If you call LoadString from other module it could not find required string and you'll get error ERROR_RESOURCE_NAME_NOT_FOUND. You could override it by calling AfxSetResourceHandle function.

Or you could explicitly select module with resources by passing resource handle to LoadString.

2
votes

Please ensure you call AFX_MANAGE_STATE at the beginning of a function so that appropriate (dll or exe) resources are loaded. See also: http://msdn.microsoft.com/en-us/library/ba9d5yh5(VS.80).aspx