search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

C++ DLL設計 & C#呼叫使用(可以要C++動態配置記憶體) – jashliao部落格

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 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