TribleTT schrieb:
char* app_path = "C:\\Miss.pdf\0"; //String auf auszuführende Datei
Tu' mal die unötige '\0' da weg...
// edit:
Und dann mach'n ma mal halbwegs schönes C++ d'raus:
/* Zeichensatz einstellen unter MS Visual Studio 2010: wurscht. */
#include <string>
#include <map>
#include <iostream>
#include <windows.h>
#ifdef UNICODE
std::wostream &tcout = std::wcout;
typedef std::wstring tstring;
#elif
std::ostream &tcout = std::cout;
typedef std::string tstring;
#endif
template< typename KEY, typename VALUE >
class create_map
{
private:
std::map< KEY, VALUE > map;
public:
create_map( KEY const &key, VALUE const &value) { map[ key ] = value; }
create_map< KEY, VALUE >& operator()( KEY const &key, VALUE const &value ) { map[ key ] = value; return *this; }
operator std::map< KEY, VALUE >() { return map; }
};
tstring get_shellex_error_msg( int const error_code )
{
static std::map< int, tstring > const error_map = create_map< int, tstring >
( 0, TEXT( "The operating system is out of memory or resources." ) )
( ERROR_FILE_NOT_FOUND, TEXT( "The specified file was not found." ) )
( ERROR_PATH_NOT_FOUND, TEXT( "The specified path was not found." ) )
( ERROR_BAD_FORMAT, TEXT( "The .exe file is invalid (non-Win32 .exe or error in .exe image)." ) )
( SE_ERR_ACCESSDENIED, TEXT( "The operating system denied access to the specified file." ) )
( SE_ERR_ASSOCINCOMPLETE, TEXT( "The file name association is incomplete or invalid." ) )
( SE_ERR_DDEBUSY, TEXT( "The DDE transaction could not be completed because other DDE transactions were being processed." ) )
( SE_ERR_DDEFAIL, TEXT( "The DDE transaction failed." ) )
( SE_ERR_DDETIMEOUT, TEXT( "The DDE transaction could not be completed because the request timed out." ) )
( SE_ERR_DLLNOTFOUND, TEXT( "The specified DLL was not found." ) )
( SE_ERR_FNF, TEXT( "The specified file was not found." ) )
( SE_ERR_NOASSOC, TEXT( "There is no application associated with the given file name extension." ) )
( SE_ERR_OOM, TEXT( "There was not enough memory to complete the operation." ) )
( SE_ERR_PNF, TEXT( "The specified path was not found." ) )
( SE_ERR_SHARE, TEXT( "A sharing violation occurred." ) );
auto it = error_map.find( error_code );
return ( it != error_map.end() ? it->second : TEXT( "An unknown error occured." ) );
}
int main()
{
tcout << TEXT( "=====Test-Programm=====\n\n" );
LPCTSTR file = TEXT( "C:\\Miss.pdf" );
tcout << file << '\n';
int result = reinterpret_cast< int >(
ShellExecute( nullptr, TEXT( "open" ), file, nullptr, nullptr, SW_NORMAL ) );
if( result > 32 ) tcout << TEXT( "Programm wurde gestartet!\n" );
else tcout << get_shellex_error_msg( result ) << '\n';
}
// edith: 'n TEXT überseh'n