473,322 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Problems Integrating C++ Dll with C#

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
2 1639
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: news | last post by:
We're being asked to get Quickbooks Enterprise edition for our business. We use a completely hand-made online store (PHP and mySQL) and used to simply create CSV sheets that were imported as...
0
by: Al | last post by:
I would like to add SIP stack to J2EE application server. I know that JCA 1.5 allows doing such thing. But JCA 1.5 is part of J2EE 1.4. Currently the most J2EE vendors support J2EE 1.3. Can anybody...
3
by: Phil Frost | last post by:
Greetings all. I'm attempting to embed a python interpreter at a very low level in an OS I am writing. Currently I'm stuck with build issues. Firstly, as there is no working C compiler in our OS, I...
0
by: kadam_murali | last post by:
Integrating crystal reports with oracle forms , Have anyone of you have ever tried this ? If yes please send me sample codes.Its very urgent. thanks Murali
0
by: Jakke | last post by:
Hi all, I don't know if I'm at right newsgroup but I've got some questions about integrating Crystal Reports into my own application. I'm totally new regarding Crystal Reports. Therefore I've...
0
by: Rob C | last post by:
We have a large, C++/MFC application. I want to be able to do some new development using .NET and then utilize them inside my C++ application. I remember reading that you can "easily" turn your...
3
by: Sonoman | last post by:
Hi all: Is there a class or function that I could use to integrate? By integrating , I mean calculus integration. I need to get data from a sensor that gives me the acceleration of an object. In...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
4
by: karpagam | last post by:
Since WebServices are a standardized way to invoke a method of another application over the internet, is there a way to integrate two different applications running on different platforms (Say a...
1
by: irfanhab | last post by:
Hey guys! I am having some serious problems integrating Python and C, and it's strange. Putting it simple, Just as I include Python.h in my C programe (without any further python interfacing...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.