//C++ ObjInf.dll //--- #define DLL_EXPORT //省略... #define API __stdcall//CallingConvention extern "C" { struct ObjInf{ virtual Initial() = 0; virtual Delete() = 0; virtual Run(int time) = 0; }; DLL_EXPORT ObjInf* API CreateObj(); }; //--- //C# using System; using System.Runtime.InteropServices; namespace DllTest { [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)] public struct ObjInf_vTable { [UnmanagedFunctionPointer(CallingConvention.ThisCall)] public delegate void funInitial(IntPtr thisPtr); [UnmanagedFunctionPointer(CallingConvention.ThisCall)] public delegate void funDelete(IntPtr thisPtr); [UnmanagedFunctionPointer(CallingConvention.ThisCall)] public delegate void funRun(IntPtr thisPtr , int time); public funInitial Initial; public funDelete Delete; public funRun Run; } [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)] public struct sObjInf { public IntPtr pTable; } class Program { [DllImport("ObjInf.dll", CallingConvention = CallingConvention.StdCall)] public static extern IntPtr CreateObj(); static void Main(string[] args) { IntPtr ThisPtr = CreateObj(); sObjInf obj = (sObjInf)Marshal.PtrToStructure(ThisPtr, typeof(sObjInf)); ObjInf_vTable objTable = (ObjInf_vTable)Marshal.PtrToStructure(obj.pTable, typeof(ObjInf_vTable)); objTable.Initial(ThisPtr); } } }