using uninitialized memory warning and else in cpp [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 months ago.
Improve this question
there is warnings in c++ i can't solve it
i have Visual Studio 2019
first i got error with #include "pch.h"
and 3 warnings
-using uninitialized memory : in processesSnapshot
`
while (Process32Next(processesSnapshot, &processInfo))
`
-argument conversion from 'unsigned __int64' to 'unsigned long', possible loss of data
-argument conversion from 'unsigned __int64' to 'DWORD', possible loss of data
`
MODULEENTRY32 module = GetModule("ac_client.exe", pid);
HANDLE phandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
`
`
#include "pch.h"
#include <iostream>
#include <Windows.h>
#include <TlHelp32.h>
DWORD GetPID(const char* ProcessName) {
PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof(processInfo);
HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (processesSnapshot == INVALID_HANDLE_VALUE)
return 0;
Process32First(processesSnapshot, &processInfo);
if (!strcmp(processInfo.szExeFile, ProcessName))
{
CloseHandle(processesSnapshot);
}
while (Process32Next(processesSnapshot, &processInfo))
{
if (!strcmp(processInfo.szExeFile, ProcessName))
{
CloseHandle(processesSnapshot);
}
}
CloseHandle(processesSnapshot);
return processInfo.th32ProcessID;
}
MODULEENTRY32 GetModule(const char* moduleName, unsigned long ProcessID)
{
MODULEENTRY32 modEntry = { 0 };
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, ProcessID);
if (hSnapshot != INVALID_HANDLE_VALUE)
{
MODULEENTRY32 curr = { 0 };
curr.dwSize = sizeof(MODULEENTRY32);
if (Module32First(hSnapshot, &curr))
{
do
{
if (!strcmp(curr.szModule, moduleName))
{
modEntry = curr;
break;
}
} while (Module32Next(hSnapshot, &curr));
}
CloseHandle(hSnapshot);
}
return modEntry;
}
int main()
{
std::cout << "Hello World!\n";
unsigned long long pid = GetPID("ac_client.exe");
MODULEENTRY32 module = GetModule("ac_client.exe", pid);
HANDLE phandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
unsigned long long result;
int ammodesiredvalue = 999999;
ReadProcessMemory(phandle, (void*)((unsigned long long)module.modBaseAddr + 0x0010B1E0), &result, sizeof(result), 0);
ReadProcessMemory(phandle, (void*)((unsigned long long)result + 0x54), &result, sizeof(result), 0);
ReadProcessMemory(phandle, (void*)((unsigned long long)result + 0x14), &result, sizeof(result), 0);
//ReadProcessMemory(phandle, (void*)((unsigned long long)result + 0x14), &result, sizeof(result), 0);
WriteProcessMemory(phandle, (void*)((unsigned long long)result + 0x14), &ammodesiredvalue, sizeof(ammodesiredvalue), 0);
std::cout << "Your ammo value is " << result << std::endl;
system("pause");
}
`
i looking for fix this error and warnings

Your code has a number of problems. I'm going to look at one small section, and point out what look to me like obvious problems. Not sure if they're the source of the symptoms you're seeing, but ...
Process32First(processesSnapshot, &processInfo);
if (!strcmp(processInfo.szExeFile, ProcessName))
{
CloseHandle(processesSnapshot);
}
So here if we found the right process, we close the process snapshot, but then:
while (Process32Next(processesSnapshot, &processInfo))
{
...we try to continue using the process snapshot, even if it's already been closed. Then:
if (!strcmp(processInfo.szExeFile, ProcessName))
{
CloseHandle(processesSnapshot);
}
...we check whether we have the right process, and (again) close the snapshot if we found it. But we don't break out of the loop--so again, we try to continue using the snapshot, even if we've closed it. Then:
}
CloseHandle(processesSnapshot);
...when we exit the loop, we close the snapshot yet again. At this point, we've potentially closed our snapshot three times, and continued using it after it was closed in a couple of different places.
My personal inclination is that any time I see something that needs to be opened and later closed (or something along those lines) I think of using RAII/SBRM to deal with it. That means I'd create a class to manage the process snapshot. I'd create the snapshot in the class' constructor, and close it in the class' destructor, and add other member functions to obtain the contents of the current item, advance to the next item, and so on.
Given that this iterates things, it also makes sense (in my opinion) to have this class act as an actual iterator.
// warning: untested code.
class ProcessIterator {
HANDLE snapshot;
bool valid;
PROCESSENTRY32 processInfo;
public:
using iterator_category = std::input_iterator_tag;
using difference_type = std::ptrdiff_t; // not really, but it'll probably do for now.
using value_type = PROCESSENTRY32;
using pointer = PROCESSENTRY32 *;
using reference = PROCESSENTRY32 &;
ProcessIterator(DWORD ID) : snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, ID))
{
if (!snapshot)
throw std::runtime_error("Unable to open process snapshot");
valid = Process32First(snapshot, &processInfo);
}
ProcessIterator() : valid(false) {}
ProcessIterator operator++() {
valid = Process32Next(snapshot, &processInfo);
return *this;
}
PROCESSENTRY32 operator*() const { return processInfo; }
bool operator==(ProcessIterator other) {
// only invalid iterators are equal:
return (!valid) && (!other.valid);
}
~ProcessIterator() { CloseHandle(snapshot); }
};
Since this is a normal iterator, we can use it for normal iterator "stuff", such as finding an entry using std::find_if:
DWORD getPid(char const *filename) {
auto p = std::find_if(ProcessIterator(0), ProcessIterator(),
[&](PROCESSENTRY32 const &p) { return !std::strcmp(filename, p.szExeFile); });
return p->th32ProcessID;
}

