#include <wdm.h>
#include <usbdi.h>
#include <windef.h>
#include <stdio.h>
#include <stdlib.h>
#include <ntstrsafe.h>
#define NOBITMAP
#include <mmreg.h>
#undef NOBITMAP
.....
#define FRAME_DBG_FILENAME L"\\??\\C:\\xxx.bin"
NTSTATUS
USBCAMD_SaveFrameToFile(
IN PUCHAR FrameBuffer,
IN ULONG FrameSize,
IN ULONG FrameIndex
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
HANDLE hFile;
OBJECT_ATTRIBUTES objectAttributes;
UNICODE_STRING unicodeFilename;
IO_STATUS_BLOCK ioStatus;
// WCHAR frameFilename[] = FRAME_DBG_FILENAME;
WCHAR frameFilename[32];
LPCWSTR pszFormat = L"\\??\\C:\\xxx_%x.bin";
//寫入想要的檔名
RtlStringCbPrintfW(frameFilename, sizeof(frameFilename), pszFormat, FrameIndex);
RtlInitUnicodeString(&unicodeFilename, frameFilename);
// Create data file.
InitializeObjectAttributes (
&objectAttributes,
&unicodeFilename,
OBJ_CASE_INSENSITIVE|OBJ_KERNEL_HANDLE,
NULL,
NULL);
/* //覆蓋檔案
ntStatus = ZwCreateFile(&hFile,
GENERIC_WRITE,
&objectAttributes,
&ioStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OVERWRITE_IF,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0);
*/
//續寫檔案
ntStatus = ZwCreateFile( &hFile,
FILE_APPEND_DATA,
&objectAttributes,
&ioStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_WRITE,
FILE_OPEN_IF,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0 );
if (ntStatus == STATUS_SUCCESS)
{
if ((FrameBuffer) && (FrameSize))
{
ntStatus = ZwWriteFile(hFile,
NULL,
NULL,
NULL,
&ioStatus,
FrameBuffer,
FrameSize,
NULL,
NULL);
}
ZwClose(hFile);
}else
{
AlDebugPrint(("Create frame file Failed!\n"));
}
return ntStatus;
}
留言列表