S
Stefan
I have a C-API and need to know how to implement a few
function in VB.Net. Who can help to translate this?
The functions sends a two-dimensional array to a server and
get a changed array back.
Here is the declaration in C:
---------------------------------------------
#define G_VOID_T void
#define G_DT_UNUSED 0
#define G_DT_STRING 1
#define G_DT_LONG 2
#define G_DT_DOUBLE 3
#define G_DT_BLANK 4
typedef (long, G_STS_T);
typedef (long, G_LONG_T);
typedef (unsigned long, G_ULONG_T);
typedef (char, G_CHAR_T);
typedef (char *, G_STR_T);
typedef (unsigned short, G_WORD_T);
typedef (double, G_DOUBLE_T);
typedef (unsigned short, G_USHORT_T);
typedef (G_VOID_T *, G_PVOID_T);
typedef (G_PVOID_T, G_HGRID_T);
typedef (G_PVOID_T, G_HANDLE_T);
typedef_struct(G_RANGE_T)
{
/* First Row in the range (zero based). IN/OUT */
ELEMENT(G_ULONG_T, ulRowStart);
/* First Column in the range (zero based).IN/OUT */
ELEMENT(G_ULONG_T, ulColumnStart);
/* Number of rows in the range IN/OUT */
ELEMENT(G_ULONG_T, ulNumRows);
/* Number of columns in the range IN/OUT */
ELEMENT(G_ULONG_T, ulNumColumns);
} END(G_RANGE_T);
typedef(G_RANGE_T *, G_PRANGE_T);
typedef_union(G_DATA_VALUE)
{
/* A Null terminated Pascal string containing
data or a member name.
* This is defined as a string whose first byte
contains the length of the string. IN/OUT */
ELEMENT(G_STR_T, pszStr);
/* A word value containing data. IN */
ELEMENT(G_WORD_T, wData);
/* A long value containing data. IN */
ELEMENT(G_LONG_T, lData);
/* A floating point value containing data. IN/OUT */
ELEMENT(G_DOUBLE_T, dblData);
} END(G_DATA_VALUE);
typedef_struct(G_DATA_T)
{
/* Attributes bitmask describing data or member. OUT */
ELEMENT(G_PVOID_T, pAttributes);
ELEMENT(G_DATA_VALUE, Value);
/* Tag describing the data type. IN/OUT */
ELEMENT(G_USHORT_T, usType);
} END(G_DATA_T);
typedef(G_DATA_T *, G_PDATA_T);
typedef(G_DATA_T **, G_PPDATA_T);
/Function Prototypes**************************/
G_FUNC_M GSendRows(G_HGRID_T hGrid,
G_PRANGE_T pRangeIn,
G_PPDATA_T ppDataIn);
G_FUNC_M GGetResults(G_HGRID_T hGrid,
G_ULONG_T ulOptions,
G_PRANGE_T pRangeOut,
G_PUSHORT_T pState);
G_FUNC_M GGetRows(G_HGRID_T hGrid,
G_ULONG_T ulOptions,
G_PRANGE_T pRangeRequested,
G_PRANGE_T pRangeOut,
G_PPDATA_T *
pppDataOut);
---------------------------------------------
in an example the array will build as follow:
G_PPDATA_T BuildTable (G_PRANGE_T pRange)
{
G_PPDATA_T ppTable;
G_STR_T current_str;
G_USHORT_T slen = 0;
pRange->ulRowStart = 0;
pRange->ulColumnStart = 0;
pRange->ulNumRows = 2
pRange->ulNumColumns = 5;
ppTable = AllocTwoDims(2, 5);
/* ROW 1 */
ppTable[0][0].usType = G_DT_BLANK;
ppTable[0][1].usType = G_DT_BLANK;
slen = strlen("Year");
current_str = malloc(sizeof(G_CHAR_T)*(slen+2));
*current_str = slen;
strcpy( (current_str + 1), "Year");
ppTable[0][2].usType = G_DT_STRING;
ppTable[0][2].Value.pszStr = current_str;
slen = strlen("Product");
current_str = malloc(sizeof(G_CHAR_T)*(slen+2));
*current_str = slen;
strcpy( (current_str + 1), "Product");
ppTable[0][3].usType = G_DT_STRING;
ppTable[0][3].Value.pszStr = current_str;
slen = strlen("Market");
current_str = malloc(sizeof(G_CHAR_T)*(slen+2));
*current_str = slen;
strcpy((current_str + 1), "Market");
ppTable[0][4].usType = G_DT_STRING;
ppTable[0][4].Value.pszStr = current_str;
/*** ROW 2 ***/
slen = strlen("Actual");
current_str = malloc(sizeof(G_CHAR_T)*(slen+2));
*current_str = slen;
strcpy((current_str + 1), "Actual");
ppTable[1][0].usType = G_DT_STRING;
ppTable[1][0].Value.pszStr = current_str;
ppTable[1][1].usType = G_DT_STRING;
slen = strlen("Sales");
current_str = malloc(sizeof(G_CHAR_T)*(slen+2));
*current_str = slen;
strcpy( (current_str + 1), "Sales");
ppTable[1][1].Value.pszStr = current_str;
ppTable[1][2].usType = G_DT_DOUBLE;
ppTable[1][2].Value.dblData = 123.45;
ppTable[1][3].usType = G_DT_BLANK;
ppTable[1][4].usType = G_DT_BLANK;
return (ppTable);
}
/* This function allocates the necessary data to send to
the server */
G_PPDATA_T AllocTwoDims (G_ULONG_T ulRows, G_ULONG_T
ulCols)
{
G_PPDATA_T ppTemp;
G_ULONG_T ulIndex;
ppTemp = malloc(sizeof(G_PDATA_T) * ulRows);
for (ulIndex = 0; ulIndex < ulRows; ulIndex++)
{
ppTemp[ulIndex] = malloc(sizeof(G_DATA_T)
* ulCols);
}
return ppTemp;
}
/* This function frees the memory allocated by
AllocTwoDims */
void FreeTwoDim(G_PPDATA_T ppDataToFree, G_ULONG_T ulRows)
{
G_ULONG_T ulIndex;
for (ulIndex = 0; ulIndex < ulRows; ulIndex++)
{
if(ppDataToFree[ulIndex]->usType ==
G_DT_STRING)
{
free(ppDataToFree[ulIndex]-
free(ppDataToFree[ulIndex]);
}
free(ppDataToFree);
}
-----------------------------------------------------------
----------
G_PPDATA_T ppDataIn;
G_PPDATA_T ppDataOut;
G_RANGE_T rDataRangeIn, rDataRangeOut,
rDataRangeRequested;
G_ULONG_T ulOptions;
G_USHORT_T usState;
/* 'hGrid' is a handle that get from a few function-calls
before
/* 'sts' gives an errormessage back from the
server (0 = ok)
ppDataIn = BuildTable(&rRangeDataIn);
/* Send the entire grid to define the query */
sts = GSendRows(hGrid, &rRangeDataIn, ppDataIn);
/* Free the data */
FreeTwoDim(ppDataIn, rRangeDataIn.ulNumRows);
/* Determine the results of the retrieve and how much data
is being returned.*/
sts = GGetResults(hGrid, 0, &rRangeDataOut, &usState);
/* Get all of the data */
sts = GGetRows(hGrid,0, &rDataRangeRequested,
&rRangeDateOut, &ppDataOut);
function in VB.Net. Who can help to translate this?
The functions sends a two-dimensional array to a server and
get a changed array back.
Here is the declaration in C:
---------------------------------------------
#define G_VOID_T void
#define G_DT_UNUSED 0
#define G_DT_STRING 1
#define G_DT_LONG 2
#define G_DT_DOUBLE 3
#define G_DT_BLANK 4
typedef (long, G_STS_T);
typedef (long, G_LONG_T);
typedef (unsigned long, G_ULONG_T);
typedef (char, G_CHAR_T);
typedef (char *, G_STR_T);
typedef (unsigned short, G_WORD_T);
typedef (double, G_DOUBLE_T);
typedef (unsigned short, G_USHORT_T);
typedef (G_VOID_T *, G_PVOID_T);
typedef (G_PVOID_T, G_HGRID_T);
typedef (G_PVOID_T, G_HANDLE_T);
typedef_struct(G_RANGE_T)
{
/* First Row in the range (zero based). IN/OUT */
ELEMENT(G_ULONG_T, ulRowStart);
/* First Column in the range (zero based).IN/OUT */
ELEMENT(G_ULONG_T, ulColumnStart);
/* Number of rows in the range IN/OUT */
ELEMENT(G_ULONG_T, ulNumRows);
/* Number of columns in the range IN/OUT */
ELEMENT(G_ULONG_T, ulNumColumns);
} END(G_RANGE_T);
typedef(G_RANGE_T *, G_PRANGE_T);
typedef_union(G_DATA_VALUE)
{
/* A Null terminated Pascal string containing
data or a member name.
* This is defined as a string whose first byte
contains the length of the string. IN/OUT */
ELEMENT(G_STR_T, pszStr);
/* A word value containing data. IN */
ELEMENT(G_WORD_T, wData);
/* A long value containing data. IN */
ELEMENT(G_LONG_T, lData);
/* A floating point value containing data. IN/OUT */
ELEMENT(G_DOUBLE_T, dblData);
} END(G_DATA_VALUE);
typedef_struct(G_DATA_T)
{
/* Attributes bitmask describing data or member. OUT */
ELEMENT(G_PVOID_T, pAttributes);
ELEMENT(G_DATA_VALUE, Value);
/* Tag describing the data type. IN/OUT */
ELEMENT(G_USHORT_T, usType);
} END(G_DATA_T);
typedef(G_DATA_T *, G_PDATA_T);
typedef(G_DATA_T **, G_PPDATA_T);
/Function Prototypes**************************/
G_FUNC_M GSendRows(G_HGRID_T hGrid,
G_PRANGE_T pRangeIn,
G_PPDATA_T ppDataIn);
G_FUNC_M GGetResults(G_HGRID_T hGrid,
G_ULONG_T ulOptions,
G_PRANGE_T pRangeOut,
G_PUSHORT_T pState);
G_FUNC_M GGetRows(G_HGRID_T hGrid,
G_ULONG_T ulOptions,
G_PRANGE_T pRangeRequested,
G_PRANGE_T pRangeOut,
G_PPDATA_T *
pppDataOut);
---------------------------------------------
in an example the array will build as follow:
G_PPDATA_T BuildTable (G_PRANGE_T pRange)
{
G_PPDATA_T ppTable;
G_STR_T current_str;
G_USHORT_T slen = 0;
pRange->ulRowStart = 0;
pRange->ulColumnStart = 0;
pRange->ulNumRows = 2
pRange->ulNumColumns = 5;
ppTable = AllocTwoDims(2, 5);
/* ROW 1 */
ppTable[0][0].usType = G_DT_BLANK;
ppTable[0][1].usType = G_DT_BLANK;
slen = strlen("Year");
current_str = malloc(sizeof(G_CHAR_T)*(slen+2));
*current_str = slen;
strcpy( (current_str + 1), "Year");
ppTable[0][2].usType = G_DT_STRING;
ppTable[0][2].Value.pszStr = current_str;
slen = strlen("Product");
current_str = malloc(sizeof(G_CHAR_T)*(slen+2));
*current_str = slen;
strcpy( (current_str + 1), "Product");
ppTable[0][3].usType = G_DT_STRING;
ppTable[0][3].Value.pszStr = current_str;
slen = strlen("Market");
current_str = malloc(sizeof(G_CHAR_T)*(slen+2));
*current_str = slen;
strcpy((current_str + 1), "Market");
ppTable[0][4].usType = G_DT_STRING;
ppTable[0][4].Value.pszStr = current_str;
/*** ROW 2 ***/
slen = strlen("Actual");
current_str = malloc(sizeof(G_CHAR_T)*(slen+2));
*current_str = slen;
strcpy((current_str + 1), "Actual");
ppTable[1][0].usType = G_DT_STRING;
ppTable[1][0].Value.pszStr = current_str;
ppTable[1][1].usType = G_DT_STRING;
slen = strlen("Sales");
current_str = malloc(sizeof(G_CHAR_T)*(slen+2));
*current_str = slen;
strcpy( (current_str + 1), "Sales");
ppTable[1][1].Value.pszStr = current_str;
ppTable[1][2].usType = G_DT_DOUBLE;
ppTable[1][2].Value.dblData = 123.45;
ppTable[1][3].usType = G_DT_BLANK;
ppTable[1][4].usType = G_DT_BLANK;
return (ppTable);
}
/* This function allocates the necessary data to send to
the server */
G_PPDATA_T AllocTwoDims (G_ULONG_T ulRows, G_ULONG_T
ulCols)
{
G_PPDATA_T ppTemp;
G_ULONG_T ulIndex;
ppTemp = malloc(sizeof(G_PDATA_T) * ulRows);
for (ulIndex = 0; ulIndex < ulRows; ulIndex++)
{
ppTemp[ulIndex] = malloc(sizeof(G_DATA_T)
* ulCols);
}
return ppTemp;
}
/* This function frees the memory allocated by
AllocTwoDims */
void FreeTwoDim(G_PPDATA_T ppDataToFree, G_ULONG_T ulRows)
{
G_ULONG_T ulIndex;
for (ulIndex = 0; ulIndex < ulRows; ulIndex++)
{
if(ppDataToFree[ulIndex]->usType ==
G_DT_STRING)
{
free(ppDataToFree[ulIndex]-
}Value.pszStr);
free(ppDataToFree[ulIndex]);
}
free(ppDataToFree);
}
-----------------------------------------------------------
----------
G_PPDATA_T ppDataIn;
G_PPDATA_T ppDataOut;
G_RANGE_T rDataRangeIn, rDataRangeOut,
rDataRangeRequested;
G_ULONG_T ulOptions;
G_USHORT_T usState;
/* 'hGrid' is a handle that get from a few function-calls
before
/* 'sts' gives an errormessage back from the
server (0 = ok)
ppDataIn = BuildTable(&rRangeDataIn);
/* Send the entire grid to define the query */
sts = GSendRows(hGrid, &rRangeDataIn, ppDataIn);
/* Free the data */
FreeTwoDim(ppDataIn, rRangeDataIn.ulNumRows);
/* Determine the results of the retrieve and how much data
is being returned.*/
sts = GGetResults(hGrid, 0, &rRangeDataOut, &usState);
/* Get all of the data */
sts = GGetRows(hGrid,0, &rDataRangeRequested,
&rRangeDateOut, &ppDataOut);