我正在從本地C++移植大量的.h和.lib文件到託管C++作爲C#中引用的.dll最終使用。本機C++託管C++到C#
請問,我知道將整個東西移植到.NET會容易得多,但如果我能的話。這是第三方,我所有的.lib(無導出)和.h文件可以使用。
一切都一直順利,直到我打虛擬功能,現在我有一些代表問題。
在我得到的錯誤是:
錯誤C3756: '的ThreadFunc':委託定義衝突與現有的符號
錯誤C2079: 'MyWrapTest :: MyThreadWrap :: m_threadAttr' 使用未定義類'MyWrapTest :: MyThreadAttrWrap' 錯誤C2664: 'MyWrapTest :: AutoPtr :: AutoPtr(T *)':不能從 'MyWrapTest :: MyThreadAttrWrap' 轉換參數1至 'MyThread的*'
爲了清楚起見,我將包括本機代碼和我正在處理的內容W上。首先,本地代碼:
#ifndef MYTHREAD_HPP
#define MYTHREAD_HPP
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
#define STDCALL unsigned __stdcall
typedef unsigned (__stdcall *ThreadFunc)(void*);
#else
#define STDCALL void*
typedef void* (*ThreadFunc)(void*);
typedef unsigned int HANDLE ;
#endif
#include "generaltypes.hpp"
class MyThreadAttr;
class MyThread
{
public:
MyThread(void);
MyThread(MyThreadAttr * tta);
virtual ~MyThread() {};
virtual HANDLE start(ThreadFunc,void *, unsigned *);
virtual int stop();
static void wait(HANDLE);
#ifdef WIN32
static void wait(HANDLE, int);// msec timeout required since 'cancelThread' is no-op
#endif
static void sleep(unsigned int);
static int32 cancelThread(HANDLE hThread); // no-op on Windows (returns -1)!
#ifndef WIN32
static void setCancelStates(void);
static void endProcess();
#endif
protected:
MyThreadAttr * m_threadAttr;
void setThreadAttr(MyThreadAttr * tta);
};
#endif
和新的東西,我正在開發:
#pragma once
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
#define STDCALL unsigned __stdcall
//typedef unsigned (__stdcall ThreadFunc)(Object^);
#else
#define STDCALL Object^
typedef unsigned int HANDLE;
#endif
#include "gentypes.hpp"
#include "AutoPtr.h"
#include "MyThread.hpp"
using namespace System;
using namespace System::Runtime::InteropServices;
namespace MyWrapTest
{
public delegate Object^ ThreadFunc(Object^ o);
ref class MyThreadAttrWrap;
//#include "MyThreadAttrWrap.h"
public ref class MyThreadWrap
{
public:
MyThreadWrap(void)
{
AutoPtr<MyThread> m_NativeMyThread(new MyThread);
};
MyThreadWrap(MyThreadAttrWrap tta)
{
AutoPtr<MyThread> m_NativeMyThread(tta);
};
/*virtual ~MyThreadWrap(){};
virtual HANDLE start(ThreadFunc,System::Object^, unsigned ^);
virtual int stop();*/
static void wait(HANDLE h)
{
m_NativeMyThread->wait(h);
};
#ifdef WIN32
static void wait(HANDLE h, int i) // msec timeout required since 'cancelThread' is no-op
{
m_NativeMyThread->wait(h, i);
};
#endif
static void sleep(unsigned int i)
{
m_NativeMyThread->sleep(i);
};
static int32 cancelThread(HANDLE hThread); // no-op on Windows (returns -1)!
#ifndef WIN32
static void setCancelStates(void);
static void endProcess();
#endif
protected:
MyThreadAttrWrap m_threadAttr;
void setThreadAttr(MyThreadAttrWrap tta);
private:
AutoPtr<MyThread> m_NativeMyThread;
};
}
突出顯示所有代碼並點擊菜單頂部的0101按鈕。 – jkeys 2009-07-14 22:57:03