Related

argument of type "WCHAR" is incompatible with parameter of type "const char"

So I was checking csgo scripting with C++ and everything was going smoothly but when I finished the Bhop code I found out that "string1" is "const char" and "string2" is wchar. I tried fixing, i searched redit, youtube literally everything but i couldn't fix it.
#include "memory.h"
#include <TlHelp32.h>
Memory :: Memory(const char* processName)
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
const auto snapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
while (Process32Next(snapShot, &entry))
{
if (!strcmp(processName, entry.szExeFile))
{
this->id = entry.th32ProcessID;
this->process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, this->id);
break;
}
}
if (snapShot)
CloseHandle(this->process);
}
Memory :: ~Memory()
{
if (this->process)
CloseHandle(this->process);
}
DWORD Memory :: GetProcessId()
{
return this->id;
}
HANDLE Memory :: GetProcessHandle()
{
return this->process;
}
uintptr_t Memory :: GetModuleAdress(const char* moduleName)
{
MODULEENTRY32 entry;
entry.dwSize = sizeof(MODULEENTRY32);
const auto snapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, this->id);
uintptr_t result = 0;
while (Module32Next(snapShot, &entry))
{
if (!strcmp(moduleName, entry.szModule))
{
result = reinterpret_cast<uintptr_t>(entry.modBaseAddr);
break;
}
}
if (snapShot)
CloseHandle(snapShot);
return result;
}
The error comes up on if (!strcmp(processName, entry.szExeFile)) where processName is "const char" and entry.szExeFile is "wchar". Please tell how to fix my problem
because i got no clue.
You are using TCHAR-based Win32 API macros, and you are compiling your project with UNICODE defined, so the macros are resolving to the wchar_t version of the APIs. But you are using char data in the rest of your code, so you need to use the ANSI (char) version of the APIs explicitly instead.
Also, there are other bugs in your code. Namely, ignoring the 1st entry in the process and modules lists. And your constructor is closing the wrong HANDLE.
Try this:
Memory :: Memory(const char* processName)
{
PROCESSENTRY32A entry;
entry.dwSize = sizeof(entry);
const auto snapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (Process32FirstA(snapShot, &entry))
{
do
{
if (strcmp(processName, entry.szExeFile) == 0)
{
this->id = entry.th32ProcessID;
this->process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, this->id);
break;
}
}
while (Process32NextA(snapShot, &entry));
}
if (snapShot)
CloseHandle(snapShot);
}
uintptr_t Memory :: GetModuleAdress(const char* moduleName)
{
MODULEENTRY32A entry;
entry.dwSize = sizeof(entry);
const auto snapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, this->id);
uintptr_t result = 0;
if (Module32FirstA(snapShot, &entry))
{
do
{
if (strcmp(moduleName, entry.szModule) == 0)
{
result = reinterpret_cast<uintptr_t>(entry.modBaseAddr);
break;
}
}
while (Module32NextA(snapShot, &entry));
}
if (snapShot)
CloseHandle(snapShot);
return result;
}

