Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a little help converting some C typedefs to VB

Status
Not open for further replies.

Jasen

IS-IT--Management
May 1, 2002
435
0
0
US
Let me preface by saying I know very little about C++. What I'm trying to do is access an API in VB, but only have a C++ example to go by. Confusing to say the least. So I'm attempting to recreate the API call, and need to define some new types to do so. Not as straight forward as I thought it would be.
Here's the original code I think is relevant:
Code:
typedef  char            COR_I1;//string?
typedef  short           COR_I2;//integer
typedef  int             COR_I4;//long
typedef  unsigned char   COR_U1;//string?
typedef  unsigned short  COR_U2;//integer
typedef  unsigned int    COR_U4;//long
typedef  char            COR_BOOLEAN;//string?
typedef COR_U1 PTM_DATA_TYPE;   //string?
typedef COR_U2 PTM_DATA_LENGTH; //integer
typedef COR_U2 PTM_ELEMENTS;    //integer

typedef struct ptm_data_rec
{
   PTM_DATA_TYPE    type;
   PTM_DATA_LENGTH  len;
   PTM_ELEMENTS     elem;
   UCHAR            fill[PTM_DATA_FILL]; 
   COR_I1           value[PTM_MAXSIZE];
} PTM_DATA;

typedef struct ptmap_addr
{
   RECORD_PTR   ptr;
   COR_I4   seq_num;
} PTMAP_ADDR;

typedef struct cor_status
    {
        COR_I4      status;         
        COR_I4      err_source;     
        COR_I4      err_code;       
        COR_I4      err_ref;        
        COR_BOOLEAN err_reported;   
        TCHAR       err_msg[COR_STATUS_ERR_MSG_LEN];                          
        TCHAR       _fill[3];           
} COR_STATUS;

And then what I think it would look like in VB6, without the type aliases:
Code:
Public Declare Function PTMAP_modify_setpoint Lib "ptmap.dll" (point_value As PTM_DATA, req_adr As PTMAP_ADDR, retstat As COR_STATUS) As Long

Public Type PTM_DATA
    type As String
    len As Integer
    elem As Integer
    fill As String
    value As String
End Type

Public Type PTMAP_ADDR
    ptr As String
    seq_num As Long
End Type

Public Type COR_STATUS
    status As Long
    err_source As Long
    err_code As Long
    err_ref As Long
    err_reported As String
    err_msg As String
    fill As String  '** original member name has invalid character "_"
End Type

This code takes down the IDE with an access violation when I attempt to call the function. From the little bit you see here, did I get the data types and so forth right?
 
char = Byte
short = Integer
int = Long
UCHAR fill[PTM_DATA_FILL] = String[PTM_DATA_FILL]
COR_I1 value[PTM_MAXSIZE] = String[PTM_MAXSIZE]
TCHAR = Byte
RECORD_PTR is probably a Long

All the unsigned versions of these types are the same as the signed versions since VB doesn't let you define unsigned numbers...

You can never use String directly when calling an API. It should always be a fixed size string.
You'll need to find out the value of PTM_DATA_FILL and PTM_MAXSIZE, and replace those with their numeric value.
 
Makes sense. I can look through the #defines and find those. They're the VB equiv of a constant I take it?

My worry is about the member named "_fill" in the C code. I can't name it that in the VB type def, so I'm hoping it'll be ok without the underscore.
 
#defines are sort of like a constant, but instead of a single variable that cannot be changed, the compiler replaces every instance of the #defined word with the value after it. Ex.
Code:
#define MAX   50

int num = MAX;
...
if ( num == MAX ) { ... }
will be changed to:
Code:
int num = 50;
...
if ( num == 50 ) { ... }
by the preprocessor, then it is compiled as usual...

As for the _ in the name, you can call it whatever you want. The important thing is just getting the types right (and in the right order).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top