How to use resource files in D

Bill Baxter dnewsgroup at billbaxter.com
Thu Jul 3 17:18:30 PDT 2008


Jim Gadrow wrote:
> Ok, on to my next problem in my unceasing struggle to learn both D and the Windows API at the same time.
> 
> I've done a LOT of searching and cannot manage to find the correct method of creating and using a resource in a windows program.
> 
> What I would like to see is a minimal example of creating a 'hello world' windows application with the strings replaced by string resources.
> 
> Obviously, I have no idea how to import the symbol ID_HELLO into my application. I've tried following one example I saw in one news group that suggested replacing the symbol name with the id value and doing:
> 
> const char* ID_HELLO = cast (char*) 1;
> 
> But that resulted in an Access Violation.
> 
> And declaring something like:
> 
> extern (D)
> const char* ID_HELLO;
> 
> resulted in a message box with an empty message. I've never dealt with resource files before, so this is all new to me. It would probably be nice to have a sample available with all the others that shows the proper way of handling resources.
> 
> I had the following in my .rc file (It's probably wrong...)

First, basic how-to questions like this are supposed to go to 
digitalmars.D.learn.  No biggie though.

As for the answer, you got some answers already about how to compile 
resource files, but I didn't see anyone yet mention that there is a free 
resource compiler called 'rcc.exe' in the BUP (Basic Utilities Package):
     http://ftp.digitalmars.com/bup.zip
It doesn't handle some of the newer extensions to RC files like big 
Vista icons.

That zip also contains the very useful 'implib' program that can be used 
to create dmd import libs from DLLs, so it's worth downloading in any event.

--bb



More information about the Digitalmars-d mailing list