1
When I run this code in the place where it was supposed to appear the directory appears Ó²o formula.exe, someone could help me solve ?
#include <iostream>
#include <Windows.h>
#include <lmcons.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <string>
using namespace std;
string teste() {
char buffer[MAX_PATH];
GetModuleFileName( NULL, buffer, MAX_PATH );
string::size_type pos = string( buffer ).find_last_of( "\\/" );
return string( buffer ).substr( 0, pos);
}
int main(){
TCHAR teste[MAX_PATH];
cout << teste << endl;
string cmd = "reg add HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /t REG_SZ /v formula /d ";
cmd += teste;
cmd += "\\formula.exe";
cout << cmd.c_str() << endl;
system(cmd.c_str());
}
Where is the content of
TCHAR teste[MAX_PATH];
is initialized?– Victor Stafusa
You really wanted to
cmd += teste;
or should have beencmd += teste();
? Having two different things with the nameteste
is to ask for confusion.– Victor Stafusa
Can solve as follows
– Nycolas