我想C#
从C++CLR
. 我也为它创建了包装器。假设在C#
类库中:
namespace MyImage
{
public class DicomHandler
{
public void TestImage(DicomImage dicomImage,int height,int width)
{
}
}
public class DicomImage
{
}
}
然后在 中Wrapper
,我创建了 的对象,DicomHandler
我需要调用TestImage(DicomImage dicomImage,int height,int width)
.
包装类库包括,
在 IWrapper.h 中
#pragma once
#include<windows.h>
#include <string>
using namespace MyImage;
#ifdef MANAGEDWRAPPER_EXPORTS
#define DLLAPI __declspec(dllexport)
#else
#define DLLAPI __declspec(dllimport)
#pragma comment(lib,"F:\\8May\\firebreath-FireBreath-firebreath-1.7.0-0- gdf8659e\\firebreath\\Wrapper\\Debug\\Wrapper.lib")
#endif
class IWrapper
{
public:
static IWrapper *CreateInstance();
static void Destroy(IWrapper *instance);
virtual DLLAPI void Sethandle(HWND handle)=0;
virtual DLLAPI void TestDicomImage(DicomImage^ _dicomImage,int width,int height)=0;
};
In Wrapper.h,
#pragma once
#include <windows.h>
#include <vcclr.h>
#include "IWrapper.h"
#include "stdio.h"
#include "string.h"
using namespace System;
using namespace System::Reflection;
using namespace System::IO;
using namespace MyImage;
using namespace std;
using namespace System::Runtime::InteropServices;
class Wrapper:public IWrapper
{
private:
gcroot<DicomHandler^> _dicomHandler;
//gcroot<DicomImageHandler^> _dicomImageHandler;
public:
Wrapper(){}
virtual DLLAPI void SetHandle(HWND handle);
virtual DLLAPI void TestDicomImage(DicomImage^ _dicomImage,int winwidth,int winheight);
};
在 Wrapper.cpp 中,
#include "stdafx.h"
#include "Wrapper.h"
#include "IWrapper.h"
#include <windows.h>
#include<iostream>
#include <winuser.h>
#include <tchar.h>
#include<vcclr.h>
#include <msclr\marshal_cppstd.h>
#include <string>
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
using namespace System;
using namespace System::IO;
using namespace std;
using namespace DicomImage;
void Wrapper::SetHandle(HWND handle)
{
_dicomHandler=gcnew DicomHandler;
//_dicomImageHandler=gcnew DicomImageHandler;
_dicomHandler->SetHandle((System::IntPtr)handle);
}
IWrapper *IWrapper::CreateInstance()
{
IWrapper *instance =(IWrapper*)new Wrapper();
return (instance);
}
void IWrapper::Destroy(IWrapper *instance)
{
delete instance;
}
void Wrapper::TestDicomImage(DicomImage^ _dicomImage,int width,int height)
{
_dicomHandler->TestImage(_dicomImage,width,height);
}
然后它会引发三个错误,例如
1) 错误 C3395: 'Wrapper::TestDicomImage' : __declspec(dllexport) 不能应用于具有 __clrcall 调用约定的函数
2) 错误 C3395: 'IWrapper::TestDicomImage' : __declspec(dllexport) 不能应用于具有 __clrcall 调用约定的函数
3) 错误 C2259: 'Wrapper' : 无法实例化抽象类
如何解决这些错误?请为我提供解决方案。