|
-
Oct 9th, 2001, 03:14 PM
#1
Thread Starter
Black Cat
Write resource to file
I think this should work, but I'm getting an Access Violation at the first WriteFile. Anyone know why?
Thanks,
Code:
//file names
#define CPL "\\wgpocpl.cpl"
#define DLL "\\wgpoadmn.dll"
char * pchSystemDir = NULL; //the windows system directory
HRSRC hCpl = NULL; //handle to control panel resource
HRSRC hDll = NULL; //handle to DLL resource
HGLOBAL hCpl2 = NULL;
HGLOBAL hDll2 = NULL;
char * pchCpl = NULL; //location of resource in memory
char * pchDll = NULL; //location of resource in memory
char * pchCplName = NULL; //full file name of cpl
char * pchDllName = NULL; //full file name of dll
HANDLE hCplFile = INVALID_HANDLE_VALUE;
HANDLE hDllFile = INVALID_HANDLE_VALUE;
//load the resources into memory
hCpl = FindResource(NULL, IDR_CPL, "CUSTOM");
hDll = FindResource(NULL, IDR_DLL, "CUSTOM");
hCpl2 = LoadResource(NULL, hCpl);
hDll2 = LoadResource(NULL, hDll);
pchCpl = (char*)LockResource(hCpl2);
pchDll = (char*)LockResource(hDll2);
//create the files
hCplFile = CreateFile(pchCplName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL);
hDllFile = CreateFile(pchDllName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL);
HeapFree(GetProcessHeap(), 0, pchCplName);
HeapFree(GetProcessHeap(), 0, pchDllName);
//write to the files
WriteFile(hCplFile, pchCpl, SizeofResource(hInstance, hCpl), NULL, NULL);
WriteFile(hDllFile, pchDll, SizeofResource(hInstance, hDll), NULL, NULL);
//close the files
CloseHandle(hCplFile);
CloseHandle(hDllFile);
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Oct 9th, 2001, 03:32 PM
#2
Frenzied Member
Just a thought
[quote]
BOOL WriteFile(
HANDLE hFile, // handle to file to write to
LPCVOID lpBuffer, // pointer to data to write to file
DWORD nNumberOfBytesToWrite, // number of bytes to write
LPDWORD lpNumberOfBytesWritten, // pointer to number of bytes written
LPOVERLAPPED lpOverlapped // pointer to structure for overlapped I/O
);
Windows NT: If lpOverlapped is NULL, lpNumberOfBytesWritten cannot be NULL.
Are you using NT. If you are than your last parameters are both NULL.
-
Oct 9th, 2001, 03:57 PM
#3
Thread Starter
Black Cat
Thanks! I completely overlooked that - I declared an int and passed it a pointer to it instead of NULL and it works great.
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|