Search code examples
c#stringembedded-resource

Accessing strings in an rc file


I have an rc file conating a string table that is in a dll say X.

I wish to use the strings in this string table in a C# project say Y present in the same solution. If the project Y was C++, I know you can use LoadString function, but for C#, I am not sure.

Can you list out the steps needed?


Solution

  • You can still use LoadString thanks to P-Invoke

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    static extern int LoadString(IntPtr hInstance, uint uID,StringBuilder lpBuffer, int nBufferMax);
    

    Here also defintions of LoadLibrary and FreeLibrary

    [DllImport("kernel32", SetLastError=true, CharSet = CharSet.Unicode)]
    static extern IntPtr LoadLibraryA(string lpFileName);
    
    [DllImport("kernel32.dll", SetLastError=true)]
    static extern bool FreeLibrary(IntPtr hModule);