WriteFile with an overlapped occasionally gives me ERROR_INVALID_HANDLE. Am I doing memset correct?

I am using WriteFile to write to a file and I am getting an error of ERROR_INVALID_HANDLE sometimes. I read that this could be because the value of HANDLE in Overlapped is invalid.
But I am just having a hard time figuring this out. I wonder if something is going out of scope. Would appreciate it if someone can take a look. I can always add more code here
const LPOVERLAPPED lpOverlapped = GetOverlapped(true, hFile, ulBufSize, &ullFileOffset,volumeName);
if (lpOverlapped == nullptr)
{
CloseHandle(hFile);
return false;
}
if (!WriteFile(hFile,(const PVOID)(((UINT64) s_pMemoryBuffer[volumeName]) + iBufferOffset),ulBufSize,&dwBytesWritten,lpOverlapped))
{
DWORD errCode = GetLastError(); //Error here
//Why do I get an error code 6 here every now and then
}
Now this is the method that returns the overlapped structure
LPOVERLAPPED foo::GetOverlapped(bool useOverlappedIo, HANDLE hFile, UINT32 ulBufSize, UINT64* ullFileOffset,const std::string& volumeName)
{
if (useOverlappedIo)
{
while (true)
{
int index = 0;
while (index < cMaxOverlappedIOS)
{
if (!OverlappedInUse[volumeName][index])
{
OverlappedInUse[volumeName][index] = true;
LPOVERLAPPED overlapped = &(OverlappedArray[volumeName][index]);
if (overlapped->hEvent == nullptr) // Need Event
{
overlapped->hEvent = CreateEvent(
nullptr,
TRUE,
TRUE,
nullptr);
if (overlapped->hEvent == nullptr)
{
printf("Error creating event (error code: %u)\n", GetLastError());
return nullptr;
}
}
overlapped->Offset = (UINT32)(*ullFileOffset & 0xFFFFFFFF); // Low order 32 bits
overlapped->OffsetHigh = (UINT32)(*ullFileOffset >> 32); // High order 32 bits
*ullFileOffset += ulBufSize; // Update pointer to next record
return overlapped;
}
// Else Keep looking
index++;
}
// None available, wait for at least one to free up
if (WaitForPendingIOs(hFile, FALSE,volumeName) != ERROR_SUCCESS)
{
return nullptr;
}
} // Now start loop over again
}
else
{
return nullptr;
}
}
This is how I am initializing the array before this code gets called
for(auto vol : readVolumes)
{
OVERLAPPED* oarray = new OVERLAPPED[cMaxOverlappedIOS];
memset(oarray, 0, sizeof(oarray));
OverlappedArray[vol] = oarray;
bool* boolinuse = new bool[cMaxOverlappedIOS]{false};
OverlappedInUse[vol] = boolinuse;
s_pMemoryBuffer[vol] = nullptr;
s_uDataBufferSize[vol] = 0;
}
Any suggestions on why I would get that error ?

Editing memory with a custom function in Lua C API

