Posts

Showing posts from September, 2007

MAKEINTRESOURCE macro

Many Win32 API functions use a LPCTSTR parameter as resource name or type. For example, a trivial one: HICON LoadIcon(HINSTANCE hInstance, LPCTSTR lpIconName); And the documentation for the lpIconName states that: Pointer to a null-terminated string that contains the name of the icon resource to be loaded. Alternatively, this parameter can contain the resource identifier in the low-order word and zero in the high-order word. Use the MAKEINTRESOURCE macro to create this value. Now, how the LoadIcon code knows to diferentiate between a resource string name and a predefined constant like IDI_ASTERISK which is defined as: #define IDI_ASTERISK MAKEINTRESOURCE(32516) We are used to the wizard generated resource IDs in our applications but a resource can have any null terminated string as name and type too. Look to the FindResource function for example. All resource Win32API functions use the macro IS_INTRESOURCE(id) BOOL IS_INTRESOURCE( WORD wInteger ); #define I

Navigating to an embedded resource in .NET

This task is very common but since i did not find a clear and simple solution i decided to write it. I have a simple C# application which has a webbrowser control and i want to use the res:// protocol to navigate to an embedded resource, a html file from the assembly, like this: webbrowser.Navigate("res://myApp.exe/Help.htm"); since managed resources are not native ones, adding an html file to the project and select "embedded resource" wont help. if you open the assembly with a resource editor you won;t see the html resource. hence, the res:// protocol wont work. so i wrote this simple console application which accepts as parameters the resource file you want to add. Usage: AddResourceManaged.exe ExePath ResFile ResName [ResType] adds a new resource to an exe file ExePath - path of the exe ResFile - path of the file to be added as a resource ResName - name of the resource ResType - (optional) type of the resource; if omitted, the application will try to use o