error: no matching function for call to 'std::basic_string<wchar_t>::basic_string(char [260])'|
Apr 30, 2013 at 1:36am UTC
First:
I just started learning C++ like 2 hours ago to aid my java program. I started this because of this link:
http://mark.koli.ch/2009/12/uac-prompt-from-java-createprocess-error740-the-requested-operation-requires-elevation.html
Second:
I am a quick learner when it comes to programming, but I need examples.
Now here is my problem:
C:\Users\Timberwolf\Documents\C++ Projects\Tool Belt UAC Launcher\app.cpp|24|error: no matching function for call to 'std::basic_string<wchar_t>::basic_string(char [260])'|
and here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include <string>
#include <cstring>
#include <Windows.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <shellapi.h>
#include <process.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#define SUCCESS 0
#define FAILURE 1
#define MAXPATHLEN MAX_PATH
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int cmdShow)
{
char module_name[MAX_PATH];
GetModuleFileName(0, module_name, MAX_PATH);
std::wstring path(module_name);
path.erase(path.find_last_of('\\' ), std::wstring::npos);
path.append("\\uac.exe" );
HRESULT ret = SUCCESS;
SHELLEXECUTEINFO sinfo;
memset(&sinfo, 0, sizeof (SHELLEXECUTEINFO));
sinfo.cbSize = sizeof (SHELLEXECUTEINFO);
sinfo.fMask = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_NOCLOSEPROCESS;
sinfo.hwnd = NULL;
sinfo.lpFile = path;
sinfo.lpVerb = L"runas" ;
sinfo.nShow = SW_SHOWMAXIMIZED;
BOOL result = ShellExecuteEx(&sinfo);
if (result)
{
WaitForSingleObject(sinfo.hProcess, INFINITE);
CloseHandle(sinfo.hProcess);
ret = SUCCESS;
}
else
{
ret = FAILURE;
}
return ret;
}
Any comments, help, and suggestion are welcome and appreciated.
Last edited on Apr 30, 2013 at 11:16am UTC
Apr 30, 2013 at 12:40pm UTC
I got it working:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#include <string>
#include <cstring>
#include <Windows.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <shellapi.h>
#include <process.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#define SUCCESS 0
#define FAILURE 1
#define MAXPATHLEN MAX_PATH
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int cmdShow)
{
char module_name[MAX_PATH];
GetModuleFileName(0, module_name, MAX_PATH);
const size_t cSize = strlen(module_name)+1;
wchar_t * wc = new wchar_t [cSize];
mbstowcs (wc, module_name, cSize);
std::wstring p(wc);
p.erase(p.find_last_of('\\' ), std::wstring::npos);
p.append(L"\\uac.exe" );
LPSTR path = (LPSTR) p.c_str();
LPSTR r = "runas" ;
HRESULT ret = SUCCESS;
SHELLEXECUTEINFO sinfo;
memset(&sinfo, 0, sizeof (SHELLEXECUTEINFO));
sinfo.cbSize = sizeof (SHELLEXECUTEINFO);
sinfo.fMask = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_NOCLOSEPROCESS;
sinfo.hwnd = NULL;
sinfo.lpFile = path;
sinfo.lpVerb = r;
sinfo.nShow = SW_SHOWMAXIMIZED;
BOOL result = ShellExecuteEx(&sinfo);
if (result)
{
WaitForSingleObject(sinfo.hProcess, INFINITE);
CloseHandle(sinfo.hProcess);
ret = SUCCESS;
}
else
{
ret = FAILURE;
}
return ret;
}
Topic archived. No new replies allowed.