troubleshooting Question

Export a resource

Avatar of zeurx
zeurxFlag for United States of America asked on
System Programming
18 Comments1 Solution314 ViewsLast Modified:
i have been trying to export a resource to a file for the past few weeks. When i try to run the exporting code in my dll it can not get the resource and returns a NULL error.

resource = bmp
bmp for wallpaper

<code>
    // Set File //
     
     TCHAR WinDir[INFO_BUFFER_SIZE];
     GetWindowsDirectory(WinDir,sizeof(WinDir));
     CString Wallpaper; Wallpaper.Format("%s",WinDir);
     CString sHeight; sHeight.Format("%i",height); CString sWidth; sWidth.Format("%i",width);
     Wallpaper += "\\Shadower-"+sWidth+"x"+sHeight+".bmp";
     AfxMessageBox(Wallpaper);
     // Get Resource //
     HMODULE hModule = LoadLibrary("Shadower.dll");
     CString size; size.Format("%i",width);
     LPCTSTR lpFile; lpFile = "SHADOWBG_"; lpFile =+ (char *) (LPCTSTR) size;
     AfxMessageBox(lpFile,MB_OK,NULL);
     HRSRC hRes = FindResource(hModule,lpFile,RT_BITMAP);
     HGLOBAL hResLoad = LoadResource(hModule,hRes);
     LPVOID bmpResource = LockResource(hResLoad);
     // Save to Bmp //
     DWORD Size = 0;
     memcpy (&Size, bmpResource, sizeof (DWORD));
     DWORD written = 0;
     LPSTR Wall = (char *) (LPCTSTR) Wallpaper;
     HANDLE hFile = CreateFile(Wall,
                                        GENERIC_WRITE,
                                        FILE_SHARE_READ,
                                        NULL,
                                        CREATE_ALWAYS,
                                        FILE_ATTRIBUTE_READONLY,
                                        NULL);
     WriteFile(hFile, "BM", 2, &written, NULL);
     WriteFile(hFile, bmpResource, Size, &written, NULL);
     UnlockResource(hResLoad);
     FreeLibrary(hModule);
     // Set Wallpaper //
     Reg.SetRootKey(HKEY_CURRENT_USER);
     Reg.SetKey("Control Panel\\Desktop",0);
     Reg.WriteString("Wallpaper",Wallpaper);
     Reg.WriteString("WallpaperStyle","2");
     SystemParametersInfo(SPI_SETDESKWALLPAPER,0,NULL,SPIF_SENDCHANGE|SPIF_UPDATEINIFILE);
when i run this code i get an error...
this is what i use to get to this function...
#include "..\dll\Wallpaper.h"
          CWallpaper Wallpaper;
          Wallpaper.ExtractBMP(768,1024);
</code>

Could someone look through this code and tell me what might be going wrong.
the resource name im trying to get is "SHADOWBG_1024" and i would like to make the numbers in that change with the screen size, i have the code for that thow.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 18 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 18 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros