Re: Visual C++ dll to Delphi

"David, David, David, David Segatore, Segatore, Segatore, Segatore" <[email protected]>
Newsgroups gmane.comp.lang.delphi.jedi
Message-ID <[email protected]>
Thanx for your help I did the translation in this way and now is working
fine:
////////// Definisco  STRUCT INIT //////////////////////////////////////////////
type
  StructInit = record
  enabled  : boolean;
  CommPort : integer;
  Settings : pchar;
end;
  Init = StructInit; file://il nome structinit ha solo valore in C
  PInit = ^Init;
  
type
   RefreshStatus = procedure( Id : LongInt; Status : LongInt); stdcall ;
////////////////////////////////////////////////////////////////////////////////
//// creazione record CHIPINF //////////////////////////////////////////////////
type
  StructChip = record
  ReadersIndex : integer;
  nargs : integer;
  params : ^pchar;
  PtrFunc : RefreshStatus;
end;
  CHIPINF = StructChip;
////////////////////////////////////////////////////////////////////////////////
file://---------- FUNZIONE SET_Enviroment -------------------------------------------
function Set_Enviroment(NP : integer; mSettings : PInit ; InitString : pchar) : integer;stdcall;
var
 vRet : integer;  file://risultato da controllare
 i    : integer;
 f    : textfile; file://texfile da utilizzare per leggere e scrivere
Const MAX_PORT = 5; file://massimo numero di caricatori
begin
 vRet := 0; // valore di errore di default...
 result := vRet;
end;
////////// #END# Funzione Set_Enviroment ///////////////////////////////////////
function Close_Enviroment:integer; stdcall;
begin
result := 0;
end;
////////////////////////////////////////////////////////////////////////////////
function Card_Perso(ChipPers : CHIPINF):integer;stdcall;
begin
result := 0;
end;
////////////////////////////////////////////////////////////////////////////////
function Card_Read(CardCode : pchar; size : integer ; ReaderIndex : integer;
         PtrFunc : RefreshStatus):integer; stdcall;
begin
result := 0;
end;
////////////////////////////////////////////////////////////////////////////////
function Card_Test(ChipPers : CHIPINF):integer;stdcall;
begin
result := 0;
end;
////////////////////////////////////////////////////////////////////////////////
function Lib_Version(CardCode : pchar ; size : integer): integer;stdcall;
var
vret : integer;
begin
vret := 0;
result := vret;
end;
//////////////////////////////////////////////////////////////////////////////
Exports       file://export function
   Set_Enviroment,    
   Close_Enviroment,
   Card_Perso,
   Card_Read,
   Card_Test,
   Lib_Version;
/////////////////////////////////////////////////////////////////////////////
Thank you vey much for your help Andrew and Robert.
If you need some advice on smartcard system, I am more
confident with that field.
bye
David

Robert Marquardt <[email protected]> wrote:
On Fri, 19 Dec 2003 15:04:25 +0100, you wrote:

>>#pragma once
>
>Dunno

Throw away. Tells the C compiler to include the header only once.

>>#define DllImport __declspec( dllimport )
>>#define DllExport __declspec( dllexport )

Simply exports the function from the DLL:

>>#ifdef __cplusplus
>>extern "C" {
>>#endif

Thess the C++ compiler that it is a C function without C++ name
mangling.

>>typedef struct StructInit {

Ignore the StructInit name. It only has a meaning in C.

>> BOOL enabled;
>> int CommPort;
>> char *Settings;
>>} INIT;
>
>This is a simple record, like this:
>
>Type
>
> StructInit = record

I am sure it should be packed record.
The name is INIT.

> Enabled : Boolean;

BOOL is LongBool

> CommPort : Integer;
> Settings : PChar;
> end;
>
> Init = StructInit;
>
>>typedef void (WINAPI *refreshStatus)(long id, long status);
>
>This is a function template call, like this:
>
>Type
> RefreshStatus = procedure( Id : LongInt;Status : LongInt );stdcall;
>
>Or
>
>Type
> RefreshStatus = function( Id : LongInt;Status : LongInt ) : Pointer;
> stdcall;

This is wrong. It is a procedure.

-- 
Robert Marquardt (Team JEDI) http://delphi-jedi.org

To unsubscribe from this group, send an email to:
[email protected]




Yahoo! Groups Links

To visit your group on the web, go to:
http://groups.yahoo.com/group/Delphi-JEDI/

To unsubscribe from this group, send an email to:
[email protected]

Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/ 



---------------------------------
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

[Non-text portions of this message have been removed]


To unsubscribe from this group, send an email to:
[email protected]

 

Yahoo! Groups Links

To visit your group on the web, go to:
 http://groups.yahoo.com/group/Delphi-JEDI/

To unsubscribe from this group, send an email to:
 [email protected]

Your use of Yahoo! Groups is subject to:
 http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.