www.digitalmars.com         C & C++   DMDScript  

D - Help Translating API

reply Juarez Rudsatz <juarez correio.com> writes:
People,

I need some help from converting for converting a C API to a D module. 
I have some questions and dont now how solving that :

1 - This tranlation is correct ? 


long __stdcall isc_attach_database (
   int  *, 
   short, 
   char *, 
   isc_db_handle  *, 
   short, 
   char *
 );
 
To :

extern(C) {

int isc_attach_database(
	int *,
	short *,
	char *,
	isc_db_handle *,
	char *
)

}
					    

2 - This tranlation is correct ? 

long __cdecl isc_event_block (
   char * *, 
   char * *, 
   unsigned short, 
   ...
   );

To :

extern(C) {

int isc_event_block(
   char * *, 
   char * *, 
   unsigned short, 
   ...
   );
 }
 
 3 - in D long is 64 bits long ?
 
 
4 - This translation is correct ?

typedef struct isc_blob_ctl{
    long      (*ctl_source)();	
    struct isc_blob_ctl *ctl_source_handle; 
    short		  ctl_to_sub_type;  	
    short		  ctl_from_sub_type;	

} *ISC_BLOB_CTL;

To :

struct isc_blob_ctl{
    int()		  ctl_source;	
    isc_blob_ctl*	  ctl_source_handle; 
    short		  ctl_to_sub_type;  	
    short		  ctl_from_sub_type;	

};

isc_blob_ctl* ISC_BLOB_CTL;

5 - Is correct ?

typedef void     *isc_att_handle;

To :

typedef void*	 isc_att_handle;

6 - For compiling and liking what I need ?

a ) the module ibase.d
b) the ibase.lib
c ) the ibase.dll

How this 3 things have connection ? 

Thanks 

Juarez Rudsatz
Mar 11 2002
next sibling parent "Walter" <walter digitalmars.com> writes:
"Juarez Rudsatz" <juarez correio.com> wrote in message
news:Xns91CEEFEBAB2FEjuarezcom 63.105.9.61...
 People,

 I need some help from converting for converting a C API to a D module.
 I have some questions and dont now how solving that :

 1 - This tranlation is correct ?


 long __stdcall isc_attach_database (
    int  *,
    short,
    char *,
    isc_db_handle  *,
    short,
    char *
  );

 To :

 extern(C) {

 int isc_attach_database(
 int *,
 short *,
 char *,
 isc_db_handle *,
 char *
 )

 }
stdcall translates to extern (Windows)
 2 - This tranlation is correct ?

 long __cdecl isc_event_block (
    char * *,
    char * *,
    unsigned short,
    ...
    );

 To :

 extern(C) {

 int isc_event_block(
    char * *,
    char * *,
    unsigned short,
    ...
    );
  }
unsigned short translates to ushort.
  3 - in D long is 64 bits long ?
Yes.
 4 - This translation is correct ?

 typedef struct isc_blob_ctl{
     long      (*ctl_source)();
     struct isc_blob_ctl *ctl_source_handle;
     short   ctl_to_sub_type;
     short   ctl_from_sub_type;

 } *ISC_BLOB_CTL;

 To :

 struct isc_blob_ctl{
     int()   ctl_source;
No, int(*ctl_source)();
     isc_blob_ctl*   ctl_source_handle;
     short   ctl_to_sub_type;
     short   ctl_from_sub_type;

 };

 isc_blob_ctl* ISC_BLOB_CTL;

 5 - Is correct ?

 typedef void     *isc_att_handle;

 To :

 typedef void* isc_att_handle;
alias void* isc_att_handle;
 6 - For compiling and liking what I need ?

 a ) the module ibase.d
 b) the ibase.lib
 c ) the ibase.dll

 How this 3 things have connection ?
It would be analogous to C. dlls are only necessary if you want to use them. They are not required like in java.
Mar 11 2002
prev sibling parent reply "OddesE" <OddesE_XYZ hotmail.com> writes:
"Juarez Rudsatz" <juarez correio.com> wrote in message
news:Xns91CEEFEBAB2FEjuarezcom 63.105.9.61...
 People,

 I need some help from converting for converting a C API to a D module.
 I have some questions and dont now how solving that :

 1 - This tranlation is correct ?
