我在C#中遇到了Dll問題。 Dll是用C++語言編寫的。我想使用DLL的結構和方法。我不知道如何在C#中編寫代碼,我使用結構和方法。如何在C#語言中使用C++ dlll?
C++代碼: 這是標題。
#ifndef _FILTERS_H_
#define _FILTERS_H_
#ifdef __DLL
# define DLLIMPORT __declspec (dllexport)
#else
# define DLLIMPORT __declspec (dllimport)
#endif
#define _AFXDLL
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <Wingdi.h>
///#include <windows.h>
///#include <afxwin.h>
#include <windef.h>
using namespace std;
///using namespace Gdiplus;
///#pragma comment (lib,"Gdiplus.lib")
#pragma comment (lib,"Gdi32.lib")
///using namespace System;
///using namespace System::Drawing;
#ifdef EXPORTING_DLL
#ifndef _RDT_
extern struct __declspec(dllexport) SCIOX_bitmap{
int width;
int height;
int color_depth;
int* points;
};
#endif
extern __declspec(dllexport) SCIOX_bitmap median(SCIOX_bitmap image, int size);
#else
#ifndef _RDT_
class __declspec (dllimport) DllClass
{
public:
DllClass();
virtual ~DllClass(void);
private:
};
#endif
#ifndef _RDT_
#define _RDT_
#endif
#endif /* _FILTERS_H_ */
我想叫中位數(屬性);以C#語言。
坦克你的回答和對不起壞英語
大量的例子在這裏,請搜索本: DllImport –
如果您對pinvoke不夠了解,甚至無法啓動,那麼這絕對不是您想要開始的那種功能。地板墊下隱藏着非常陰暗的內存管理問題。強烈建議使用C++/CLI。 –
不要在類型上使用'__declspec(dllexport)'。在普通的舊數據上,比如'SCIOX_bitmap',它沒用。在有特色的類中,比如'DllClass',它是有害的。習慣將接受「this」指針的全局函數導出爲明確的參數。他們可以調用該對象的成員函數作爲實現的一部分,但成員函數不能以任何輕微便攜的方式導出。 –