我有 ac# 文件如下:
//MyHandler.cs
public **class MyHandler**
{
**Function1(IntPtr handle)**
{....}
Function2(MyImageHandler myImgHandler,int height,int width)
{....}
};
public **class MyImageHandler**
{
FunctionX(string imagePath,int height,int width)
{.....}
};
我使用包含头文件的 c++/CLI 包装器 dll 来包装它,如下所示:
//IWrapper
#pragma once
#include<windows.h>
#include <string>
#ifdef MANAGEDWRAPPER_EXPORTS
#define DLLAPI __declspec(dllexport)
#else
#define DLLAPI __declspec(dllimport)
#pragma comment(lib,"D:\\MY\\MYY1\\Wrapper\\Debug\\MyFinalLibrary.lib")
#endif
class IWrapper
{
public:
virtual DLLAPI void Function1(HWND handle)=0;
**virtual __stdcall void Function2(MyImageHandler myImageHandler,int width,int height)=0;**
};
** MyImageHandler 是一个托管类。所以我通过 __stdcall 导出它。我这样做对吗?** 现在我有一个实现上述头文件的头文件,然后是一个 cpp 文件,如下所示:
#include "Wrapper.h"
#include "IWrapper.h"
#include<vcclr.h>
#include <windows.h>
Function1(HWND handle)
{....}
Function2(MyImageHandler myImgHandler,int height,int weight)
{
//Here I need to typecast the MyImageHandler type to a managed handle
}