[英]Setting up a wrapper to use C# .dll in C++
I have a .Dll written in C#. 我有一个用C#编写的.Dll。 I need to use this .Dll in a C++ application.
我需要在C ++应用程序中使用此.Dll。 After doing some research I am attempting to write a wrapper.
经过研究后,我尝试编写一个包装器。 I am still setting it up But I cannot get my project to compile.
我仍在设置它,但我无法编译我的项目。 I have set my project up in Visual studio 2015, As a Visual C++, CLR, Class library project.
我已经在Visual Studio 2015中设置了我的项目,作为Visual C ++,CLR,类库项目。
So far my code looks as follows: C# Class: 到目前为止,我的代码如下:C#类:
using System.Windows.Threading;
using System.Runtime.InteropServices;
namespace RF182CInterface
{
public class RFIDInterface
{
public RFIDInterface()
{
.
.
.
.H file .H文件
// RFIDWrapper.h
#pragma once
using namespace System;
namespace RFIDWrapper {
class RFIDWrapperIFacePrivate;
class __declspec(dllexport) RFIDWrapperIFace
{
private:
RFIDWrapperIFacePrivate* _private;
public:
RFIDWrapperIFace();
~RFIDWrapperIFace();
};
}
.cpp file: .cpp文件:
// This is the main DLL file.
#using "RF182CInterface.dll";
#include "stdafx.h"
#include <msclr\auto_gcroot.h>
#include "RFIDWrapper.h"
using namespace System::Runtime::InteropServices; // Marshal
class RFIDWrapperIFacePrivate
{
public:
msclr::auto_gcroot<RF182CInterface::RFIDInterface^> rf182CInterface;
};
When I attempt to compile I get the following errors: 当我尝试编译时,出现以下错误:
Warning 1 warning C4627: '#using "RF182CInterface.dll"': skipped when looking for precompiled header use 警告1警告C4627:'#using“ RF182CInterface.dll”':查找预编译头使用时已跳过
Error 2 error C2653: 'RF182CInterface' : is not a class or namespace name 错误2错误C2653:“ RF182CInterface”:不是类或名称空间名称
Error 3 error C2065: 'RFIDInterface' : undeclared identifier 错误3错误C2065:“ RFIDInterface”:未声明的标识符
Error 4 error C2059: syntax error : '>' Error 5 error C2976: 'msclr::auto_gcroot' : too few template arguments 错误4错误C2059:语法错误:'>'错误5错误C2976:'msclr :: auto_gcroot':模板参数太少
I believe they all stem from the warning where the .dll is skipped. 我相信它们全都源于.dll被跳过的警告。 The .dll is in the same folder as the .cpp and .h files.
.dll与.cpp和.h文件位于同一文件夹中。
What am I doing wrong? 我究竟做错了什么?
#include "stdafx.h"
必须是目标文件中的第一行 ,任何#using
其后(或者更好的是,在其中)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.