0

We would like to list the contents (key/value pairs) of an unmanaged resource library (DLL) in C#.
(Please note, the resource DLL is NOT a .Net assembly/DLL)

The resource library is defined as specified in MSDN.

mc -s EventLogMsgs.mc
rc EventLogMsgs.rc
link /DLL /SUBSYSTEM:WINDOWS /NOENTRY /MACHINE:x86 EventLogMsgs.Res 

A sample EventLogMsgs.mc may be:

; // - Event categories -
; // Categories must be numbered consecutively starting at 1.
; // ********************************************************

MessageId=0x1
Severity=Success
SymbolicName=INSTALL_CATEGORY
Language=English
Installation
.

MessageId=0x2
Severity=Success
SymbolicName=QUERY_CATEGORY
Language=English
Database Query
.

...

If this resource library DLL were a .Net assembly DLL, listing the resources would be done using something along these lines:

string strResourceDLLPath = "c:\\temp\\EventLogMsgs.DLL";

Assembly resAssembly = Assembly.LoadFrom( strResourceDLLPath );
ResourceManager resMgr = new ResourceManager( "ResourcesLib.Messages", resAssembly );
ResourceSet resSet = resMgr.GetResourceSet( System.Globalization.CultureInfo.CurrentCulture, true, true );

foreach (DictionaryEntry r in resSet)
    Console.WriteLine( "Key={0} Value={1}", r.Key.ToString(), r.Value.ToString() );

Thanks!

alexg
  • 653
  • 7
  • 29
  • `ResourceManager` is for managed resources. – Daniel A. White Jun 06 '14 at 15:31
  • Agreed, ResourceManager can NOT be used for this purpose. The code snippet was just a demonstration of what we're trying to achieve for a non-managed resource. – alexg Jun 06 '14 at 15:33
  • 2
    I think you have to use the win32 api. – Daniel A. White Jun 06 '14 at 15:36
  • 1
    Look at [this post](http://stackoverflow.com/questions/8242578/how-to-findresource-pinvoke-a-string-resource-in-c), it has sample of how to load resource from unmanaged dll using imported win32 API functions. – Alexander Jun 06 '14 at 20:53

1 Answers1

0

This post contains a win32 API solution for listing the message details in a resource-only DLL.

In order to be able to do the same in C#, P/Invoke would have to be utilized.

Community
  • 1
  • 1
alexg
  • 653
  • 7
  • 29