BMP from dll to file

can someone tell me how i can get a bmp resource from the dll to the drive. This is for a desktop changer with a set of wallpapers included in the dll and the ability to select one from the disk. so all i need is a way to get bmp from dll to disk ex.c:\wallpaper.bmp

1. Use FindResource or FindResourceEx to get a handle to that bitmap resource.
2. Use LoadResource to load it into memory as it is stored in the file.
3. Use LockResource to get a pointer to that memory block.
4. Write the memory block to file. You have two small things to keep in mind:
a.) Write 'B' and 'M' as the two first bytes of the file; these are the Windows Bitmap file signatures but aren't stored in the resource.
b.) The first 4 bytes of the memory block give you the size of the resource. These 4 bytes aren't to be written into the file.

a.) If you look into a .BMP file, the first two bytes are 'B' and 'M'. If you look into the bitmap resource, these two bytes are missing. So if you want to create a valid .BMP file, you have to write these two bytes yourself.

b.) If you look into the bitmap resource (to the memory pointed by the value you get from LockResource), the first 4 bytes are the size of the bitmap resource. You don't have to write these 4 bytes to the file, because .BMP files don't have this value. But this size value should be used for how many bytes do you have to write to the file.

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Which line gives you the error? And if you debug step-by-step, what's the result of each line? If anything fails, what's the GetLastError() value after the failure? Etc.
Btw, you should write WriteFile(hFile, bmpResource + sizeof(DWORD), Size, &written, NULL); instead.

And I think you can use LoadLibraryEx function with the LOAD_LIBRARY_AS_DATAFILE flag. It prevents the DLL from running it's startup code.

but i cant open the file,
---------------------------
Paint
---------------------------
A sharing violation occurred while accessing E:\windows\Shadower-1024x768.bmp.
---------------------------
OK
---------------------------
is what i get when i try to open it in paint.

Well, the purpose of using a debugger is not only showing you which line crashes. You can check values of variables, too. In your case "bmpResource" seems to be NULL (as I thought you will take care of error checking). Now if you try to copy anything from NULL, it will crash.

And just think a little about setting memcpy's last parameter to zero. Now you copy zero bytes, e.g., nothing. Now how would "size" get initialized?

Now, for the heaven's sake, please use the "Step" and "Watch" functions of your debugger and check all the returned values beginning from FindResource. If any of the resource functions return NULL, modify your code so that you call GetLastError () after it and check the returned value.

Introduction:
Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers). Error trapping with try..catch to help the code run even if something goes wrong.
Continuing from the seve…

Introduction:
The undo support, implementing a stack.
Continuing from the eigth article about sudoku.
We need a mechanism to keep track of the digits entered so as to implement an undo mechanism. This should be a ‘Last In First Out’ collec…