// CPSModulesStartDll.cpp*: définit les fonctions exportées pour l'application DLL.
//
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <Shlobj.h>
#include <string.h>
#include "SimConnect.h"
#include <wchar.h>
#include <WinBase.h>
static enum GROUP_ID {
GROUP_MENU
};
static enum EVENT_ID {
EVENT_MENU_START,
EVENT_SUBMENU_START,
EVENT_SUBMENU1_START
};
FILE *fp;
char ExeFileName[MAX_PATH + 1];
char FileName[MAX_PATH + 1];
char ch;
int c = 0;
wchar_t pg[MAX_PATH];
HANDLE hSimConnect = NULL;
static int quit = 0 ;
void CALLBACK MyDispatchProcMI(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
{
//HRESULT hr;
switch(pData->dwID)
{
case SIMCONNECT_RECV_ID_EVENT:
{
SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData;
switch(evt->uEventID)
{
case EVENT_SUBMENU_START:
{
STARTUPINFO si = { 0 };
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL ;
PROCESS_INFORMATION pi = { 0 };
strcpy(FileName, "XCPS1.dat"); // Contains: d:\Program Files (x86)\Concorde Performance System\CFM.exe
fp = fopen(FileName, "r");
while ((ch = fgetc(fp)) != EOF)
{
ExeFileName[c] =ch;
++c;
}
fclose(fp);
ExeFileName[c] = '\0';
[COLOR="DarkOrange"]DWORD Path = ::GetModuleFileNameA(nullptr,ExeFileName,sizeof(ExeFileName));
MultiByteToWideChar(CP_ACP, 0, Path + ExeFileName, -1, pg, MAX_PATH);[/COLOR]
::CreateProcess(NULL, pg , NULL, NULL, FALSE,
NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi) ;
break;
}
case EVENT_SUBMENU1_START:
{
STARTUPINFO si = { 0 };
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL ;
PROCESS_INFORMATION pi = { 0 };
strcpy(FileName, "XCPS2.dat"); //Contains: d:\Program Files (x86)\Concorde Performance System\CDC.exe
fp = fopen(FileName, "r");
while ((ch = fgetc(fp)) != EOF)
{
ExeFileName[c] =ch;
++c;
}
fclose(fp);
ExeFileName[c] = '\0';
[COLOR="DarkOrange"]DWORD Path = ::GetModuleFileNameA(nullptr,ExeFileName,sizeof(ExeFileName));
MultiByteToWideChar(CP_ACP, 0, Path + ExeFileName, -1, pg, MAX_PATH);[/COLOR]
::CreateProcess(NULL, pg , NULL, NULL, FALSE,
NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi) ;
break;
}
default:
break;
}
break;
}
case SIMCONNECT_RECV_ID_QUIT:
{
quit = 1;
break;
}
default:
printf("Received ID: %d", pData->dwID);
break;
}
}
int __stdcall DLLStart(void)
{
HRESULT hr;
// Place all initialization code for the client in this function
if (SUCCEEDED(SimConnect_Open(&hSimConnect, "StartModules", NULL, 0, 0, 0)))
{
// Create some private events
hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_MENU_START);
hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_SUBMENU_START);
hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_SUBMENU1_START);
hr = SimConnect_MenuAddItem(hSimConnect, "CPS", EVENT_MENU_START, 12345);
hr = SimConnect_MenuAddSubItem(hSimConnect, EVENT_MENU_START, "FUEL MANAGEMENT",EVENT_SUBMENU_START, 234567);
hr = SimConnect_MenuAddSubItem(hSimConnect, EVENT_MENU_START, "DESCENT CALCULATOR",EVENT_SUBMENU1_START, 345678);
// Sign up for the notifications
hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_MENU, EVENT_MENU_START);
hr = SimConnect_SetNotificationGroupPriority(hSimConnect, GROUP_MENU, SIMCONNECT_GROUP_PRIORITY_HIGHEST);
SimConnect_CallDispatch(hSimConnect, MyDispatchProcMI, NULL);
}
return 0;
}
//
// The DLLStop function must be present.
//
void __stdcall DLLStop(void)
{
// Close the client
if (hSimConnect != NULL)
HRESULT hr = SimConnect_Close(hSimConnect);
}