C#处理返回为LPSTR的DLL调用

来源:互联网 发布:淘宝如何创建企业店铺 编辑:程序博客网 时间:2024/06/10 19:37

1、在vc中我是这么定义接口函数。
  int _stdcall GetGeoInfo(double dx,double dy,const char* szPath,char* field1,char* field2,bool v_bIsCache,LPSTR pszBackString)
  LPSTR pszBackString为要传出的字符串信息。
  StringBuilder strReturn=new StringBuilder(50);
  记住一点,传入用string,传出用StringBuilder

2、自己例子:

dll函数:MES_API BOOL WINAPI MES_GetWO( LPCSTR pcsSN, OUT LPSTR psWO , OUT LPSTR psReturn );

C#调用 [DllImport("MES.dll", CharSet = CharSet.Ansi)]

        public static extern bool MES_GetWO(String pcsSN,  StringBuilder psWO,   StringBuilder psReturn);

 

        public StringBuilder strWO1 = new StringBuilder(50);
        public StringBuilder strErrorMessage1 = new StringBuilder(50);

 bPass = MesOperate.MES_GetWO(strSN,  strWO1, strErrorMessage1);