Solved

Trying to call a C DLL, need some C --> Delphi translating help

Posted on 2014-11-21
11
316 Views
Last Modified: 2014-12-02
Hi, I'm trying to call a 3rd party sort routine DLL written in C from my Delphi 7 app. The tech support from this place never worked with Delphi before so they are not much help there... and I know nothing about C.
    The dll file 'libsortcl.dll' contains these 3 routines I need to call:

1) sortcl_alloc()
2) sortcl_routine()
3) sortcl_free()

According the the C header file that it uses, I apparently need these variable and type declarations:

typedef struct cs_sortcl_s  cs_sortcl_t;
typedef cs_sortcl_t *cs_sortcl_p;
struct cs_sortcl_s {
    void* priv;
};


sortcl_alloc() takes no parameters and returns a variable of type cs_sortcl_t :

cs_sortcl_t* sortcl_alloc();
cs_sortcl_t* sortcl = sortcl_alloc();


sortcl_routine()is a function that accepts two arguments:
- a pointer to the structure cs_sortcl_t, which was allocated in
sortcl_alloc()
- a pointer to a char

int sortcl_routine(cs_sortcl_t* sortcl,char* command);


sortcl_free accepts one parameter, which is a variable of the type
cs_sortcl_t, and returns a void:

void sortcl_free(cs_sortcl_t* sortcl);


Additionally, the docs say that "The compiler also requires the header files sortcl_routine.h and cosort.h". Does this mean I include these C files in my Delphi app? That won't work, will it??
   Ito goes on to say "If compiling dynamically, you must define __DLL_IMPORT__". Is there a Delphi equivalent of this "__DLL_IMPORT__".

Thanks to all.. this DLL stuff has always been greek to me... especially when you throw C into the mix. Would anyone be abel to Delphi-ize this for me please?

Thanks
   Shawn
0
Comment
Question by:shawn857
  • 7
  • 2
  • 2
11 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 400 total points
ID: 40459096
>   the docs say that "The compiler also requires the header files sortcl_routine.h and cosort.h". Does this mean I include these C files in my Delphi app? That won't work, will it??
Delphi can not accept/analyze C headers/code. When needed you convert the headers to ".pas" files that delphi can understand. At this point that is not required, all you need is creating the related parameters that you pass/receive from the DLL functions.

Converting, I will try...

typedef struct cs_sortcl_s  cs_sortcl_t;
typedef cs_sortcl_t *cs_sortcl_p;
struct cs_sortcl_s {
    void* priv;
};

Should be:

Interface

Type
  cs_sortcl_t= ^cs_sortcl_s;
  cs_sortcl_s= Record
    priv: Pointer;
  end;

function sortcl_alloc(): cs_sortcl_t;  stdcall;
function sortcl_routine(cs_sortcl_p: cs_sortcl_t; cmd: PChar): integer;  stdcall;
procedure sortcl_free(cs_sortcl_p: cs_sortcl_t);  stdcall;

Implementation

function sortcl_alloc; external 'libsortcl.dll';
function sortcl_routinel; external 'libsortcl.dll';
procedure sortcl_free; external 'libsortcl.dll';

//When using
var
  cs_sortcl_p: cs_sortcl_t;
  rs: integer;      //result from sortcl_routine()
  cmd: PChar;           //sortcl_routine() param2
begin
  //Call the DLL functions
  cs_sortcl_p:= sortcl_alloc();
  rs:= sortcl_routine(cs_sortcl_p, cmd);
  sortcl_free(cs_sortcl_p);
end;

Open in new window

0
 

Author Comment

by:shawn857
ID: 40460395
Fantastic Jimy, thanks. I'm going to try this and I will let you know...

Thanks
   Shawn
0
 

Author Comment

by:shawn857
ID: 40461435
Well, good news and bad news Jimy: everything compiles fine, then I start stepping through the code in debug. The cs_sortcl_p:= sortcl_alloc(); statement works fine, and produces a handle. But the rs:= sortcl_routine(cs_sortcl_p, cmd); statement produces this runtime error:

Access violation at address 00726086 in module 'libsortcl.dll'. Read of address 0000001D.

I have the libsortcl.dll file in my working directory, as per the documentation that came with the sort utility.
   Any ideas?

Thanks!
    Shawn

P.S: The sortcl_free(cs_sortcl_p); statement works fine too. I tested it by commenting out the call to sortcl_routine.
0
 
LVL 24

Expert Comment

by:jimyX
ID: 40461512
Hi Shawn,

>   "But the rs:= sortcl_routine(cs_sortcl_p, cmd); statement produces this runtime error:..."

What did you assign to cmd?
You need to assign something before calling sortcl_routine().

I suspect you need to send some sort of command to be chewed by the routine "sortcl_routine" in order to get integer result.

What does the docs say about working with that function?
0
 

Author Comment

