博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

在C#中调用C++的dll的方法

Posted on 2012-02-22 10:26  未页  阅读(287)  评论(0编辑  收藏  举报

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4. using System.Runtime.InteropServices;   //注入dll需要引用的命名空间  
  5.  
  6. namespace TG300  
  7. {  
  8.     public class TG300API  
  9.     {  
  10.         //打开读写器  
  11.         [DllImport("RM300API.dll", EntryPoint = "OpenReader")]   //  在这里注入dll和对应的C++的方法  
  12.         public static extern IntPtr OpenReader([MarshalAs(UnmanagedType.LPWStr)] string arrCom);   //在C#中调用时使用的方法名称,以此参数的定义  
  13.  
  14.         //关闭读写器  
  15.         [DllImport("RM300API.dll", EntryPoint = "CloseReader")]  
  16.         public static extern void CloseReader(IntPtr handle);  
  17.  
  18.          
  19.     }  
  20. }