我有一个结构:
PROCESSENTRY32 pe32;我想把这个结构传递给一个函数。该函数将创建一个文件,并将结构中的数据写入该文件。函数的名称是takeinput()。我将结构传递给函数:
errflag = takeinput (&pe32);
在takeinput(PROCESSENTRY32 *pe31)中,我使用createfile()创建了一个D:\File.txt文件。现在,我必须将日期从写入file.txt。我正在使用:
WriteFile(
hFile, // open file handle
DataBuffer, // start of data to write
dwBytesToWrite, // number of bytes to write
&dwBytesWritten, // number of bytes that were written
NULL); // no overlapped structure这里,hFile,我知道。我知道的最后三个。但我对DataBuffer参数感到困惑。在那里传递什么?structure pe31中有很多变量。有人能在这方面帮我吗?
如果有其他方法可以将结构的数据写入file.txt,请给我解释一下。提前谢谢。
发布于 2011-01-10 17:04:26
这就是保存数据的缓冲区。您的电话将是:
takeinput (PROCESSENTRY32* ppe32)
{
WriteFile(
hFile, // open file handle
(void*)ppe2, // pointer to buffer to write
sizeof(PROCESSENTRY32), // number of bytes to write
&dwBytesWritten, // this will contain number of bytes actually written
NULL); // no overlapped structure
// some other stuff
}返回后,dwBytesWritten应等于sizeof(PROCESSENTRY32)。
发布于 2011-01-10 17:03:31
WriteFile函数签名为
BOOL WINAPI WriteFile(
__in HANDLE hFile,
__in LPCVOID lpBuffer,
__in DWORD nNumberOfBytesToWrite,
__out_opt LPDWORD lpNumberOfBytesWritten,
__inout_opt LPOVERLAPPED lpOverlapped
);您的DataBuffer在签名中为lpBuffer,lpBuffer是指向包含要写入文件或设备的数据的缓冲区的指针。您应该显式地将指向数据的指针(PROCESSENTRY32 pe31)转换为空( ( void )pe31 )的指针,并将其传递给WriteFile。
发布于 2011-01-10 17:04:19
你有没有读过 WriteFile function?,它可能会帮助你理解它所用的每个参数的用途和它们的含义。
BOOL WINAPI WriteFile(
__in HANDLE hFile,
__in LPCVOID lpBuffer,
__in DWORD nNumberOfBytesToWrite,
__out_opt LPDWORD lpNumberOfBytesWritten,
__inout_opt LPOVERLAPPED lpOverlapped
);您说您对DataBuffer参数感到困惑。MSDN解释说这是:
指向包含要写入文件或设备的数据的缓冲区的指针。
该缓冲区必须在写操作期间保持有效。在写入操作完成之前,调用方不得使用此缓冲区。
因此,从本质上讲,DataBuffer (lpBuffer)参数是您提供要写出到文本文件的数据的位置。
这里有一个关于如何打开和写入文件here的完整示例。您应该能够按照代码进行操作,以了解如何为您的特定情况编写代码。
https://stackoverflow.com/questions/4644970
复制相似问题