by:shawn857
ID: 40461546
Yep I did Jimy, I populated a string (hstring) with all the proper sort parameters I needed to do the sort as per the docs. Then I did a Cmd:=PChar(hstring); to convert it to PChar. Then I used Cmd in the call to sortcl_routine.
    It looks to me like it's not even getting through to the sortcl_routine at all. Even if my "Cmd" instructions were faulty, the sortcl_routine function should at least attempt to execute and return a sort error code (because of incorrect parameters).

Thanks!
    Shawn
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 25

Assisted Solution

by:Sinisa Vuk
Sinisa Vuk earned 100 total points
ID: 40463082
you did not post sortcl_routine.h, cosort.h .... but maybe calling convention is wrong - use cdecl instead of stdcall.
0
 

Author Comment

by:shawn857
ID: 40463221
Thanks Sinisa. I did try cdecl instead of stdcall... no luck, same runtime error  :-(
Here are the contents of those files you requested:


Sortcl_routine.h:

/*****************************************************************************
 *  File: sortcl_routine.h - Definitions and Declarations for sortcl APIs
 *
 *  Copyright 1978 - 2007 CoSort/Innovative Routines International(IRI), Inc.
 *  All Rights Reserved.
 ******************************************************************************/

#ifndef SORTCL_ROUTINE_H
#define SORTCL_ROUTINE_H

#ifndef SORTCL_H

/* declare sortcl structure */

typedef struct cs_sortcl_s  cs_sortcl_t;
typedef cs_sortcl_t *cs_sortcl_p;
typedef struct cs_queue_s cs_queue_t;

struct cs_sortcl_s {
    void* priv;
};

struct cs_queue_s {
    void* priv;
};

cs_queue_t* cs_queue_alloc(void);
void cs_queue_init(cs_queue_t* queue, int max_size);
void cs_queue_end_of_data(cs_queue_t* queue);
void cs_queue_done(cs_queue_t* queue);
int cs_queue_is_done(cs_queue_t* queue);
void cs_queue_free(cs_queue_t* queue);

int cs_queue_ptr_to_string(cs_queue_t* queue, char* str, int maxlen);

#endif

/* threadsafe routines */

#ifdef  __cplusplus
extern "C" {
#endif /* __cplusplus */

#if defined (__DLL_IMPORT__)
#define CS_SORTCL_LIBSPEC __declspec( dllimport )
#elif defined (_USRDLL)
#define CS_SORTCL_LIBSPEC __declspec( dllexport )
#else
#define CS_SORTCL_LIBSPEC
#endif /* CS_SORTCL_LIBSPEC */

CS_SORTCL_LIBSPEC int sortcl_routine( cs_sortcl_p pSortcl, const char *szCmd );
CS_SORTCL_LIBSPEC cs_sortcl_t* sortcl_alloc(void);
CS_SORTCL_LIBSPEC void sortcl_free(cs_sortcl_t* sortcl);
CS_SORTCL_LIBSPEC int sortcl_reg_userproc(cs_sortcl_t* sortcl, char *, cs_function_ptr funcptr);

#ifdef  __cplusplus
}
#endif /* __cplusplus */

/*************** STRUCTURES AND VARIABLES NEEDED TO DEFINE EXTERNAL FIELD LEVEL FUNCTIONS *****************/

/* these are the function return values. */
#define CE_EXT_OK		  0		/* ret value is ok, all others indicate not ok */
#define CE_EXT_BADTYPE    1		/* display a warning and try not to call the external function again */ 
#define CE_EXT_BADVALUE   2		/* display a warning the first time indicating possible bad data */
#define CE_EXT_BADNUM     3		/* display a warning the first time indicating possible bad data */
#define CE_EXT_ABORT     -1		/* display an error message if any sent back and abort */


#ifndef _CS_LONGDOUBLE_T_
#define _CS_LONGDOUBLE_T_
#ifdef WINDOWS
typedef double cs_longdouble_t;
#else
#ifndef cs_longdouble_t
typedef long double cs_longdouble_t;
#endif /* cs_longdouble_t */
#endif /* WINDOWS */
#endif /* _CS_LONGDOUBLE_T_ */

/* Defined values for the iMode field in the source structure */
typedef enum {
	CS_EXT_BEGIN,   /* a signal to initialize, before any data is sent       */
	CS_EXT_VALUE,   /* used on every call to return a field or value         */
	CS_EXT_BREAK,	/* used on break conditions, not implemented yet         */
	CS_EXT_END      /* used to signal the end of processing, clean up        */
} cs_ext_mode;

/* The union cs_ext_value_s contains the actual values/data that are passed to/from sortcl
   and the user defined routine for the field.*/
typedef union cs_ext_value_s {
	char            *szValue;
	cs_longdouble_t ldValue;
	double          dValue;
	int             iValue;
	long            lValue;
	short           shValue;
} cs_ext_value_t;

/* This contains the definitions associated with the data that is passed into the external function. */ 
typedef struct cs_ext_arg_s {
	int             iValueForm; /* Found in cosort.h, can be CS_ALPHA, CS_NUMERIC, Separates out the data by form
								   and then the data can be further classified using datatypes */ 
	int             iValueType; /* This is the datatype of the source argument. A list of datatypes and their names
								   can be found from cosort.h. e.g. CS_ASCII, CS_DOUBLE */
	int             iValueLen;  /* The length of the source argument. sizeof (type) for numeric data, 
								   length of string for CS_ASCII */  
	cs_ext_value_t* arg;		/* This contains the value or the actual data for the field */
} cs_ext_arg_t;

/* The structure cs_ext_source_s contains the source argument(s) which are passed on to the external
   function. The function call is setup in sortcl in the format ----
   *********************  /FIELD=(F1=BASIC_FUNC(ARG1,ARG2,ARG3....ARGn)++ *********************
   This is internally setup as an array of sources(arguments), and then passed onto the user.

   The index of the first source argument starts at 1, and goes on until ARGn.Theoretically a function
   could also have zero arguments. 

   ++ Further expansisons and uses refer to the CoSort Manual. */
/*------------------------------------------------------------------------------------------------*/
typedef struct cs_ext_source_s {
	void*         pPrivate;	/* a priv pointer for the external function to use as needed */
	cs_ext_mode   iMode;	
	int           iNumArgs;	/* number of arguments passed in */ 
	cs_ext_arg_t* SrcArgs;  /* pointer to the source arguments. This is an array */ 
} cs_ext_source_t;

/* This structure contains the result value computed by the field level function which is passed
   back to the calling sortcl program. There can only be one result value that you can pass back.
   The result should be setup using the structure given below so that sortcl can interpret it
   correctly for the final output. 

   The default datatype and size expected by the sortcl script is passed into the result argument. 
   The user can override these values. The memory for ResArg->arg needs to be setup by the user.
*/
/*------------------------------------------------------------------------------------------------*/
typedef struct cs_ext_result_s {
	int          iErrorNum;     /* An error number for the user to return, if there is an error at their end */
	char         *szErrorMsg;   /* An error string for the user to return. The memory for this
	                               needs to be allocated by the user. */ 
	cs_ext_arg_t *ResArg;		/* pointer to result argument. */ 
	void         *extended[2];     /* additional data for feld xforms */
} cs_ext_result_t;

/* Function declaration for an external WINDOWS routine looks like this 
__declspec (dllexport) int cs_ext_function( cs_ext_source_t *source, cs_ext_result_t *result );
*/

#endif /* SORTCL_ROUTINE_H */

Open in new window



Cosort.h:

/*****************************************************************************
 *  File: cosort.h - Definitions and declarations for CoSort engine
 *
 *  Copyright 1978 - 2007 CoSort/Innovative Routines International(IRI), Inc.
 *  All Rights Reserved.
 ******************************************************************************/

#ifndef _DEFINED_COSORT_H_
#define _DEFINED_COSORT_H_

#ifdef  __cplusplus
extern "C" {
#endif /* __cplusplus */

#include "cosort_err.h"

#ifdef WIN32
#include <windows.h>
#endif

#if (defined (WIN32) || defined (_WINDOWS)) && !defined (WINDOWS)
#define WINDOWS 
#endif /* WIN32 */

#ifndef HAVE_CONFIG_H

#ifndef int64_t
#ifdef WINDOWS
#define int64_t      __int64
#else
#define int64_t      long long  
#endif /* WINDOWS */
#endif /* int64_t */

#ifndef cs_function_ptr
typedef int (*cs_function_ptr)();
#endif /* cs_function_ptr */


#ifndef _CS_LONGDOUBLE_T_
#define _CS_LONGDOUBLE_T_
#ifdef WINDOWS
typedef long double cs_longdouble_t;
#else
#ifndef cs_longdouble_t
typedef long double cs_longdouble_t;
#endif /* cs_longdouble_t */
#endif /* WINDOWS */
#endif /* _CS_LONGDOUBLE_T_ */


typedef struct cs_cosort_s cs_cosort_t;

struct cs_cosort_s {
    void* priv;
    int sw;
    int mesg;
    char* porta;
    char* portb;
    int total_reccount;
};

/* library initialization */
void cosort_lib_init(void);
void cosort_lib_fini(void);

/* cosort structure handling */
cs_cosort_t* cosort_alloc(void);
int cosort_init(cs_cosort_t* cs);
void cosort_done(cs_cosort_t* cs);
void cosort_free(cs_cosort_t* cs);

/* reentrant cosort routine */
void cosort_r(cs_cosort_t* cs);

/* emergency cleanup routine (in case of segv, etc) */
void cosort_cleanup(cs_cosort_t* cs);

/* Defined values for the iMode field in the compare structure */
typedef enum {
    CS_CMP_BEGIN,   /* a signal to initialize, before any data is sent       */
    CS_CMP_VALUE,   /* used on every call to return a field or value         */
    CS_CMP_END      /* used to signal the end of processing, clean up        */
} cs_cmp_mode;

struct cs_cmpdata_s {
  void        *pPrivate;     /* Priv pointer for use by external function */
  cs_cmp_mode  iMode;    
  int          iErrorNum;    /* Return error value. For future use */
  int          iRecordLen1;  /* Length of first field or record */
  int          iRecordLen2;  /* Length of second field or record */
  int          iFieldOffset; 
  int          iFieldLen;
};
typedef struct cs_cmpdata_s cs_cmpdata_t;
typedef cs_cmpdata_t*  cs_cmpdata_p;

#endif

/*#define __DLL_IMPORT__ */
/* Uncomment the previous line when linking with cosortdll.lib/cosortdll.dll */
#ifdef _USRDLL
#define DllExport       __declspec( dllexport )
#define COSORT_RET DllExport void _stdcall 
#define MAXJOBS 32
extern char *CS_Return[];
extern DllExport int64_t cs_rec_ct;
extern DllExport int64_t cs_input_ct;
extern DllExport int64_t cs_reject_ct;
#else
#define DllExport
#ifdef __DLL_IMPORT__
#define DllImport       __declspec( dllimport )
#define COSORT_RET DllImport void _stdcall 

extern DllImport char *CS_Return[];
extern DllImport int64_t cs_rec_ct;
extern DllImport int64_t cs_input_ct;
extern DllImport int64_t cs_input_ct;
#else
#define COSORT_RET void 
extern char *CS_Return[];
extern int64_t cs_rec_ct;
extern int64_t cs_input_ct;
extern int64_t cs_reject_ct;
#endif
#endif

COSORT_RET cosort(int *sw, int *msg, char *porta, char *portb);

/* after calling cosort(), these globals are record counts */
/* extern int64_t cs_rec_ct;    */
/* extern int64_t cs_input_ct;  */
/* extern int64_t cs_reject_ct; */

/* External Library Variables */
#ifdef WIN32
#define CS_DLL "cs_user.dll"
typedef HINSTANCE cs_handle;
#else
#define CS_DLL "cs_user.so"
typedef void*  cs_handle;
#endif

/* Arguments for Memory */
#define CS_TOTALMEM    1
#define CS_AVAILMEM    2

/* First argument for COSORT. */
#define CS_DEFINE       (1<<8)
#define CS_INIT         0
#define CS_INPUT        1
#define CS_COMPARE      2
#define CS_OUTPUT       3
#define CS_ERROR        4
#define CS_EOJ          5

/* Second argument for CS_INIT. */
#define CS_SORT         0
#define CS_MERGE        1
#define CS_CHECK        2
#define CS_JOIN         3
#define CS_REPORT       4

/* options from (portb->integer on CS_INIT)     bit positions  */
#define CS_NOOPTIONS    0x0
#define CS_NODUPS       0x1
#define CS_STABLE       0x2
#define CS_QUICKEXIT    0x4
#define CS_DUPSONLY     0x8
/* cs_monitor = CS_MONITOR(options)  => 0 -> 15 */
#define CS_MONITOR(x)   (x >> 4) & 15
#define CS_SPREQD(x)    (x >> 8) & 1  

/* comparisons */
#define  CS_EQ  0
#define  CS_NE  1
#define  CS_LT  2
#define  CS_GT  3
#define  CS_LE  4
#define  CS_GE  5

/* NULL precedence */
#define CS_NULLSHIGH    1 /* NULLs high */
#define CS_NULLSLOW     2  /* NULLs low */

/* Second argument for CS_INPUT or CS_OUTPUT. */
#define CS_PROGRAM      0x00
#define CS_FONLY        0x01
#define CS_UONLY        0x02
#define CS_BOTH         (CS_FONLY | CS_UONLY)
#define CS_APPEND       0x04   /*JP 2/1/97  append feature */

/* Use in Compare Functions */
#define CS_GREATER      0x01
#define CS_LESSER       0x02
#define CS_DOCOMPARE    (CS_GREATER & CS_LESSER)

#define CS_NOTSET       -1  /* for "unset" values, not used by API users */
/**************************************************************** 
 ************ 10 byte format of each K E Y parameter ************ 
 ****************************************************************/ 
struct ckey {     /* * * * structure of each compare key * * * * */ 

                /* bit# 7 6 5 4 3 2 1 0  of one byte fields  * * */ 

    char  k_dir;     /* r r r            reserved for future use
                              c c c c    null char 1st 1/2
                                      d  direction 0 asc 1 desc  */
    char  k_ftype;   /* c c c c          null char 2nd 1/2
                                r r      reserved for future use 
                                    f f  0 fxd  1 sep  2 blnk sep */
    unsigned short k_pos;    /* 1 based,  starting byte  OR  field number */
    unsigned short k_length; /* length in bytes of the key                */
    char  k_form;    /* 0 char  1 num  2 date  3 time  4 timestamp*/
    char  k_align;   /* r r              reserved for future
                            l 0          null char is low 
                            0 h          null char is high 
                                r        reserved for future
                                  c      case: 0 ('A' != 'a') 1 off
                                    a a  align: 0 no  1 left 2 rt */
    char  k_type;    /* data type (1 -> 115) used with k_form     */
    char  k_fsep;    /* field separator char  (if k_ftype & 1)    */
    cs_function_ptr k_custom_proc_funcptr; /* function pointer to custom compare,
                                              needed for UNIX, used only internally
                                              for sortcl purposes right now.
                                              May be given to the user later on*/
    char*           k_custom_proc_name; /* function pointer to custom compare
                                           needed for WINDOWS, used only internally
                                           right now for sortcl. May be given to
                                           user later */
  };
typedef struct ckey CKEY;
typedef struct ckey cs_key_t;

/************************************************
** Compare return codes                        **
*************************************************
** For compare_routine(s1,s2) a result of      **
** TRUE means s1 comes after s2                **
************************************************/
#define CS_SAME         0
#define CS_TRUE         1
#define CS_FALSE        -1

/************************************************
** Key Structure value defines                 **
************************************************/
/************************************************
** CKEY k_dir                                  **
*************************************************
** Key Direction                               **
************************************************/
#define CS_ASCEND       0
#define CS_DESCEND      1

/************************************************
** CKEY k_ftype                                **
*************************************************
** Key Seperation type                         **
************************************************/
#define CS_FCHAR        0
#define CS_FANY         1
#define CS_FBLANK       2
#define CS_FSTR         3

/************************************************
** CKEY k_form                                 **
*************************************************
** Key Form                                    **
************************************************/
#define CS_ALPHA        0
#define CS_NUMERIC      1
#define CS_DATE         2
#define CS_TIME         3
#define CS_TIMESTAMP    4
#define CS_CUSTOMKEY    5
#define CS_MBYTECHAR    6

/************************************************
** CKEY k_align                                **
*************************************************
** Values when using with Form CS_ALPHA        **
*************************************************
** Key Alignment and Key Casefolding           **
*************************************************
** The options for Alignment and Casefolding   **
** are now present in the .align member of CKEY**
** The valid integer values are as follows:    **
**                                             **
** 0    No Casefold, No Alignment              **
** 1    No Casefold, Left Alignment            **
** 2    No Casefold, Right Alignment           **
** 3    Not Used                               **
** 4    Casefold, No Alignment                 **
** 5    Casefold, Left Alignment               **
** 6    Casefold, Right Alignment              **
** 7    Not Used                               **
**                                             **
** It is recommended that API programmers use  **
** the defines below, and use these values as  **
** reference only when debugging their code.   **
************************************************/
#define CS_NOJUST       0x00
#define CS_JUSTRIGHT    0x01  /* Right bit of the two */
#define CS_JUSTLEFT     0x02  /* Left bit of the two */
#define CS_NOCASEFOLD ~(0x04) /* Lowercase matters */
#define CS_CASEFOLD     0x04  /* Lowercase does not matter */
#define CS_COLLSEQ      0x08  /* Collating Sequence Used */
#define CS_TBH          0x40  /* Trailing Blanks High */
#define CS_TBL          0x80  /* Trailing Blanks Low */
#define CS_TBI          0xF0  /* Trailing Blanks Ignored */
/************************************************
** CKEY k_align                                **
*************************************************
** Values when using with Form CS_NUMERIC      **
*************************************************
** Backwards compatibility only, no longer used**
************************************************/
#define CS_EXTERNAL 0
#define CS_INTERNAL 1
/************************************************
** CKEY k_type                                 **
*************************************************
** Key Type                                    **
*************************************************
** Values when using with Form CS_NUMERIC      **
************************************************/
/* numeric type keys */

#define CS_ASCNUM       0   /* ASCII NUMERIC "0", "1", "2", etc. */
#define CS_CHAR         1
/* Signed C types */
#define CS_SCHAR        2
#define CS_SHORT        4
#define CS_INT          6
#define CS_LONG         8
#define CS_FLOAT        10
#define CS_DOUBLE       11
/* Unsigned C types */
#define CS_UCHAR        3
#define CS_USHORT       5
#define CS_UINT         7
#define CS_ULONG        9

/* Signed RM/Cobol types */
#define CS_RMCOMP       12      /* MF signed, stored 0x00-0x09 */
#define CS_URMCOMP      13
#define CS_RMCMP1       14      /* ? 2 bytes, 2's comp, big-endian */
#define CS_RMCMP3       15      /* MF COMP-3, 0x0B or 0x0F signed positive */
#define CS_URMCMP3      16
#define CS_RMCMP6       17      /* MF COMP-3, no sign half-byte */
#define CS_RMDISP       18      /* Unsigned DISPLAY */
#define CS_URMDISP      19      /* Unsigned DISPLAY */
#define CS_RMDISPSL     20      /* MF DISPLAY, different sign semantics */
#define CS_RMDISPSLS    21
#define CS_RMDISPST     22
#define CS_RMDISPSTS    23

/* See documentation about RM/Cobol DISPLAY, COMP, COMP-1, -3 and -6 storage
   in MF.  For MF'ed RM, use the following.  Note how length differs from
   normal MF types.

   CS_MFDISPST  for RM's COMPUTATIONAL.
   CS_MFCMP1    for RM's COMP-1, length 2.
   CS_UMFCOMP   for RM's COMP-6, length as (integer)((1 + 9's in PIC) / 2)

   The MF types below will NOT work for RM's native storage. */

/* Signed MicroFocus Cobol types. */
#define CS_MFCOMP       24      /* 1-8 bytes, 2's comp, big-endian */
#define CS_UMFCOMP      25
#define CS_MFCMP3       26      /* packed decimal, ends with sign half-byte */
#define CS_UMFCMP3      27
#define CS_MFCMP4       28
#define CS_UMFCMP4      29
#define CS_MFCMP5       30      /* MFCOMP, machine dep */
#define CS_UMFCMP5      31
#define CS_MFCMPX       32      /* MFCOMP, 1-18 bytes */
#define CS_MFDISP       33      /* 1-18 bytes, incorporated sign leading */
#define CS_UMFDISP      34      /* Unsigned MF DISPLAY */
#define CS_MFDISPSL     35      /* 1-18 bytes, incorporated sign leading */
#define CS_MFDISPSLS    36      /* 1-19 bytes, digit storage, sign leading */
#define CS_MFDISPST     37      /* 1-18 bytes, incorporated sign trailing */
#define CS_MFDISPSTS    38      /* 1-19 bytes, digit storage, sign trailing */

#define CS_ZONED 39             /* zoned decimals */
#define CS_ZONED_ASC_IN_EBC  40 /* ZONED ASCII with EBCDIC */

/* Signed RM/Cobol types in EBCDIC orientation */
#define CS_ERMCOMP       46      /* MF signed, stored 0x00-0x09 */
#define CS_EURMCOMP      47
#define CS_ERMCMP1       48      /* ? 2 bytes, 2's comp, big-endian */
#define CS_ERMCMP3       49      /* MF COMP-3, 0x0B or 0x0F signed positive */
#define CS_EURMCMP3      50
#define CS_ERMCMP6       51      /* MF COMP-3, no sign half-byte */
#define CS_ERMDISP       52      /* Unsigned DISPLAY */
#define CS_EURMDISP      53      /* Unsigned DISPLAY */
#define CS_ERMDISPSL     54      /* MF DISPLAY, different sign semantics */
#define CS_ERMDISPSLS    55
#define CS_ERMDISPST     56
#define CS_ERMDISPSTS    57

/* Signed MicroFocus Cobol types. in EBCDIC orientation */
#define CS_EMFCOMP       58      /* 1-8 bytes, 2's comp, big-endian */
#define CS_EUMFCOMP      59
#define CS_EMFCMP3       60      /* packed decimal, ends with sign half-byte */
#define CS_EUMFCMP3      61
#define CS_EMFCMP4       62
#define CS_EUMFCMP4      63
#define CS_EMFCMP5       64      /* MFCOMP, machine dep */
#define CS_EUMFCMP5      65
#define CS_EMFCMPX       66      /* MFCOMP, 1-18 bytes */
#define CS_EMFDISP       67      /* 1-18 bytes, incorporated sign leading */
#define CS_EUMFDISP      68      /* Unsigned MF DISPLAY */
#define CS_EMFDISPSL     69      /* 1-18 bytes, incorporated sign leading */
#define CS_EMFDISPSLS    70      /* 1-19 bytes, digit storage, sign leading */
#define CS_EMFDISPST     71      /* 1-18 bytes, incorporated sign trailing */
#define CS_EMFDISPSTS    72      /* 1-19 bytes, digit storage, sign trailing */

/* other numeric types */
#define CS_ZONED_EBCDIC  77      /* Signed Numeric (ZONED EBCDIC)  */
#define CS_CURRENCY      78
#define CS_MONEY         78
#define CS_IP_ADDRESS    79
#define CS_WHOLE_NUMBER  80
#define CS_BIT           81
#define CS_LONGDOUBLE    82

/* PSIGNF - packed with 0xf meaning positive (on output) */
#define CS_PSIGNF        83
/* PD - PACKED DECIMAL (0xb and 0xd as negative sign digits) */
#define CS_PD            84

#define CS_INT32         85
#define CS_UINT32        86
#define CS_INT64         87
#define CS_UINT64        88

//////////////////////////////////////////////////////////
////Following Definition For Multi Byte Characters  //////
//////////////////////////////////////////////////////////

/*------------------------------------------------------*/
//MultiByte Unicode  Chinese Japanese Korean
#define CS_UTF16_UNICODE              0
#define CS_UNI_ALPHABETIC             1
#define CS_UNI_DIGITS                 2
#define CS_UNI_CHINESE_PINYIN         3
#define CS_UNI_CHINESE_BIHUA          4

#define CS_UNI_HIRAGANA               6
#define CS_UNI_HIRAGANA_SMALL         7
#define CS_UNI_HIRAGANA_BIG           8
#define CS_UNI_KATAKANA_FULL          9
#define CS_UNI_KATAKANA_FULL_SMALL    10
#define CS_UNI_KATAKANA_FULL_BIG      11
#define CS_UNI_KATAKANA_HALF          12
#define CS_UNI_KANJI                  13

// Korean Unicode
#define CS_UNI_HANGUL                 14
// #define CS_UNI_HANJA               15

/*------------------------------------------------------*/
//MultiByte GBK   Big 5
#define CS_GBK_SIMPLIFIED             20
#define CS_GBK_TRAD_COM               21
#define CS_GBK_TRAD_RAR               22

#define CS_GBK_DIGITS                 29

#define CS_BIG5_COM                   30
#define CS_BIG5_RAR                   31
#define CS_BIG5_DIGITS                32

/*------------------------------------------------------*/
//MultiByte Japanese SJIS
#define CS_SJIS_HIRAGANA              40
#define CS_SJIS_HIRAGANA_SMALL        41
#define CS_SJIS_HIRAGANA_BIG          42
#define CS_SJIS_KATAKANA_FULL         43
#define CS_SJIS_KATAKANA_FULL_SMALL   44
#define CS_SJIS_KATAKANA_FULL_BIG     45
#define CS_SJIS_KATAKANA_HALF         46
#define CS_SJIS_KANJI                 47
#define CS_SJIS_KANJI_RAR             48
#define CS_SJIS_DIGITS                49
#define CS_SJIS_ALPHABETIC            50

/*------------------------------------------------------*/
//MultiByte Korean KSC 5601
#define CS_KSC5601_HANGUL_COM         51
#define CS_KSC5601_HANGUL_RAR         52
// #define CS_KSC5601_HANJA           53
#define CS_KSC5601_DIGITS             54

/*------------------------------------------------------*/
//Thai MultiByte Unicode and SingleByte TIS 620 
#define CS_UNI_THAI					  55
#define CS_TIS_620					  56


/* DATE/TIME/TIMESTAMP form */
#define CS_MASKED       0      /* masked date     */
#define CS_ISO          1      /* ISO format      */
#define CS_AMERICAN     2      /* American format */
#define CS_EUROPEAN     3      /* European format */
#define CS_JAPANESE     4      /* Japanese format */
#define CS_MONTH_DAY    5      /* Jan < .. < Dec  Sun < .. < Sat */
#define CS_Y2K_ASCII_YR 6      /* ASCII 2 Digit Year             */
#define CS_Y2K_ASCII_JULIAN 7  /* ASCII julian date              */
#define CS_ORACLE       8	   /* Oracle date "DD-MON-YY"        */

/************************************************
** CKEY k_type                                 **
*************************************************
** Key Type                                    **
*************************************************
** Values when using with Form CS_ASCII        **
************************************************/

/* Single-Byte Character Sets */
#define CS_UNTYPED      -1      /* Not used by API users */
#define CS_ASCII         0      /* ISO 8859-1   */
#define CS_LATIN1        0      /* ISO 8859-1   */
#define CS_EBCDIC        3      /* IBM Standard */
#define CS_LATIN2        5      /* ISO 8859-2   */
#define CS_LATIN3        6      /* ISO 8859-3   */
#define CS_BALTIC        7      /* ISO 8859-4   */
#define CS_CYRILLIC      8      /* ISO 8859-5   */
#define CS_ARABIC        9      /* ISO 8859-6   */
#define CS_GREEK        10      /* ISO 8859-7   */
#define CS_HEBREW       11      /* ISO 8859-8   */
#define CS_TURKISH      12      /* ISO 8859-9   */
#define CS_LATIN5       12      /* ISO 8859-9   */
#define CS_LATIN6       13      /* ISO 8859-10  */
#define CS_THAI         14      /* Unknown      */
  /* SBCS 15 - 19 RESERVED*/
/* Chinese */
  /* DBCS 20 - 24 */
#define CS_BIG5          20      /* Big 5, Big 5 Encoding */
#define CS_IBM_DBCS_HOST 21     /* IBM Simplified Chinese HOST */
#define CS_IBM_DBCS_PC   22     /* IBM Simplified Chinese PC */
  /* MBCS 25 - 29 */
#define CS_GBK          25      /* Extended GB2312 to include ISO10646 CJK characters */
#define CS_EUC_CN       25      /* GB 2312-80, (compatible subset of GBK) */
#define CS_EUC_TW       26      /* CNS 11643-1992 (Planes 1 - 3) */
/* Japanese */
  /* DBCS 30 - 34 */
#define CS_SJIS         30      /* JIS X 0208-1990, Shift Jis Encoding */
  /* MBCS 35 - 39 */
#define CS_EUC_JP       35      /* 0: JIS X 0201-1976 1: JIS X 0208 2: h-w katakana 3: JIS X 0212-1990 */
  /* RESERVED 40 - 44 */
#define CS_ASCINEBC     41
#define CS_ALTSEQ       42
/* Korean */
  /* DBCS 35 - 39 */
#define CS_JOHAB        45      /* KS X 1001:1992, JOHAB Encoding */
#define CS_KEF          46      /* Korean EBCDIC Format */
#define CS_EHANGUL      47      /* IBM DBCS HOST Format */
#define CS_HHANGUL      48      /* Hitachi Format */
#define CS_UHANGUL      49      /* UNISYS Format */
  /* MBCS 50 - 54 */
#define CS_EUC_KR       50      /* KS X 1001:1992, EUC Encoding */
#define CS_WANSUNG      50      /* KS X 1001:1992, EUC Encoding */
#define CS_WANSUNG_1    51      /* KS X 1001:1992, EUC Encoding */
#define CS_ASCII_1      52
#define CS_ASCII_2      53
/* Vietnamese */
  /* DBCS 55 - 59 */
  /* MBCS 60 - 64 */
  /* RESERVED 65 - 69 */
  /* RESERVED 70 - 74 */
#define CS_ASCINNATURAL 73
/* Universal Character Set Codings - Unicode */
#define CS_UTF8         80      /* ISO 10646-1:1993 */
#define CS_UTF16        81      /* ISO 10646-1:1993 */
#define CS_UTF32        82      /* ISO 10646-1:1993, UTR#19 */
/* DBMS General */
#define CS_VARCHAR      85
#define CS_LONG_VARCHAR 86
#define CS_CSTRING      87
#define CS_DB2_ISO_DATE 88
/* DBMS Specific */
#define CS_VARCHAR_TBH  90
#define CS_VARCHAR_TBI  91
#define CS_CSTRING_TBH  92

#define CS_CSV          95

  /* extensions of ASCII and EBCDIC for RowGen  */
#define CS_ASCII_ALPHA         1
#define CS_ASCII_UPPERCASE     2
#define CS_ASCII_LOWERCASE     3
#define CS_ASCII_DIGIT         4
#define CS_ASCII_ALPHA_DIGIT   5
#define CS_ASCII_SPACE         6
#define CS_ASCII_PRINTABLE     7

#define CS_ALPHABETIC          1
#define CS_UPPERCASE           2
#define CS_LOWERCASE           3
#define CS_DIGIT               4
#define CS_ALPHA_DIGIT         5
#define CS_SPACE               6
#define CS_PRINTABLE           7

#define CS_EBCDIC_ALPHA        1
#define CS_EBCDIC_UPPERCASE    2
#define CS_EBCDIC_LOWERCASE    3
#define CS_EBCDIC_DIGIT        4
#define CS_EBCDIC_ALPHA_DIGIT  5
#define CS_EBCDIC_SPACE        6
#define CS_EBCDIC_PRINTABLE    7

#define Monitor_Target(x) x > 8 ? 1 : \
                          x > 7 ? 10 : \
                          x > 6 ? 100 : \
                          x > 5 ? 1000 : \
                          x > 4 ? 10000 : \
                          x > 3 ? 100000 : 1000000

#define CS_Level_Status  1
#define CS_Level_Warning 2
#define CS_Level_Error   3

/* ################################################################################ */

#define CS_DF_OFF           0
#define CS_DF_WORKONLY      1
#define CS_DF_OUTONLY       2
#define CS_DF_ON            3

/* Structure holding Field information for conversions */
struct cs_ConvFieldInfo
{ 
   int version; /* version of this structure */
   short  len;  /* length of field */
   char   fill; /* fill character */
   short  prec; /* precision of field if numeric, float, or double */
   char  money; /* 1 for money  */
   char   mill; /* 0: NOT 1000; else: 1,000 */
};

struct cs_dbcs_struct {
    unsigned char leading_byte;
    unsigned char trailing_byte;
};

#ifdef  __cplusplus
}
#endif
#endif /* _COSORT_H */

Open in new window



Thanks!
    Shawn
0
 

Author Comment

by:shawn857
ID: 40466188
I googled around a bit on this and found this page:

http://stackoverflow.com/questions/3073860/problem-creating-calling-a-dll

There it suggests that sometimes putting a '@4' at the end of your calling function/procedure name will work. I tried it and it didn't.  :-(

I also noticed how it mentioned the "Dumpbin" utility and how it would retrieve the exact names of a DLL's exported routines. I didn't have Dumpbin.exe on my system so I googled around and found the utility "Wumpbin" and installed that and ran my DLL through it. It showed that the exact name of it was "sortcl_routine"... no different than what I was using before.  :-(
    Any more thoughts guys?

Thanks
    Shawn
0
 
LVL 25

Expert Comment

by:Sinisa Vuk
ID: 40467621
I use PE Analyzer lite from time to time to see export function names. Your calling dll is for 32bit?
0
 

Author Comment

by:shawn857
ID: 40472791
Yes, 32 bit Sinisa...

Thanks
   Shawn
0
 

Author Closing Comment

by:shawn857
ID: 40477912
Guys, we found out the problem  - the support team from the company said that they found that a compile time option was set wrong in their DLL. They created a fix and now it works fine. It did indeed require the "cdecl" protocol instead of the "stdcall", so Sinisa, you deserve some points as well for that contribution!

Thanks!
    Shawn
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now