本文介绍了在MFC类中调用结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MFC基于对话框的应用程序中,我将使用函数指针调用不同条件的dll函数,所以我认为这些函数指针在包含结构&的包装函数中声明。最后返回包含函数指针地址的结构指针。怎么做?任何想法?

In MFC dialogue based application,I've to call dll function using function pointer for different condition, so I think these function pointers are declared in wrapper function which containing structure & at last returns structure pointer which containing address of function pointer.How to do that? any idea?

void *UniqueFunction(int flag)
{
	if(flag==0)
	{
		struct MyStruct
		{
		typedef int(*pFunctionPointer1)(CString,HANDLE *);
		typedef int(*pFunctionPointer2)(int,HANDLE);
		typedef int(*pFunctionPointer3)(int,int,char*,HANDLE);
		typedef int(*pFunctionPointer4)(int,int,int,HANDLE);
		typedef int(*pFunctionPointer5)(HANDLE);
		typedef CString(*pFunctionPointer6)(DWORD);
		}*FirstStruct;
		return FirstStruct;
	}



在上面的代码中,我试图在函数中声明结构,它编译错误但是如何在点击按钮的事件上调用它?这是对还是错?请建议!!


In above code I've tried to declare structure in function,it compiled error free but how to call that on event of button clicked?and is this right or wrong?Please suggest!!

推荐答案


struct MyStruct
{
    typedef int(*pFunctionPointer1Type)(CString,HANDLE *);
    pFunctionPointer1Type pFunctionPointer1;
//    typedef int(*pFunctionPointer2)(int,HANDLE);
//    typedef int(*pFunctionPointer3)(int,int,char*,HANDLE);
//    typedef int(*pFunctionPointer4)(int,int,int,HANDLE);
//    typedef int(*pFunctionPointer5)(HANDLE);
//    typedef CString(*pFunctionPointer6)(DWORD);
}*FirstStruct;
    FirstStruct = new MyStruct;
    FirstStruct->pFunctionPointer1 = FunctionOne;
// repeat for other pointers

// or if using dynamic DLL
HINSTANCE hDLL = ::LoadLibrary("mydllname");
FirstStruct->pFunctionPointer1 = (pFunctionPointer1Type)::GetProcAddress(hDLL, "FunctionOne");

return FirstStruct;



这篇关于在MFC类中调用结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:37
查看更多