fork download
  1. //C++ ObjInf.dll
  2. //---
  3.  
  4.  
  5.  
  6. #define DLL_EXPORT //省略...
  7. #define API __stdcall//CallingConvention
  8.  
  9. extern "C"
  10. {
  11. struct ObjInf{
  12. virtual Initial() = 0;
  13. virtual Delete() = 0;
  14. virtual Run(int time) = 0;
  15. };
  16. DLL_EXPORT ObjInf* API CreateObj();
  17. };
  18.  
  19.  
  20.  
  21. //---
  22. //C#
  23.  
  24.  
  25. using System;
  26. using System.Runtime.InteropServices;
  27. namespace DllTest
  28. {
  29.  
  30. [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)]
  31. public struct ObjInf_vTable
  32. {
  33. [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
  34. public delegate void funInitial(IntPtr thisPtr);
  35.  
  36. [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
  37. public delegate void funDelete(IntPtr thisPtr);
  38.  
  39. [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
  40. public delegate void funRun(IntPtr thisPtr , int time);
  41.  
  42. public funInitial Initial;
  43. public funDelete Delete;
  44. public funRun Run;
  45. }
  46.  
  47.  
  48. [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)]
  49. public struct sObjInf
  50. {
  51. public IntPtr pTable;
  52. }
  53.  
  54. class Program
  55. {
  56. [DllImport("ObjInf.dll", CallingConvention = CallingConvention.StdCall)]
  57. public static extern IntPtr CreateObj();
  58.  
  59.  
  60. static void Main(string[] args)
  61. {
  62. IntPtr ThisPtr = CreateObj();
  63. sObjInf obj = (sObjInf)Marshal.PtrToStructure(ThisPtr, typeof(sObjInf));
  64. ObjInf_vTable objTable = (ObjInf_vTable)Marshal.PtrToStructure(obj.pTable, typeof(ObjInf_vTable));
  65.  
  66. objTable.Initial(ThisPtr);
  67. }
  68. }
  69. }
  70.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty