Skip to content
Permalink
Browse files

[Win] Show error message if mainwin fails to load exe

Currently it will just die quietly which is no good for the user.
  • Loading branch information
NathanW2 committed Jan 29, 2018
1 parent cc9f7af commit 0be37ad465ec7b020c5cd0e9be52d7eb75234627
Showing with 39 additions and 6 deletions.
  1. +39 −6 src/app/mainwin.cpp
@@ -7,6 +7,18 @@
#include <list>
#include <memory>

void showError( std::string message, std::string title )
{
std::string newmessage = "Opps, looks like an error loading QGIS \n\n Details: \n\n" + message;
MessageBox(
NULL,
newmessage.c_str(),
title.c_str(),
MB_ICONERROR | MB_OK
);
std::cerr << message << std::endl;
}

std::string moduleExeBaseName( void )
{
DWORD l = MAX_PATH;
@@ -54,7 +66,8 @@ int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL
}
catch ( std::ifstream::failure e )
{
std::cerr << "could read environment variable list " << basename + ".vars" << " [" << e.what() << "]" << std::endl;
std::string message = "Could not read environment variable list " + basename + ".vars" + " [" + e.what() + "]";
showError( message, "Error loading QGIS" );
return EXIT_FAILURE;
}

@@ -71,7 +84,8 @@ int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL
}
catch ( std::ifstream::failure e )
{
std::cerr << "could not write environment file " << basename + ".env" << " [" << e.what() << "]" << std::endl;
std::string message = "Could not write environment file " + basename + ".env" + " [" + e.what() + "]";
showError( message, "Error loading QGIS" );
return EXIT_FAILURE;
}
}
@@ -93,14 +107,16 @@ int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL
{
if ( _putenv( var.c_str() ) < 0 )
{
std::cerr << "could not set environment variable:" << var << std::endl;
std::string message = "Could not set environment variable:" + var;
showError( message, "Error loading QGIS" );
return EXIT_FAILURE;
}
}
}
catch ( std::ifstream::failure e )
{
std::cerr << "could not read environment file " << basename + ".env" << " [" << e.what() << "]" << std::endl;
std::string message = "Could not read environment file " + basename + ".env" + " [" + e.what() + "]";
showError( message, "Error loading QGIS" );
return EXIT_FAILURE;
}
}
@@ -114,14 +130,31 @@ int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL

if ( !hGetProcIDDLL )
{
std::cerr << "Could not load the qgis_app.dll" << std::endl;
DWORD error = GetLastError();
LPTSTR errorText = NULL;

FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
error,
MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
( LPTSTR )&errorText,
0,
NULL );

std::string messsage = "Could not load qgis_app.dll \n Windows Error: " + std::string( errorText )
+ "\n Help: \n\n Check " + basename + ".env for correct environment paths";
showError( messsage, "Error loading QGIS" );

LocalFree( errorText );
errorText = NULL;
return EXIT_FAILURE;
}

int ( *realmain )( int, char *[] ) = ( int ( * )( int, char *[] ) ) GetProcAddress( hGetProcIDDLL, "main" );
if ( !realmain )
{
std::cerr << "could not locate main function in qgis_app.dll" << std::endl;
showError( "Could not locate main function in qgis_app.dll", "Error loading QGIS" );
return EXIT_FAILURE;
}

0 comments on commit 0be37ad

Please sign in to comment.
You can’t perform that action at this time.