I'm trying to edit memory with my custom function in the luaC api but for example when i do like 3 lua_tonumber(LS, -1) it just gets mixed up? Please try to review my code and tell me how to fix this..
lua_State *L;
using namespace std;
DWORD MyGetProcessId(LPCTSTR ProcessName)
{
PROCESSENTRY32 pt;
HANDLE hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
pt.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hsnap, &pt)) {
do {
if (!lstrcmpi(pt.szExeFile, ProcessName)) {
CloseHandle(hsnap);
return pt.th32ProcessID;
}
} while (Process32Next(hsnap, &pt));
}
CloseHandle(hsnap);
return 0;
}
int CustomGetProcessByName(lua_State* Ls) {
DWORD dieman = MyGetProcessId(lua_tostring(Ls, -1));
lua_pushvalue(Ls, dieman);
return 1;
}
int CustomWriteMemInt(lua_State* Ls) {
HANDLE ProcHand = OpenProcess(PROCESS_ALL_ACCESS, FALSE, lua_tonumber(Ls, -1));
int Value = lua_tonumber(Ls, -3);
WriteProcessMemory(ProcHand, (LPVOID)lua_topointer(Ls, -2), &Value, sizeof(Value), 0);
return 1;
}
void Load() {
L = luaL_newstate();
lua_register(L, "GetProcByName", CustomGetProcessByName);
lua_register(L, "WriteMemInt", CustomWriteMemInt);
}
int main() {
Load();
luaL_dostring(L, "a = GetProcByName('ac_client.exe')");
luaL_dostring(L, "WriteMemInt(a, 0x0293AA60, 9999)");
system("Pause");
}
I know the writing memory function works because I did it without this..
lua_topointer returns a pointer to a lua object. You just want to use lua_tonumber instead.
Note that a number is normally a double so will not be able to hold 64-bit addresses, in your example it should work though as the address appears to be 32-bit.

Same c++ code sometimes works and sometimes doesnt

