Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I could write a program for Microsoft Flight Simulator x. When i am putting into the dll, or put into the class I can't call to the dispatch function "
MyDispatchProcMI
" without parameter...

What I have tried:

// in Heade file

#include <iostream>
#include <windows.h>
#include<string>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>
#include "SimConnect.h"

using namespace std;
namespace myDllNamespace
{
	HANDLE  hSimConnect = NULL;
	HRESULT hr;
	int     quit = 0;
	HANDLE  hSimConnect = NULL;

	static enum GROUP_ID {
		GROUP_MENU
	};

	static enum EVENT_ID {
		EVENT_MENU_ONE,
		EVENT_MENU_TWO,
	};

	static int menuUseCount = 0;
	class myDll{
	public:
		static __declspec(dllexport)void InitSimConnect();
		static __declspec(dllexport)void DeInitSimConnect();
		static int CALLBACK *MyDispatchProcMI(SIMCONNECT_RECV* , DWORD , void *);
	};
}


/// in cpp file

<pre>
#include "dllHeader.h"

namespace myDllNamespace {


	 int CALLBACK* myDll::MyDispatchProcMI(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
	{
		switch (pData->dwID)
		{
			case SIMCONNECT_RECV_ID_EVENT:
			{
											 SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData;

											 switch (evt->uEventID)
											 {
												 case EVENT_MENU_ONE:
													 printf("\nMenu item one selected %d", evt->dwData);

													 ++menuUseCount;

													 // Selected four times, so replace item one with item two
													 if (menuUseCount == 4)
													 {
														 hr = SimConnect_MenuDeleteItem(hSimConnect, EVENT_MENU_ONE);
														 hr = SimConnect_RemoveClientEvent(hSimConnect, GROUP_MENU, EVENT_MENU_ONE);

														 hr = SimConnect_MenuAddItem(hSimConnect, "Menu Item Two", EVENT_MENU_TWO, 54321);
														 hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_MENU, EVENT_MENU_TWO);
													 }
													 break;

												 case EVENT_MENU_TWO:

													 ++menuUseCount;

													 printf("\nMenu item two selected %d", evt->dwData);

													 if (menuUseCount == 6)
														 quit = 1;
													 break;

												 default:
													 printf("\nReceived unknown event: %d", evt->uEventID);
													 break;
											 }
											 break;
			}

			case SIMCONNECT_RECV_ID_QUIT:
			{
											quit = 1;
											break;
			}

			default:
				printf("Received ID: %d", pData->dwID);
				break;
		}
		return 0;
	}

	void myDll::InitSimConnect()
	{

		if (SUCCEEDED(SimConnect_Open(&hSimConnect, "Menu Items", NULL, 0, 0, 0)))
		{
			printf("\nConnected to Flight Simulator!");

			// Create some private events
			hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_MENU_ONE);
			hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_MENU_TWO);

			// Add one menu item
			hr = SimConnect_MenuAddItem(hSimConnect, "Menu Item One", EVENT_MENU_ONE, 12345);


			// Sign up for the notifications
			hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_MENU, EVENT_MENU_ONE);

			hr = SimConnect_SetNotificationGroupPriority(hSimConnect, GROUP_MENU, SIMCONNECT_GROUP_PRIORITY_HIGHEST);

			while (0 == quit)
			{
				SimConnect_CallDispatch(hSimConnect, MyDispatchProcMI, NULL);
				Sleep(1);
			}

			// Clean up before exiting
			if (menuUseCount < 4)
				hr = SimConnect_MenuDeleteItem(hSimConnect, EVENT_MENU_ONE); else
				hr = SimConnect_MenuDeleteItem(hSimConnect, EVENT_MENU_TWO);

			hr = SimConnect_Close(hSimConnect);



		}
	}

}
Posted
Updated 19-Jul-17 20:24pm
v3
Comments
KarstenK 18-Jul-17 3:46am    
What is the question? Please debug for a detailed error and reformat your code!!!!
Richard MacCutchan 20-Jul-17 4:20am    
I think that MyDispatchProcMI needs to be a static method.
Richard MacCutchan 20-Jul-17 4:22am    
Your declaration and definition conflict with each other. You cannot declare something as a pointer and then redefine it as a class method.

1 solution

That is absolutly obvious, because the declaration of your function is:

C++
static int CALLBACK *MyDispatchProcMI(SIMCONNECT_RECV* , DWORD , void *);

so the callback gets feed with some data and its size and some context. It is a common implemenation for such stuff. Normally the context is the handle or pointer to the target object and the data is some information what is going on.

Such handler got called from the context object and not manuelly. If it not gets called your setup isnt correct or incomplete.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900