如何使用GetPrivateProfilestring()从当前目录上升级目录

How to go up a directory from current directory with GetPrivateProfileString()

本文关键字:当前目录 何使用 GetPrivateProfilestring      更新时间:2023-10-16

我正在尝试使用 GetPrivateProfileString从INI文件中读取我的程序的身份详细信息。我想上directory/Folder/File.ini(,但不知道该怎么做

我尝试了GetFullPathName()

void ini {

std::string iniPath = "/Ice/Ice.ini";
    LPWSTR inipath = A2W_EX(iniPath.c_str(), iniPath.length());

    DWORD IniPath = std::strtoul(iniPath.c_str(), NULL, 16);

    std::string playerUsername;
    std::string playerPassword;
    TCHAR iniauthChar[32];

    playerUsername = GetPrivateProfileString(authheader, authuser, 0, iniauthChar, 256, inipath);
    playerPassword = GetPrivateProfileString(authheader, authpass, 0, iniauthChar, 256, inipath);

}

这是我的INI文件,位于上方的目录

上方
[AUTH]
Username=
Password=

您应该使用\而不是/用于Windows上的目录路径。

#include <windows.h>
#include <iostream>
int main()
{
    LPWSTR fn = L"Ice\Ice.ini";
    wchar_t buf[MAX_PATH];      
    GetFullPathNameW(fn, MAX_PATH, buf, NULL);
    std::wcout << buf << std::endl;
}

或ANSI字符串:

#include <windows.h>
#include <iostream>
int main()
{
    LPSTR fn = "Ice\Ice.ini";
    char buf[MAX_PATH];     
    GetFullPathNameA(fn, MAX_PATH, buf, NULL);
    std::cout << buf << std::endl;
}