How to connect from C++ app to Wolfram Engine using WSTP

Hello,

I’m trying to hookup an existing C++ application to the Wolfram Engine. I’ve been reading the C API docs[1], the Windows dev guide[2], and the example C code bundled with the Engine.

I’m stuck trying to launch the Wolfram Engine in the background, when the C++ app starts. The only way I’ve been able to create a link is using the following code:

WSEnvironmentParameter eParams = WSNewParameters(WSREVISION, WSAPIREVISION);
WSInitialize(eParams);
std::string linkInfo = "-linkname foo -linkprotocol SharedMemory -linkmode launch"; 
link = WSOpenString(ep, linkInfo.c_str(), &err);
if (link == nullptr) {
	return false;
}

However, this causes a Windows Prompt to pop up to select the MathKernel.exe, when the C++ app starts.

I would like the C++ application to run the MathKernel in the background, and to shut it down when the C++ application exits.

How can the C++ application launch the MathKernel app in the background, without having the prompt to select the app?

[1] WSTP C Language Functions—Wolfram Documentation

[2] WSTP Development in C—Wolfram Documentation

Maybe you could use windows functions to check running processes and see if wolfram engine is running, and manually start mathkernel as new process if it is not?