+-

我必须在c中编写CreateFile函数
我写了这个,但它没有用
我写了这个,但它没有用
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int main()
{
HANDLE hfile = CreateFile(
".\temp.txt", // "\\.\C:"
GENERIC_READ,
0,
NULL,
CREATE_NEW,
FILE_ATTRIBUTE_NORMAL,
NULL);
//if (hFile == INVALID_HANDLE_VALUE) cout << "Unable to create file \n";
return 0;
}
error C2664: ‘CreateFileW’ : cannot convert parameter 1 from ‘const char [10]’ to ‘LPCWSTR’
我该如何解决这个错误?
最佳答案
该错误消息告诉您它正在尝试调用CreateFileW,这是CreateFile的宽字符版本.你需要传递一个宽字符而不是普通字符;
hfile = CreateFile(
L".\\temp.txt", // Notice the L for a wide char literal
GENERIC_READ,
0,
NULL,
CREATE_NEW,
FILE_ATTRIBUTE_NORMAL,
NULL);
更多信息can be found here.
点击查看更多相关文章
转载注明原文:c – WinAPI CreateFile函数 - 乐贴网