C#调用C++写的dll的问题,也许对熟悉的人很简单,但是这个问题我查了很多资料也没解决
c++中 有这样的方法
DWORD GetChallenge(IN HANDLE hContext,
IN WCHAR *pszUserName,
OUT BYTE **pChallenge,
OUT DWORD *dwcbChallenge);
C#中我用下面的方法使用
[DllImport( "cardmgr.DLL ", SetLastError = true)]
public static extern uint CMGetChallenge
(
IntPtr hContext,
[MarshalAs(UnmanagedType.LPWStr)] string pwszUserName,
ref byte[] pbChallenge,
ref int cbChallenge);
但是在 程序中运行时获取的pbChallenge不正确,以下是调用代码
uint dwAcquireCardStatus = 1;
uint dwLockCardStatus = 1;
uint dwChangePinStatus = 0;
IntPtr hContext = new IntPtr();
int lenChallenge = 16;
byte[] challenge = new byte[16];
dwAcquireCardStatus = CardMgrWrapper.CCAcquireSingleCard(ref hContext);
if (dwAcquireCardStatus == 0)
{
dwLockCardStatus = CardMgrWrapper.CCLockCard(hContext, 0);
if (dwLockCardStatus == 0)
{
dwChangePinStatus = CardMgrWrapper.CMGetChallenge2(hContext,