[GELÖST] ShellExecute() Problem/Fehler
-
Hallo,
ich Programmiere zur Zeit mit QT Creator einen Favoriten-Speicher für ein Spiel.
Dort will ich nun die .exe zum Spiel mit ein paar Parametern starten,
ich habe es mit ShellExecute() versucht, doch vergebens....
Mit WinExec() klapps, aber nicht aus einem definiertem Ordner sondern nur wenn sich die Spiel-.exe und die .exe meines Programms sich in einem Ordner
befinden... Deswegen will ich ShellExecute() nutzen, doch es treten Probleme
beim Compilieren auf, wenn ich es so stehen habe:string gamepath = "I:\Programs\EnemyTerritory"; string gamepathwithexe = "I:\Programs\EnemyTerritory\et.exe"; string params = "+conntect " + ip + "; +password " + pass; ShellExecute(0, "open", gamepathwithexe.c_str(), params.c_str(), gamepath.c_str(), SW_SHOWNORMAL);Nach dem was ich im Inet gelesen habe müsste es funktionieren, doch es treten
Fehler beim Compilieren auf:.../mainwindow.cpp:80: error: cannot convert 'const char*' to 'const WCHAR*' for argument '2' to 'HINSTANCE__* ShellExecuteW(HWND__*, const WCHAR*, const WCHAR*, const WCHAR*, const WCHAR*, INT)'Daraus folgt ich muss const char* in const WCHAR* umwandeln....
So:string gamepath = "I:\Programs\EnemyTerritory"; string gamepathwithexe = "I:\Programs\EnemyTerritory\et.exe"; string params = "+conntect " + ip + "; +password " + pass; ShellExecute(0, (LPCTSTR)"open", (LPCTSTR)gamepathwithexe.c_str(), (LPCTSTR)params.c_str(), (LPCTSTR)gamepath.c_str(), SW_SHOWNORMAL);Doch nun startet keine .exe, einfach nichts...
Pfade und Parameter stimmen, keine Frage...Bitte helft mir
.MfG IgelHaut
-
If the function succeeds, it returns a value greater than 32. If the function fails, it returns an error value that indicates the cause of the failure. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. It is not a true HINSTANCE, however. It can be cast only to an int and compared to either 32 or the following error codes below.
Und below ist das:
0 The operating system is out of memory or resources. ERROR_FILE_NOT_FOUND The specified file was not found. ERROR_PATH_NOT_FOUND The specified path was not found. ERROR_BAD_FORMAT The .exe file is invalid (non-Win32 .exe or error in .exe image). SE_ERR_ACCESSDENIED The operating system denied access to the specified file. SE_ERR_ASSOCINCOMPLETE The file name association is incomplete or invalid. SE_ERR_DDEBUSY The DDE transaction could not be completed because other DDE transactions were being processed. SE_ERR_DDEFAIL The DDE transaction failed. SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out. SE_ERR_DLLNOTFOUND The specified DLL was not found. SE_ERR_FNF The specified file was not found. SE_ERR_NOASSOC There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable. SE_ERR_OOM There was not enough memory to complete the operation. SE_ERR_PNF The specified path was not found. SE_ERR_SHARE A sharing violation occurred.
-
Du kannst doch nicht einfach so wild in der Gegend rumcasten! Da geht mehr kaputt als es klappt. Du kastest einen char* zu w_chart* um, obwohl beide Typen unterschiedliche Größen haben... Dann wunderst du dich, dass es nicht klappt? Du solltest stattdessen einfach einen wstring nehmen, statt einen string.
-
Und was ist mit dem "open" (zweiter Parameter)?
Sogar bei der MSDN-Doku steht "open" und bei mir kommt ein Fehler...
-
Vermutlich irgendeine besondere Einstellung. Probiert L"open", das sollte den wide-string ausgeben.
-
Janjan schrieb:
Vermutlich irgendeine besondere Einstellung. Probiert L"open", das sollte den wide-string ausgeben.
Geht aber nur bei hardcoded Literalen

-
Kóyaánasqatsi schrieb:
Janjan schrieb:
Vermutlich irgendeine besondere Einstellung. Probiert L"open", das sollte den wide-string ausgeben.
Geht aber nur bei hardcoded Literalen

Für den Rest gibt es ja auch wstring.

-
Oder einfach ShellExecuteA verwenden welches char const* erwartet und keine wchar_t const* strings.
-
Dieser Thread wurde von Moderator/in evilissimo aus dem Forum C++ in das Forum WinAPI verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
vielen Dank, genau so etwas wie ShellExecuteA habe ich gesucht
![:] 🙂](https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso)