我用ATL做了一个简单的activeX,想从activeX里面调用另外一个DLL的函数,如果DLL的函数是没有参数的话没有问题,但当传一个结构类型的数组作参数时就不行.大家帮忙.结构在CommonDef.h里定义
typedef struct _Menu
{
int menutype;
char code[13];
int price;
} menu;DLL的头文件里,这样定义#include "CommonDef.h"
#ifdef TESTDLL4_EXPORTS
#define TESTDLL4_API __declspec(dllexport)
#else
#define TESTDLL4_API __declspec(dllimport)
#endif
// This class is exported from the testdll4.dll
class TESTDLL4_API CTestdll4 {
public:
CTestdll4(void);
// TODO: add your methods here.
};
extern TESTDLL4_API int nTestdll4;
extern "C" TESTDLL4_API int fnTestdll5(int * , menu *);DLL的实装
TESTDLL4_API int fnTestdll5(int * nIndex ,menu* menus)
{
menus[0].price = 10;
menus[1].price = 15;
return S_OK;
}activeX的头文件里这么定义
#include "CommonDef.h"
typedef UINT (CALLBACK* LPFNDLLFUNC2)(int* ,menu*);在activeX里这么调用
STDMETHODIMP CFirst_ATL::test4(long *ret)
{
HINSTANCE hDLL; // Handle to DLL
LPFNDLLFUNC2 lpfnDllFunc2; // Function pointer
int lParam1;
int lParam2, uReturnVal;
menu mymenu[10];
hDLL = LoadLibrary("testdll4.dll");
if (hDLL != NULL)
{
lpfnDllFunc2 = (LPFNDLLFUNC2)GetProcAddress(hDLL,
"fnTestdll5");
if (!lpfnDllFunc2)
{
// handle the error
FreeLibrary(hDLL);
*ret = 1000;
}
else
{
// call the function
lParam1 = 100;
uReturnVal = lpfnDllFunc2(&lParam1,mymenu);
*ret = 2000 }
}
return S_OK;
}大家帮忙找找问题
typedef struct _Menu
{
int menutype;
char code[13];
int price;
} menu;DLL的头文件里,这样定义#include "CommonDef.h"
#ifdef TESTDLL4_EXPORTS
#define TESTDLL4_API __declspec(dllexport)
#else
#define TESTDLL4_API __declspec(dllimport)
#endif
// This class is exported from the testdll4.dll
class TESTDLL4_API CTestdll4 {
public:
CTestdll4(void);
// TODO: add your methods here.
};
extern TESTDLL4_API int nTestdll4;
extern "C" TESTDLL4_API int fnTestdll5(int * , menu *);DLL的实装
TESTDLL4_API int fnTestdll5(int * nIndex ,menu* menus)
{
menus[0].price = 10;
menus[1].price = 15;
return S_OK;
}activeX的头文件里这么定义
#include "CommonDef.h"
typedef UINT (CALLBACK* LPFNDLLFUNC2)(int* ,menu*);在activeX里这么调用
STDMETHODIMP CFirst_ATL::test4(long *ret)
{
HINSTANCE hDLL; // Handle to DLL
LPFNDLLFUNC2 lpfnDllFunc2; // Function pointer
int lParam1;
int lParam2, uReturnVal;
menu mymenu[10];
hDLL = LoadLibrary("testdll4.dll");
if (hDLL != NULL)
{
lpfnDllFunc2 = (LPFNDLLFUNC2)GetProcAddress(hDLL,
"fnTestdll5");
if (!lpfnDllFunc2)
{
// handle the error
FreeLibrary(hDLL);
*ret = 1000;
}
else
{
// call the function
lParam1 = 100;
uReturnVal = lpfnDllFunc2(&lParam1,mymenu);
*ret = 2000 }
}
return S_OK;
}大家帮忙找找问题
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货