C++中的代码 定义了一个iReadIdentityCard 供C# 调用
#define DL1_API extern "C" _declspec(dllexport)
#include "dl1.h"
#include <cstring>
int iReadIdentityCard(char *pOutInfo, char *pErrMsg){
char *B = "姓名|男|汉族|1988-10-23|地址|513029198810230011|发行机关|20991010|20991010|adasdadsadadsa|";
strcpy(pOutInfo, B);
return 0;
}
//---------------------============
c# 调用
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Class1
{
[DllImport("SC_ID.dll", EntryPoint = "iReadIdentityCard", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
public static extern int iReadIdentityCard(StringBuilder pOutInfo, StringBuilder pErrMsg);
}
}
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
StringBuilder a=new StringBuilder(1024);
StringBuilder b=new StringBuilder();
int x = Class1.iReadIdentityCard(a, b);
Console.WriteLine(x+">>"+a+">>");
Console.ReadKey();
}
}
}
输出 的a 是乱码