Skip to content
Igor Ziselman edited this page Mar 4, 2021 · 4 revisions

C++ Lab

// cppConsole.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <filesystem>
#include <stdlib.h>
#include <windows.h>
#include <Shlwapi.h>
#include <atlstr.h>

CString GetDirectory()
{
    WCHAR exeFilePath[MAX_PATH];
    GetModuleFileNameW(NULL, exeFilePath, MAX_PATH);
    CString exePath(exeFilePath);

    CString exeDirectory(exeFilePath);
    PathRemoveFileSpec(exeDirectory.GetBuffer(0));
    exeDirectory.ReleaseBuffer(-1);

    return exeDirectory;
}

int main()
{
    std::cout << "Hello World!\n";

    CString directoryPath = GetDirectory();
    std::wcout << "directoryPath: " << directoryPath.GetString() << std::endl;

    CString jsonFile = directoryPath + "\\..\\configuration.json";
    std::wcout << "jsonFile: " << jsonFile.GetString() << std::endl;

    //WCHAR exeFilePath[MAX_PATH];
    //GetModuleFileNameW(NULL, exeFilePath, MAX_PATH);
    ////CString exePath = CString(exeFilePath);
    //CString exePath(exeFilePath);
    //std::wcout << "exePath:" << exePath.GetString() << std::endl;

    //CString exeDirectory(exeFilePath);
    //PathRemoveFileSpec(exeDirectory.GetBuffer(0));
    //exeDirectory.ReleaseBuffer(-1);
    //std::wcout << "exeDirectory:" << exeDirectory << std::endl;

    //std::string directory = std::filesystem::path(exeFilePath).parent_path().u8string();
}
Hello World!
directoryPath: D:\My\MyProjects\@TechSugar\TechSugar\cpp-lab\CppLab\Debug

Clone this wiki locally