111,098
社区成员




// TestDll.h
#pragma once
using namespace System;
namespace TestDll
{
public ref class TestDllC
{
private:
int iPid;
static int iBasePid;
public:
TestDllC();
~TestDllC();
!TestDllC();
static TestDllC();
public:
int TestFunc();
};
}
// 这是主 DLL 文件。
#include "stdafx.h"
#include "TestDll.h"
namespace TestDll
{
TestDllC::TestDllC()
{
iPid = iBasePid++;
}
TestDllC::~TestDllC()
{
}
TestDllC::!TestDllC()
{
// delete pThis;
}
static TestDllC::TestDllC()
{
iBasePid = 0;
}
int TestDllC::TestFunc()
{
return iPid;
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using TestDll;
namespace MyCom
{
[ComVisible(true)]
[Guid("96C2B813-A76C-41a5-93D6-A4B995F70AA0")]
public interface IComTest1
{
static IComTest1 GetInstance();
void Initialize();
void Dispose();
int Test();
}
[Guid("ACA89BB6-2E04-42d7-840D-ECAEA5CCF5C1"), InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface MyCom_Events
{
}
[ProgId("MyCom.MyClass")]
public class ComTest1:IComTest1
{
private static TestDllC iTestDllC;
private static IComTest1 iTestCom;
private ComTest1()
{
}
static ComTest1()
{
iTestCom = null;
iTestDllC = new TestDllC();
}
public void Initialize()
{
}
public void Dispose()
{
}
public int Test()
{
return iTestDllC.TestFunc();
}
static public IComTest1 GetInstance()
{
if (iTestCom == null)
{
lock (iTestCom)
{
if (iTestCom == null)
{
iTestCom = new ComTest1();
}
}
}
return iTestCom;
}
}
}