my c++ code works for a couple of times straight and after few executions it suddenly stops working and throws exceptions (without any changes!), and I cant figure out why.
This is the problematic part of code:
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
TCHAR *path;
SHGetKnownFolderPath(FOLDERID_Startup, KF_FLAG_CREATE, NULL, &path);
lstrcat(path, L"\\calc.exe");
if (CreateProcess(NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
{
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
After a few executions, 2 exceptions are thrown on the CreateProcess() line, the first one:
Unhandled exception at 0x779D8829 (ntdll.dll) in PS_Down.exe: 0xC0000374: A heap has been corrupted (parameters: 0x77A15890).
The second:
Exception thrown at 0x77946111 (ntdll.dll) in PS_Down.exe: 0xC0000005: Access violation reading location 0x00000069.
It happened to me with a few other projects (that don't include the CreateProcess() func) and iv'e noticed that it always happens when TCHAR and SHGetKnownFolderPath() are involved.
Any help with understanding how to fix the issue will be much appreciated, thanks in advance!
P.S - I'm new to coding in cpp, so please try to explain accordingly
lstrcat(path, L"\\calc.exe"); will cause a buffer overrun. path is a pointer to array that can contain only folder path, nothing more. You will need to allocate a wide string, append folder path and then file path. Also you will need to check result of SHGetKnownFolderPath to determine whether path contains a valid pointer and free it later by calling CoTaskMemFree.
path is allocated with a fixed length by SHGetKnownFolderPath so you can't concatenate your executable to it directly. You'd need to use CoTaskMemRealloc to expand the space first. You also need to free the memory after you've used it. Similarly, you need to close the handles created by CreateProcess.
You could therefore make support classes to handle the resources automatically:
#include "pch.h"
#include <iostream>
#include <windows.h>
#include <Shlobj.h>
#include <wchar.h>
// A wide string exception class. perhaps something like this already exist in VS?
class werror {
std::wstring text;
public:
werror(const wchar_t* Text) : text(Text) {}
const wchar_t* what() const { return text.c_str(); }
};
class ConCatToKnownFolderPath {
PWSTR m_path;
public:
ConCatToKnownFolderPath(REFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, const WCHAR* AddToPath = nullptr) :
m_path(nullptr)
{
if (SHGetKnownFolderPath(rfid, dwFlags, hToken, &m_path) != S_OK)
throw werror(L"SHGetKnownFolderPath failed");
if (AddToPath) {
size_t newlen = wcslen(m_path) + wcslen(AddToPath) + sizeof(WCHAR); // place for \0
size_t newbufsize = newlen * sizeof(WCHAR);
auto newPtr = CoTaskMemRealloc(m_path, newbufsize);
if (!newPtr) {
CoTaskMemFree(m_path);
throw werror(L"CoTaskMemRealloc failed");
}
m_path = reinterpret_cast<PWSTR>(newPtr);
wcscat_s(m_path, newlen, AddToPath);
}
}
// move works fine
ConCatToKnownFolderPath(ConCatToKnownFolderPath&& other) noexcept :
m_path(other.m_path)
{
other.m_path = nullptr;
}
ConCatToKnownFolderPath& operator=(ConCatToKnownFolderPath&& other) noexcept {
if (m_path) CoTaskMemFree(m_path);
m_path = other.m_path;
other.m_path = nullptr;
return *this;
}
// copy not supported (but could easily be added
ConCatToKnownFolderPath(const ConCatToKnownFolderPath&) = delete;
ConCatToKnownFolderPath& operator=(const ConCatToKnownFolderPath&) = delete;
// automatic free when it goes out of scope
~ConCatToKnownFolderPath() {
if (m_path) CoTaskMemFree(m_path);
}
PWSTR data() const { return m_path; }
operator LPCWSTR () const { return m_path; }
};
struct WProcessWithInfo : PROCESS_INFORMATION {
WProcessWithInfo(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPCWSTR lpCurrentDirectory) {
STARTUPINFOW si;
ZeroMemory(&si, sizeof(STARTUPINFOW));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL;
if (!CreateProcessW(lpApplicationName, lpCommandLine, NULL, NULL, FALSE, 0, NULL, lpCurrentDirectory, &si, *this))
throw werror(L"CreateProcessWCreateProcessW failed");
CloseHandle(hThread);
}
WProcessWithInfo(const WProcessWithInfo&) = delete;
WProcessWithInfo(WProcessWithInfo&&) = delete;
WProcessWithInfo& operator=(const WProcessWithInfo&) = delete;
WProcessWithInfo& operator=(WProcessWithInfo&&) = delete;
~WProcessWithInfo() {
CloseHandle(hProcess);
}
DWORD Wait(DWORD dwMilliseconds=INFINITE) {
return WaitForSingleObject(*this, dwMilliseconds);
}
operator HANDLE () { return hProcess; }
operator LPPROCESS_INFORMATION () { return this; }
};
int main() {
try {
ConCatToKnownFolderPath path(FOLDERID_System, KF_FLAG_CREATE, NULL, L"\\calc.exe");
std::wcout << L"Starting " << path.data() << L"\n";
WProcessWithInfo proc(path, NULL, NULL);
std::wcout << L"Process started\n";
proc.Wait();
std::wcout << L"Process done\n";
}
catch (const werror& ex) {
std::wcerr << L"Exception: " << ex.what() << L"\n";
}
return 0;
}

Having issues getting the module base address C++

I am trying to make a program to store the value 500 into the calculator's memory address for the MR (Memory Restore) button on the calculator application.
I know that the address for this integer is
"calc.exe"+00073320 + 0 + C
If I use a program like cheat engine, I can get the current address for the instance of the calculator.exe i'm running, and write to it just fine that way. However, since this is not a static address, I need a way to get the module base address.
I tried using this GetModuleBase function (see code below) to get the Base Address of the calc.exe, but my issue is that I cannot get the base address. The function always returns 0 instead of the correct address.
I debugged it and found that in the GetModuleBase function, it is not even cycling once through the while loop because bModule is returning 0 from the Module32First function.
#include <tchar.h>
#include <windows.h>
#include <TlHelp32.h>
#include <iostream>
#include <Psapi.h>
#include <wchar.h>
#pragma comment( lib, "psapi" )
using namespace std;
DWORD GetModuleBase(LPSTR lpModuleName, DWORD dwProcessId)
{
MODULEENTRY32 lpModuleEntry = {0};
HANDLE hSnapShot = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, dwProcessId );
if(!hSnapShot)
return NULL;
lpModuleEntry.dwSize = sizeof(lpModuleEntry);
BOOL bModule = Module32First( hSnapShot, &lpModuleEntry );
while(bModule)
{
if(!strcmp( lpModuleEntry.szModule, lpModuleName ) )
{
CloseHandle( hSnapShot );
return (DWORD)lpModuleEntry.modBaseAddr;
}
bModule = Module32Next( hSnapShot, &lpModuleEntry );
}
CloseHandle( hSnapShot );
return NULL;
}
int main() {
HWND hWnd = FindWindow(0, "Calculator");
DWORD BaseAddr;
if(hWnd == 0){
MessageBox(0, "Error cannot find window.", "Error", MB_OK|MB_ICONERROR);
} else {
DWORD proccess_ID;
GetWindowThreadProcessId(hWnd, &proccess_ID);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proccess_ID);
if(!hProcess){
MessageBox(0, "Could not open the process!", "Error!", MB_OK|MB_ICONERROR);
} else {
int newdata = 500;
BaseAddr = GetModuleBase("calc.exe",proccess_ID);
//GetModuleBase is always returning 0, so I am not getting the correct base address
DWORD newdatasize = sizeof(newdata);
if(WriteProcessMemory(hProcess, (LPVOID)0x002413FC, &newdata, newdatasize, NULL)){
cout << "Memory successfully written." << endl;
} else {
cout << "Memory failed to write." << endl;
}
CloseHandle(hProcess);
}
}
return 0;
}
Summary: I cannot get the correct base address using my GetModuleBase function, and I need to figure out what I am doing wrong so that I can get the correct base address for the "calc.exe" process.
You should read the modules like this:
#include <windows.h>
#include <TlHelp32.h>
#include <iostream>
//You don't have to use this function if you don't want to..
int strcompare(const char* One, const char* Two, bool CaseSensitive)
{
#if defined _WIN32 || defined _WIN64
return CaseSensitive ? strcmp(One, Two) : _stricmp(One, Two);
#else
return CaseSensitive ? strcmp(One, Two) : strcasecmp(One, Two);
#endif
}
//You read module information like this..
MODULEENTRY32 GetModuleInfo(std::uint32_t ProcessID, const char* ModuleName)
{
void* hSnap = nullptr;
MODULEENTRY32 Mod32 = {0};
if ((hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ProcessID)) == INVALID_HANDLE_VALUE)
return Mod32;
Mod32.dwSize = sizeof(MODULEENTRY32);
while (Module32Next(hSnap, &Mod32))
{
if (!strcompare(ModuleName, Mod32.szModule, false))
{
CloseHandle(hSnap);
return Mod32;
}
}
CloseHandle(hSnap);
return {0};
}
int main()
{
//Change the process ID below..
BYTE* BaseAddr = GetModuleInfo(5172, "calc.exe").modBaseAddr;
std::cout<<"BASE ADDRESS: "<<(void*)BaseAddr<<"\n";
return 0;
}
EDIT: After further investigation, I found that Visual Studio was compiling for an x32 platform but calc.exe is an x64 process..
To get Visual Studio to compile for x64 you need to do the following:
Then click and select "NEW" from the following drop-down menu:
Next in the following drop down, select x64:
Save the settings and rebuild the project and it should work..