多数の.hおよび.libファイルをネイティブC++からマネージC++に移植して、最終的にC#で参照される.dllとして使用できるように取り組んでいます。
どうか、すべてを.NETに移植する方がはるかに簡単だと思いますが、できればそうすることもできます。これはサードパーティであり、使用できるのは.lib(エクスポートなし)ファイルと.hファイルだけです。
仮想関数に到達するまですべてが順調に進んでおり、現在、デリゲートの問題が発生しています。
私が得ているエラーの中には次のものがあります:
エラーC3756:'ThreadFunc':デリゲート定義が既存のシンボルと競合し
ますエラーC2079:'MyWrapTest :: MyThreadWrap::m_threadAttr'は未定義のクラスを使用します'MyWrapTest:: MyThreadAttrWrap'エラーC2664:' MyWrapTest :: AutoPtr :: AutoPtr(T *) ':パラメータ1を' MyWrapTest::MyThreadAttrWrap'から'MyThread*'に変換できません
わかりやすくするために、ネイティブコードと現在取り組んでいるものを含めます。まず、ネイティブコード:
#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;
};
}