3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
C++ DLL設計 & C# 呼叫使用(可以要C++動態配置記憶體)   //C++ typedef struct _CardReaderState {   char strAutoRead[10];   char strWithBeep[10];   char strWithLED[10];   char strSameCardDetection[10];   char strGreenMode[10]; }CardReaderState;   extern “C”{   __declspec(dllexport) int SYRIS_readStateCardReader(CardReaderState*& res);   __declspec(dllexport) int SYRIS_finish(CardReaderInfo* res,CardReaderState* res1,CardInfo* res2); }   int SYRIS_readStateCardReader(CardReaderState*& res) {   res=new CardReaderState[1];   return 1; }   int SYRIS_finish(CardReaderInfo* res,CardReaderState* res1,CardInfo* res2) {   if(res)   {      delete [] res;   }   if(res1)   {      delete [] res1;   }   if(res2)   {      delete [] res2;   }   return 1; }   //C# using System.Runtime.InteropServices;//USE DLL       [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]     public struct CardReaderState     {         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]         public string strAutoRead;         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]         public string strWithBeep;         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]         public string strWithLED;         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]         public string strSameCardDetection;         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]         public string strGreenMode;     }       [DllImport(“./SYRIS_CS_LIB.dll”, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = “SYRIS_readStateCardReader”)]     public static extern int SYRIS_readStateCardReader(ref IntPtr ptr);   [DllImport(“./SYRIS_CS_LIB.dll”, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = “SYRIS_finish”)]   public static extern int SYRIS_finish(IntPtr ptr, IntPtr ptr1, IntPtr ptr2);  

本文由jashliaoeuwordpress提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