Hi-

Does anyone know of sample code that would show me how to accomplish this:
embed a bitmap file into a project (and subsequently my DLL)
then write that embedded data to file at runtime?

I'm developing a plugin and using there UI library, I want to create the
file at runtime to prevent users from replacing the file with there own
version.

Thanks for any help,
Steve

Re: embedding bitmap by William

William
Mon Mar 01 20:29:17 CST 2004

"Steve" <steve@nowhere.com> wrote in message
news:%23LYuLj9$DHA.392@TK2MSFTNGP12.phx.gbl...
> Does anyone know of sample code that would show me how to accomplish this:
> embed a bitmap file into a project (and subsequently my DLL)
> then write that embedded data to file at runtime?

You may want to check an introductory text like Petzold's Programming
Windows. But basically, you just create a line in your resource script along
the lines of

name BITMAP MOVEABLE bitmapFileName

and when the resource compiler binds the resources to the executable the
bitmap will be part of the executable. If you use Visual Studio version 6
you can do that from the Insert menu. VS.Net has the option on the project
menu. At runtime you load the bitmap with LoadBitmap(). If you use a
numberic (#define) name for the bitmap you use MAKEINTRESOURCE() to create a
"string" name to pass to LoadBitmap().

Does that help?

Regards,
Will




Re: embedding bitmap by Steve

Steve
Tue Mar 02 12:40:51 CST 2004

From what I can find on MSDN, LoadBitmap() is a GDI call

I don't want to load a bitmap so much as I want to utilize a project
resource and somehow write it to a physical file on disk.
It may be that I can do that with LoadBitmap() somehow, I just don't see it.

Here is another example, let's say that you had an avi file that you wanted
to embed in your DLL, then create the pyhsical file at runtime... is that
possible?

Thanks for the response, I think I'm getting closer for sure.

-Steve


"William DePalo [MVP VC++]" <willd.no.spam@mvps.org> wrote in message
news:O8$nk4$$DHA.1956@TK2MSFTNGP10.phx.gbl...
> "Steve" <steve@nowhere.com> wrote in message
> news:%23LYuLj9$DHA.392@TK2MSFTNGP12.phx.gbl...
> > Does anyone know of sample code that would show me how to accomplish
this:
> > embed a bitmap file into a project (and subsequently my DLL)
> > then write that embedded data to file at runtime?
>
> You may want to check an introductory text like Petzold's Programming
> Windows. But basically, you just create a line in your resource script
along
> the lines of
>
> name BITMAP MOVEABLE bitmapFileName
>
> and when the resource compiler binds the resources to the executable the
> bitmap will be part of the executable. If you use Visual Studio version 6
> you can do that from the Insert menu. VS.Net has the option on the project
> menu. At runtime you load the bitmap with LoadBitmap(). If you use a
> numberic (#define) name for the bitmap you use MAKEINTRESOURCE() to create
a
> "string" name to pass to LoadBitmap().
>
> Does that help?
>
> Regards,
> Will
>
>
>



Re: embedding bitmap by William

William
Tue Mar 02 14:41:06 CST 2004

"Steve" <steve@nowhere.com> wrote in message
news:uEvivXIAEHA.2056@TK2MSFTNGP11.phx.gbl...
> From what I can find on MSDN, LoadBitmap() is a GDI call

Alert the media! :-)

> I don't want to load a bitmap so much as I want to utilize a project
> resource and somehow write it to a physical file on disk.
> It may be that I can do that with LoadBitmap() somehow, I just don't see
it.

Geez, I swear your previous question spoke of bitmaps. :-)

> Here is another example, let's say that you had an avi file that you
wanted
> to embed in your DLL, then create the pyhsical file at runtime... is that
> possible?

Yes, of course. Still, the answer involves updating the resource script
either manually or via the IDE to specify the name of the file that contains
the data that you want to add to your application.

At runtime you call FindResource(), LoadResource() and LockResource().
Together, they will yield a pointer to the data and its length. If you want
to create a file from that data at runtime, you can use the standard C++ (or
C) functions or Win32's CreateFile(), WriteFile(), CloseHandle().

> Thanks for the response,

You are welcome.

Regards,
Will



Re: embedding bitmap by Steve

Steve
Tue Mar 02 16:19:36 CST 2004

So I've got a nice little function that will get ptr to resources, thank you
for your help.

However, this line:
HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE("IDB_Banner"),
RT_BITMAP);

