I've been searching for quite a while now, but can't seem to find the answer. I am also no real c++ expert, so I may be trying to do something that doesn't make much sense.
My aim is to deploy a Java application within a single executable that can be pinned to the taskbar. I have come to the conclusion that this can be done through a c++ application that launches my jar file. No problem so far, I can write a simple launcher myself. in fact, I've even found tools such as jar2exe or launch4J that make the job easier.
Anyway... my problem is to make a c++ application pinnable to the Windows taskbar. I have already found a function called SetCurrentProcessExplicitAppUserModelID
that assigns the application an identifer that allows pinning to the taskbar. It has taken me quite a while to find out that this function only seems to be available through the Visual Studio Compiler. This has also worked, but once my Java application opens it creates a new window in the taskbar, so same old problem I guess.
I've found good behavior in the launch4J program. It creates an executable that runs my jar file within a single window - exactly what I want. I've also found that I can link custom object files in the configuration. So I thought of just adding an object file that calls the SetCurrentProcessExplicitAppUserModelID
function. As well as passing some additional flags for laptops (I am using openGL within the Java application) for graphics card selection. This is what I came up with:
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <shellapi.h>
#include <shobjidl.h>
// high performance gpu for nvidia and amd
extern "C"
{
__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}
int init() {
std::cout << "initializing..." << std::endl;
LPCWSTR app_id = L"EmpsWorldApp";
HRESULT hr = SetCurrentProcessExplicitAppUserModelID(app_id);
return 0;
}
const int i = init();
However... my example program cannot be compiled with MinGW's gcc - says the function SetCurrentProcessExplicitAppUserModelID
cannot be found. I couldn't find an answer to why not. The function definition exists in one of MinGW's header files: shobjidl.h
. Also - big surprise - compiling the file with Visual Studio's compiler cl
and trying to link the object file within launch4J also doesn't work.
I have also previously tried to create and launch a JVM through c++ with JNI. That didn't really work out though... the application kept crashing telling me DLLs could not be found. I also don't think this would be a very elegant way of solving my problem. I stopped searching there too.
I'm kind of running out of ideas now. Why can't I compile my application with gcc? Do I require special flags? My c++ knowledge is also pretty much non-existent... especially when it comes to exotic windows-only functions.
I'd greatly appreciate any other ideas or resources to solve my little problem.
Thanks in advance,
Thomy
User contributions licensed under CC BY-SA 3.0