无法调用班级内的调度功能...... [英] Cant call to dispatch function inside the class...

查看:72
本文介绍了无法调用班级内的调度功能......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以为Microsoft Flight Simulator x编写一个程序。当我进入dll,或者进入课堂时,我无法调用调度函数

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

而没有参数...



我的尝试:



//在Heade文件中



" 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);



		}
	}

}

推荐答案

这绝对是显而易见的,因为你的函数声明是:



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

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



所以回调得到一些数据及其大小和一些上下文的feed。这是这种东西的常见实现。通常情况下,上下文是指向目标对象的句柄或指针,数据是一些正在发生的信息。



这样的处理程序从上下文对象中调用 而不是manuelly。如果没有被调用,则您的设置不正确或不完整。


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.


这篇关于无法调用班级内的调度功能......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