The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: sharpe on June 22, 2011, 11:55:43 AM

Title: Reading resource sections
Post by: sharpe on June 22, 2011, 11:55:43 AM
Hi all,

I am writing a small app that stores an image and an MP3 file in the app itself as resources, which is used by the app after it is running.
I have tried to to read the resources using the FindResource() API but am having all sorts of trouble (LastError = 718h).
Does anyone have an example or perhaps some tips regarding this?

I look forward to hearing from you.

regards,
sharpe.
Title: Re: Reading resource sections
Post by: dedndave on June 22, 2011, 01:57:19 PM
in the resource file, you assign a unique ID number, then refer to that ID
here is a simple example with a sound file...
http://www.masm32.com/board/index.php?action=dlattach;topic=15882.0;id=8764

in the ASM file, notice the EQUate
IDS_PMF EQU     1000
;
;
;
        INVOKE  PlaySound,IDS_PMF,hInstance,SND_RESOURCE


and, in the resource file...
#define  IDS_PMF  1000

IDS_PMF  WAVE DISCARDABLE "PMF.wav"

the resource text for a bitmap is very similar, except you use "BITMAP" instead of "WAVE"
Title: Re: Reading resource sections
Post by: sharpe on June 22, 2011, 02:41:22 PM
Sweet, you just gave me another idea, nice.
But if I didn't want to play them, just access the raw data of the image and mp3, would find resource work?

INVOKE PlaySound... nice..

Thanks.
Title: Re: Reading resource sections
Post by: baltoro on June 22, 2011, 04:01:16 PM
Here is an old MSDN article (1994) by Matt Pietrek: Peering Inside the PE: A Tour of the Win32 Portable Executable File Format (http://msdn.microsoft.com/en-us/library/ms809762.aspx). Scroll down about 3/4 of the way, and, there is a section that describes the PE File Resources. It's good stuff,...but, some serious overkill.

Title: Re: Reading resource sections
Post by: sharpe on June 22, 2011, 05:29:32 PM
baltoro,

I know that article, awesome. I'll have a butchers.
Thanks!
Title: Re: Reading resource sections
Post by: Vortex on June 22, 2011, 06:58:51 PM
Hi sharpe,

Why not to embed the image and the sound file into the executable? The trick is to convert binary files to MS COFF object modules to be linked with your project module.
Title: Re: Reading resource sections
Post by: baltoro on June 22, 2011, 08:00:00 PM
Here is an example from MSDN: Using Resources (http://msdn.microsoft.com/en-us/library/ms648008(v=vs.85).aspx)
Title: Re: Reading resource sections
Post by: Vortex on June 25, 2011, 08:51:33 AM
Hi sharpe,

Here is a resource example for you.
Title: Re: Reading resource sections
Post by: sharpe on August 30, 2011, 10:55:52 AM
Hi Vortex, that's smashing, thanks very much!