我的情況是這樣的。C#編譯失敗,因爲「由於其保護級別」
我有3個項目。
PrivacyDetectorDLL PDWrapper WindowsFormsApplication1(C#)
我的目標是用本地C++類在C#中。 所以我使用了C++/Cli包裝類。 但是我得到了保護級別的錯誤。我不明白。
我得到這個錯誤!
Error 1 'PDWrapper.PDWrapperClass.m_pCPrivacyDetectEngine' is inaccessible due to its protection level K:\Visual Studio 2010 Project\PrivacyDetecter\WindowsFormsApplication1\Form1.cs 23
我從WindowsFormsApplication1項目的C#代碼是這樣的。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public PDWrapper.PDWrapperClass m_PDWrapper = null;
public Form1()
{
m_PDWrapper = new PDWrapper.PDWrapperClass();
unsafe
{
m_PDWrapper.m_pCPrivacyDetectEngine->initEngine();
}
InitializeComponent();
}
}
}
My PDWrapper Class看起來像這樣。
// PDWrapper.h
#pragma once
using namespace System;
namespace PDWrapper {
public ref class PDWrapperClass
{
// TODO: Add your methods for this class here.
public :
PDWrapperClass();
~PDWrapperClass();
public :
CPrivacyDetectEngine* m_pCPrivacyDetectEngine;
};
}
,這是我PrivacyDetectEngine頭(從PDWrapper項目頭)
#pragma once
class CPrivacyDetectEngine
{
public: // my func
CPrivacyDetectEngine(void);
~CPrivacyDetectEngine(void);
void CPrivacyDetectEngine::initEngine();
void CPrivacyDetectEngine::startEngine(char* currentPath, size_t length);
public: // my util func
int CPrivacyDetectEngine::bytecmp(unsigned char *a, unsigned char *b, int length);
void CPrivacyDetectEngine::extToNum(char* fileName, unsigned int* extNum);
int CPrivacyDetectEngine::checkFileSig(unsigned char* fileSig, int sigLength, char* filePath, char** pFileInternal);
void CPrivacyDetectEngine::parseMSDocText(char** pFileInternal, unsigned int* compSize, unsigned int* decompSize);
char* CPrivacyDetectEngine::infData(char* pFileData, int compSize, int decompSize);
void CPrivacyDetectEngine::privacyDetectXML(char* text, int textLength, int* pItemIndex, char* filePath);
void CPrivacyDetectEngine::checkSocialNum(char* text);
public: // my var
int driverCount;
char driverName[256];
unsigned int parseFileList;
};
從PrivacyDetectorDLL我PrivacyDetectEngine頭是相同的,但確實有類CPrivacyDetectEngine之間__declspec(dllexport)的像
class __declspec(dllexport) CPrivacyDetectEngine
我不知道是什麼問題....有人請幫助我。
您是否重建過所有的項目? – SLaks 2013-05-13 14:44:35
將'class CPrivacyDetectEngine'標記爲'public class CPrivacyDetectEngine'。 – Saravanan 2013-05-13 14:44:41