Das ganze ist ziemlich einfach:
Code:
#include <windows.h>
void execute(char* fileName, char* param)
{
int hInstance = (int)ShellExecute(0, "open", fileName, param, 0, SW_SHOWNORMAL);
if (hInstance <= 32)
{
char* msg;
switch(hInstance)
{
case 0 :
msg = "The operating system is out of memory or resources.";
break;
case ERROR_FILE_NOT_FOUND :
msg = "The specified file was not found.";
break;
case ERROR_BAD_FORMAT :
msg = "The .exe file is invalid (non-Win32 .exe or error in .exe image).";
break;
case SE_ERR_ACCESSDENIED :
msg = "The operating system denied access to the specified file.";
break;
case SE_ERR_OOM :
msg = "There was not enough memory to complete the operation.";
break;
default :
msg = "Could not open file.";
}
MessageBox(0, msg, 0, MB_OK | MB_ICONERROR);
}
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
execute("Java\\bin\\javaw.exe", "-jar myJar.jar");
return 0;
}
Der Großteil ist nur Fehlerbehandlung. Es sollte aber eigentlich alles ziemlich selbsterklärend sein.
ShellExecute Doku findest du hier.
Ich hoffe du weißt wie man ein C-File kompiliert.
Die bat-Datei brauchst du übrigens nicht mehr, die wird ersetzt.