I have an unmanaged MFC application. I have written a CLI wrapper for the application and converted into a DLL. The unamanged code has string table resources that is used to display messages here and there.
Now I can call the unmanaged code from C# and开发者_如何学Go use the internal logic. But the code errors out when it tries to read a resource string. I hope the resources are not loaded so I tried including a P/invoke LoadLibraryEx from kernel32.dll but still no use. How can I let the unmanaged code use its resource file? Can it do that or it should be modifed??
Thanks.
You can rebuilt MFC using UNICODE strings, declare exported function, whick takes a language id, an ID of the resource string, and return string for that reference ID and locale.
And use it in managed assembly as follows
[DllImport("resource.en-US.dll")]
string GetResourceString(int LANGUAGE_ID, int IID);
And, for example:
try
{
...
}
catch(MyException ex)
{
throw new ApplicationException(GetResourceString(ex.Language, ex.ResourceID), ex)
}
精彩评论