1

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 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.

Venkatesh Kumar
  • 642
  • 1
  • 7
  • 19
  • You can rethrow an exception, filling the message with localized exception string, if you exception class contains a particular resurce id associated with each thrown exception. – Alan Turing Sep 14 '11 at 05:50

1 Answers1

0

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)
}
Alan Turing
  • 2,482
  • 17
  • 20
  • I don know whether I have made my question unclear or I didn understand your solution. Sorry if did not. I want to use the resource inside a dll inside that dll itself. I do not want to use that in the place where the dll is called. The code errors out inside the dll code where it is trying to use the resources' string table. – Venkatesh Kumar Sep 14 '11 at 23:33