Problems Integrating C++ Dll with C#

  • Thread starter Leandro H. Delamare
  • Start date
L

Leandro H. Delamare

Hello group.

I'm with a problem a few days with Smart Cards
I Have an C++ DLL with some funcions to read a Smart Card.
But the problem is, I have the declarations in C++ and a Program Example in
Delphi.
I want to make this program with C#

How I Can Import and use the DLL Funcions in My C# Program. Some functions
is working OK, but I have a function called EAG_GetCardCredits doesn't work.

The C++ Declaration is : int WINAPI EAG_GetCardCredits(int iHandle, int
iPurseId, long *lpCardCredits);

In My C# Program I Declarate this way:
[DllImport("Crypto.dll")]
public static unsafe extern int EAG_GetCardCredits(int iHandle, int
iPurseId, out long* lpCardCredits);

The Sample in Delphi is :
Function GetCardCredits(): String;

var st: Integer;

CardCredits: LongInt;

aux,aux2: string;

begin

st:=EAG_GetCardCredits(ReaderHandle, 0, CardCredits);

if st=0 then

begin

Str(CardCredits div 100,aux);

aux2:=Format('%.02d', [CardCredits mod 100]);

aux:=aux + ',' + aux2;



GetCardCredits:=aux;

end

else GetErrorMessageGen(st,'EAG_GetCardCredits_NOK');

end;



How can I solve this problem ?



Best Regards

Leandro H. Delamare
 
A

Arthur Nesterovsky

Hi,

The C++ Declaration is : int WINAPI EAG_GetCardCredits(int iHandle, int
iPurseId, long *lpCardCredits);

In My C# Program I Declarate this way:
[DllImport("Crypto.dll")]
public static unsafe extern int EAG_GetCardCredits(int iHandle, int
iPurseId, out long* lpCardCredits);

It seems that you did a misprint. It should look like:

[DllImport("Crypto.dll")]
public static unsafe int EAG_GetCardCredits(int iHandle, int iPurseId, ref
int lpCardCredits);


Pay attantion that long in C++ has the same length as int in C#.
And "long *" isn't "out long *", but "ref long" or may be "out long".

Hope this help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top