tags:

views:

378

answers:

2

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?

+4  A: 

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.

Naveen
I don't use resource handle (I use CString's LoadString). I call LoadString from class/function that belongs to that dll. And then I call that function from activeX.
Aleksandar
@Aleksandar: Unless you pass the module handle into CString::LoadString() it will only search within the current module. There's no way around that.
sharptooth
+3  A: 

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.

Kirill V. Lyadvinsky