简体   繁体   English

dll中的MFC LoadString失败

[英]MFC LoadString in dll fails

I have a static function in dll which loads string from resource using LoadString(). 我在dll中有一个静态函数,它使用LoadString()从资源加载字符串。 When I call this function from that dll everything works OK. 当我从那个dll调用这个函数时一切正常。 But, when I call this function from other module (activeX control) LoadString fails with error ERROR_RESOURCE_NAME_NOT_FOUND. 但是,当我从其他模块(activeX控件)调用此函数时,LoadString失败,错误为ERROR_RESOURCE_NAME_NOT_FOUND。 I tried with AFX_MANAGE_STATE macro but it didn't help. 我尝试使用AFX_MANAGE_STATE宏,但它没有帮助。 Does anybody know what could be problem here and what is the solution? 有谁知道这里有什么问题,解决方案是什么?

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. 如果字符串位于不同dll的资源中,则必须从其他模块设置资源句柄以使其工作。 Try to set the resource handle using AfxSetResourceHandle method. 尝试使用AfxSetResourceHandle方法设置资源句柄。

If you do not pass handle to the instance of the module to LoadString then it uses default resource handle. 如果未将模块实例的句柄传递给LoadString则它使用默认资源句柄。 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. 因此,如果从具有必需字符串的模块调用LoadString ,那么一切正常。 If you call LoadString from other module it could not find required string and you'll get error ERROR_RESOURCE_NAME_NOT_FOUND . 如果从其他模块调用LoadString ,则无法找到所需的字符串,您将收到错误ERROR_RESOURCE_NAME_NOT_FOUND You could override it by calling AfxSetResourceHandle function. 您可以通过调用AfxSetResourceHandle函数来覆盖它。

Or you could explicitly select module with resources by passing resource handle to LoadString . 或者您可以通过将资源句柄传递给LoadString来显式选择具有资源的模块。

Please ensure you call AFX_MANAGE_STATE at the beginning of a function so that appropriate (dll or exe) resources are loaded. 请确保在函数开头调用AFX_MANAGE_STATE,以便加载适当的(dll或exe)资源。 See also: http://msdn.microsoft.com/en-us/library/ba9d5yh5(VS.80).aspx 另见: http//msdn.microsoft.com/en-us/library/ba9d5yh5(VS.80).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM