What does this error mean: "error C2664 cannot convery arguement 7 from 'TCHAR (*)[261]' to 'LPSTR'

114 Views Asked by At

I'm new to coding and I'm not too sure how I'd go about fixing this issue. The error is as follows:

error C2664: 'BOOL GetVolumeInformationA(LPCSTR,LPSTR,DWORD,LPDWORD,LPDWORD,LPDWORD,LPSTR,DWORD)': cannot convert argument 7 from 'TCHAR (*)[261]' to 'LPSTR'

Just want a clear cut answer on how I can fix this issue and an explanation on what I did wrong. Thank you so much!

The section I'm having issues in:

TCHAR volumeName[MAX_PATH + 1] = { 0 };
TCHAR fileSystemName[MAX_PATH + 1] = { 0 };
DWORD serialNumber = 0;
DWORD maxComponentLen = 0;
DWORD fileSystemFlags = 0;
if (GetVolumeInformation(_T("C:\\"), volumeName, ARRAYSIZE(volumeName), &serialNumber, &maxComponentLen, &fileSystemFlags, &fileSystemName, ARRAYSIZE(fileSystemName)));

And my source code is:

#include <Windows.h>
#include <iostream>
#include <stdlib.h>
#include <tchar.h>
#include <intrin.h>
#include <algorithm>
#include <TlHelp32.h>
#include <string>
#include <vector>

void setcolor(unsigned short color)
{
    HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hcon, color);
}

using namespace std;
vector<string> serial;

void loadserial()
{
    serial.push_back("HWIDS");
    serial.push_back("HWIDS");
    serial.push_back("HWIDS");
}


int main()
{
    loadserial();
    setcolor(10);
    std::cout << "Checking Whitelist...\n";
    Sleep(240);

    TCHAR volumeName[MAX_PATH + 1] = { 0 };
    TCHAR fileSystemName[MAX_PATH + 1] = { 0 };
    DWORD serialNumber = 0;
    DWORD maxComponentLen = 0;
    DWORD fileSystemFlags = 0;
    if (GetVolumeInformation(_T("C:\\"), volumeName, ARRAYSIZE(volumeName), &serialNumber, &maxComponentLen, &fileSystemFlags, &fileSystemName, ARRAYSIZE(fileSystemName)));

    while (true)
    {
        if (find(serial.begin(), serial.end(), to_string(serialNumber)) != serial.end())
        {
            std::cout << "Whitelisted\n";
            Sleep(2000);
            setcolor(15);
            system("cls");
            SetConsoleTitle("Loading Cheat...");
            setcolor(15);
            std::cout << "Loading...\n";
            Sleep(100);
            std::cout << "Loading (25%)\n";
            Sleep(200);
            std::cout << "Loading (50%)\n";
            Sleep(200);
            std::cout << "Loading (75%)\n";
            Sleep(200);
            std::cout << "Loading (100%)\n";
            Sleep(200);
            std::cout << "Done!\n";
            Sleep(1000);
            system("cls");
            SetConsoleTitle("Affinity");

            setcolor(5);

            setcolor(5);
            std::cout << "Welcome to Affinity\n";
            std::cout << "_________________\n";
            setcolor(12);
            std::cout << "\n";
            std::cout << "Pick Your Hack: \n";
            setcolor(10);
            std::cout << "Wallhacks: F5\n";
            setcolor(3);
            std::cout << "Bunnyhop: F6\n";
            setcolor(9);
            std::cout << "Radar: F7\n";
            setcolor(5);
            std::cout << "Exit: F8\n";

            std::cout << "\n";

            while (true)
            {
                if (GetAsyncKeyState(VK_F5))
                {
                    std::cout << "next episode\n";
                    Sleep(200);
                }

                if (GetAsyncKeyState(VK_F6))
                {
                    std::cout << "next episode\n";
                    Sleep(200);
                }

                if (GetAsyncKeyState(VK_F7))
                {
                    std::cout << "next episode\n";
                    Sleep(200);
                }

                if (GetAsyncKeyState(VK_F8))
                {
                    std::cout << "Closing\n";
                    Sleep(200);
                    system("cls");
                    std::cout << "Closing..\n";
                    Sleep(200);
                    system("cls");
                    std::cout << "Closing...\n";
                    Sleep(200);
                    system("cls");
                    std::cout << "Closing..\n";
                    Sleep(200);
                    system("cls");
                    std::cout << "Closing.\n";
                    Sleep(200);
                    system("cls");
                    std::cout << "Closing..\n";
                    Sleep(200);
                    system("cls");
                    std::cout << "Closing...\n";
                    Sleep(200);
                    system("cls");
                    exit(0);
                }
            }
        }
        else
        {
            setcolor(12);
            SetConsoleTitle("You're Not On The Whitelist ;(");
            std::cout << "You're not on the whitelist.\n";
            std::cout << "Your Serial/HWID is:";
            std::cout << serialNumber << std::endl;
            Sleep(15000);
            exit(0);
        }
    }
}
1

There are 1 best solutions below

0
On

In the lpFileSystemNameBuffer parameter of GetVolumeInformation(), you are passing in a pointer to a TCHAR[261] array (ie the type of the pointer is TCHAR(*)[261]), but the parameter is expecting a pointer to a TCHAR instead (ie the type of the pointer is TCHAR*). A TCHAR(*)[261] pointer is not implicitly convertible to a TCHAR* pointer, that is why the compiler is complaining.

Yes, GetVolumeInformation() wants you to provide it with a pointer to a memory buffer that can hold MAX_PATH (260) characters. But it wants a pointer to the 1st character of that buffer, not a pointer to the buffer itself. The two pointers may logically represent the same memory address, but they are technically different types in C++. The Win32 API is a C-based API, not a C++-based API.

When calling GetVolumeInformation(), simply change &fileSystemName to just fileSystemName, and let it decay into a pointer to the 1st character. Just like you are already doing with volumeName.

GetVolumeInformation(..., volumeName, ..., fileSystemName, ...);

Otherwise, be more explicit about taking the address of the 1st character. Change &fileSystemName to &fileSystemName[0] instead (same with volumeName):

GetVolumeInformation(..., &volumeName[0], ..., &fileSystemName[0], ...);