I marked two spots in your source with an arrow: // <----- I think they are translated wrong.
 long __stdcall isc_attach_database (
    int  *,
    short,                         // <----
    char *,
    isc_db_handle  *,
    short,                         // <----
    char *
  );

 To :

 extern(C) {

 int isc_attach_database(
 int *,
 short *,                          // <---- Should be short, not short *?
 char *,
 isc_db_handle *,
// <---- Here should go argument short?
 char *
 )
<SNIP>
 Thanks

 Juarez Rudsatz
Read Walters comment for other points. Hope this helps. -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net __________________________________________ Remove _XYZ from my address when replying by mail
Mar 12 2002
parent reply Juarez Rudsatz <juarez correio.com> writes:
Is some mistakes when translating.

I need some help again. I have some doubts :


1 - Array within a structure have the Zero Position ?

typedef struct paramvary {
    ISC_USHORT		vary_length;
    unsigned char	vary_string [10];
} PARAMVARY;

could be translated to :

struct PARAMVARY {
    ISC_USHORT		vary_length;
    ubyte[10]		vary_string;
};


2 - Far pointer are banished ?

The calling convetion is defined by following macros :

#if (defined(_MSC_VER) && defined(_WIN32)) || \
    (defined(__BORLANDC__) && (defined(__WIN32__) || defined(__OS2__)))
#define  ISC_FAR
#define  ISC_EXPORT	__stdcall
#define  ISC_EXPORT_VARARG	__cdecl
typedef           __int64  ISC_INT64;
typedef  unsigned __int64  ISC_UINT64;
#define  ISC_INT64_DEFINED
#else					/* Not Windows/NT */
#if (defined(__IBMC__) && defined(__OS2__))
#define  ISC_FAR
#define  ISC_EXPORT	_System
#define  ISC_EXPORT_VARARG	ISC_EXPORT
#else					/* not IBM C Set++ for OS/2 */
#if ( defined( _Windows) || defined( _WINDOWS))
#define  ISC_FAR	__far
#define  ISC_EXPORT     ISC_FAR __cdecl __loadds __export
#define  ISC_EXPORT_VARARG	ISC_EXPORT
#else					/* Not Windows/NT, OS/2 or Windows */
#define  ISC_FAR
#define  ISC_EXPORT
#define  ISC_EXPORT_VARARG
#endif					/* Windows and Not Windows/NT or OS/2 
*/
#endif					/* IBM C Set++ for OS/2 */
#endif   				/* Windows/NT */


My conclusion is :

ISC_FAR	   : ''
ISC_EXPORT : '__stdcall'
ISC_EXPORT_VARARG : '__cdecl'

This is right ?

and then ->

typedef struct {

    short	sqllen;	
    char  ISC_FAR *sqldata;
} XSQLVAR;

can be translated to :

struct XSQLVAR {

    short	sqllen;	
    char*	sqldata;
};
Mar 13 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Juarez Rudsatz" <juarez correio.com> wrote in message
news:Xns91D07D65AE450juarezcom 63.105.9.61...
 Is some mistakes when translating.

 I need some help again. I have some doubts :


 1 - Array within a structure have the Zero Position ?
What do you mean, "zero position"? Array in structure doesn't differ from any other array...
 typedef struct paramvary {
     ISC_USHORT vary_length;
     unsigned char vary_string [10];
 } PARAMVARY;

 could be translated to :

 struct PARAMVARY {
     ISC_USHORT vary_length;
     ubyte[10] vary_string;
 };
Yep, right. Just remove that ; after the }
 2 - Far pointer are banished ?
Since D is 32-bit and higher, there is no need in near/far pointers.
 typedef struct {

     short sqllen;
     char  ISC_FAR *sqldata;
 } XSQLVAR;

 can be translated to :

 struct XSQLVAR {

     short sqllen;
     char* sqldata;
 };
Yes.
Mar 13 2002
parent reply Juarez Rudsatz <juarez correio.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in news:a6nrcv$1qsn$1 digitaldaemon.com:

 1 - Array within a structure have the Zero Position ?
What do you mean, "zero position"? Array in structure doesn't differ from any other array...
In struct estrutura { char[5] array } , array has 5 bytes + the lenght of array?
Mar 13 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
"Juarez Rudsatz" <juarez correio.com> wrote in message
news:Xns91D0D9083BA65juarezcom 63.105.9.61...

 In struct estrutura { char[5] array } , array has 5 bytes + the lenght of
array? Of course no. It's a static array, and thus stored in the same way as in C/C++. Only dynamic arrays store their length at run-time.
Mar 13 2002