小编dsp*_*es1的帖子

将字符串转换为 LPWSTR

我很难将字符串转换为LPWSTR这样我可以使用该PathStripToRoot()函数。

好吧,MSDN 文档说我需要LPTSTR变量(http://msdn.microsoft.com/en-us/library/windows/desktop/bb773757(v=vs.85).aspx),但 Visual Studio 2013 说我需要LPWSTR.

这是我的函数的代码片段:

fileStat fileCreate(const string& targetFile)
{
    fileStat filez;

    fstream file(targetFile.c_str());
    if (!file)
    {
        cout << "File does not exist" << endl;
    }

    std::ifstream in(targetFile, ios::binary | ios::ate);
    int a = in.tellg();
    cout << "File size(bytes): " << in.tellg() << endl << endl;
    file.close();


    wstring stemp = strChange(targetFile);
    LPCWSTR result = stemp.c_str();

    /* Tried the below code but that did not work
    LPWSTR ws …
Run Code Online (Sandbox Code Playgroud)

c++ string unicode winapi

5
推荐指数
1
解决办法
1万
查看次数

使用FSCTL_LOCK_VOLUME锁定驱动器

我在锁定C驱动器时遇到问题,因此以后可以提取一些文件信息。

#define wszDrive L"\\\\.\\PhysicalDrive0"
HANDLE targetVol = INVALID_HANDLE_VALUE;
DWORD stats;
targetVol = CreateFile(wszDrive,
        0,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        OPEN_EXISTING,
        /*FILE_FLAG_NO_BUFFERING | FILE_FLAG_RANDOM_ACCESS*/0,
        NULL);

    if (targetVol == INVALID_HANDLE_VALUE)    // cannot open the drive
    {
        cout << "error in ioControl with volume handler" << endl;
        system("pause");
    }

    if (DeviceIoControl(targetVol,
        FSCTL_LOCK_VOLUME,
        NULL, 0, NULL, 0,
        &stats,
        NULL) ==0)
    {
        cout << "Error with targetVol DeviceIo" << endl;
        ErrorExit(TEXT("GetProcessId"));
        system("pause");
    }
Run Code Online (Sandbox Code Playgroud)

下面的错误出口返回“ GetProcessID失败,错误1:函数不正确。”

void ErrorExit(LPTSTR lpszFunction)
{
    // Retrieve the system error message for …
Run Code Online (Sandbox Code Playgroud)

c++ windows winapi

1
推荐指数
1
解决办法
1581
查看次数

标签 统计

c++ ×2

winapi ×2

string ×1

unicode ×1

windows ×1