By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,186 Members | 1,620 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,186 IT Pros & Developers. It's quick & easy.

Problems Integrating C++ Dll with C#

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Leandro H. Delamare" <lh********@uol.com.br> wrote in
news:O7**************@TK2MSFTNGP11.phx.gbl:

[...]
How can I solve this problem ?

Best Regards

Leandro H. Delamare


By reading this article:

http://msdn.microsoft.com/library/en-
us/cpguide/html/cpconmarshalingdatawithplatforminvoke.asp

greets
Peter

--
------ooo---OOO---ooo------

Peter Koen - www.kema.at
MCAD CAI/RS CASE/RS IAT

------ooo---OOO---ooo------
Nov 15 '05 #2

P: n/a
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.
--
______________________________
With best wishes, Arthur Nesterovsky
Please visit my home page:
http://www.nesterovsky-bros.com

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.