always returns NULL. I have a bitmap that I have imported into the project
and assigned that ID. I have checked teh DLL's size to see that it indeed
is being included.

The error that I get from GetLastError() states that it can't find the
resource. I feel the problem may be in the first parameter of
FindResource(), NULL. I'm not sure what to pass it here, from MSDN it
sounds to me that NULL would cause it to do what I want, but it's not cuttin
it.

Any more tips in this area? How do I get teh HINSTANCE of my DLL so that I
can pass it in there?

Thanks!
Steve


"William DePalo [MVP VC++]" <willd.no.spam@mvps.org> wrote in message
news:ugCJqaJAEHA.916@tk2msftngp13.phx.gbl...
> "Steve" <steve@nowhere.com> wrote in message
> news:uEvivXIAEHA.2056@TK2MSFTNGP11.phx.gbl...
> > From what I can find on MSDN, LoadBitmap() is a GDI call
>
> Alert the media! :-)
>
> > I don't want to load a bitmap so much as I want to utilize a project
> > resource and somehow write it to a physical file on disk.
> > It may be that I can do that with LoadBitmap() somehow, I just don't see
> it.
>
> Geez, I swear your previous question spoke of bitmaps. :-)
>
> > Here is another example, let's say that you had an avi file that you
> wanted
> > to embed in your DLL, then create the pyhsical file at runtime... is
that
> > possible?
>
> Yes, of course. Still, the answer involves updating the resource script
> either manually or via the IDE to specify the name of the file that
contains
> the data that you want to add to your application.
>
> At runtime you call FindResource(), LoadResource() and LockResource().
> Together, they will yield a pointer to the data and its length. If you
want
> to create a file from that data at runtime, you can use the standard C++
(or
> C) functions or Win32's CreateFile(), WriteFile(), CloseHandle().
>
> > Thanks for the response,
>
> You are welcome.
>
> Regards,
> Will
>
>



Re: embedding bitmap by Steve

Steve
Tue Mar 02 17:27:07 CST 2004

Here is the contents of the rc file and the resources.h file
////////////////////////////////////////////////////////////////////////////
/
//
// Bitmap
//

IDB_BANNER BITMAP DISCARDABLE "banner.bmp"
#endif // English (U.S.) resources
////////////////////////////////////////////////////////////////////////////
/


#define IDB_BANNER 101





"William DePalo [MVP VC++]" <willd.no.spam@mvps.org> wrote in message
news:ugCJqaJAEHA.916@tk2msftngp13.phx.gbl...
> "Steve" <steve@nowhere.com> wrote in message
> news:uEvivXIAEHA.2056@TK2MSFTNGP11.phx.gbl...
> > From what I can find on MSDN, LoadBitmap() is a GDI call
>
> Alert the media! :-)
>
> > I don't want to load a bitmap so much as I want to utilize a project
> > resource and somehow write it to a physical file on disk.
> > It may be that I can do that with LoadBitmap() somehow, I just don't see
> it.
>
> Geez, I swear your previous question spoke of bitmaps. :-)
>
> > Here is another example, let's say that you had an avi file that you
> wanted
> > to embed in your DLL, then create the pyhsical file at runtime... is
that
> > possible?
>
> Yes, of course. Still, the answer involves updating the resource script
> either manually or via the IDE to specify the name of the file that
contains
> the data that you want to add to your application.
>
> At runtime you call FindResource(), LoadResource() and LockResource().
> Together, they will yield a pointer to the data and its length. If you
want
> to create a file from that data at runtime, you can use the standard C++
(or
> C) functions or Win32's CreateFile(), WriteFile(), CloseHandle().
>
> > Thanks for the response,
>
> You are welcome.
>
> Regards,
> Will
>
>



Re: embedding bitmap by William

William
Tue Mar 02 18:18:10 CST 2004

"Steve" <steve@nowhere.com> wrote in message
news:e%23sF%23RKAEHA.580@TK2MSFTNGP11.phx.gbl...
> So I've got a nice little function that will get ptr to resources, thank
you
> for your help.

You are welcome.

> However, this line:
> HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE("IDB_Banner"),
> RT_BITMAP);
>
> always returns NULL. I have a bitmap that I have imported into the
project
> and assigned that ID. I have checked teh DLL's size to see that it indeed
> is being included.

You need to pass the instance/module handle of the component that contains
the resource. When you pass NULL (0) you are asking to find a resource in
the main module (i.e. executable). If you are trying to finding the bitmap
in a DLL then pass the hinstance handle that you get in DllMain().

Regards,
Will