MFC LoadString error in dll

I have a static function in a dll that loads a string from a resource using LoadString (). When I call this function from this DLL, everything works fine. But, when I call this function from another module (activeX control), the LoadString fails with the error ERROR_RESOURCE_NAME_NOT_FOUND. I tried using the AFX_MANAGE_STATE macro, but that did not help. Does anyone know what could be the problem here and what is the solution?

+3
source share
3 answers

If the string is in a resource of another dll, you need to install the resource descriptor from another module for it to work. Try setting the resource descriptor using the AfxSetResourceHandle method .

+6
source

If you do not pass the handle to the module instance in LoadString, then it uses the default resource handle. By default, the resource descriptor is set to the current module descriptor by default. Therefore, if you call LoadStringfrom the module with the required string, everything works fine. If you call LoadStringfrom another module, it cannot find the required line, and you will receive an error message ERROR_RESOURCE_NAME_NOT_FOUND. You can override it by calling a function AfxSetResourceHandle.

, LoadString.

+5

Please make sure you call AFX_MANAGE_STATE at the beginning of the function to load the appropriate resources (dll or exe). See also: http://msdn.microsoft.com/en-us/library/ba9d5yh5(VS.80).aspx

+2
source

Source: https://habr.com/ru/post/1713323/


All Articles