PC Review


Reply
Thread Tools Rate Thread

C Api call from VB.Net

 
 
Stefan
Guest
Posts: n/a
 
      2nd Mar 2004
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]-
>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);

 
Reply With Quote
 
 
 
 
Thomas
Guest
Posts: n/a
 
      2nd Mar 2004
as you have the C code, create an assembly (C# or C++) and create the
necessary code there.
create a reference to that assembly, and start using the code from VB. No
translation necessary.

"Stefan" <(E-Mail Removed)> wrote in message
news:2a9801c4004f$f3114c30$(E-Mail Removed)...
> 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]-
> >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);
>



 
Reply With Quote
 
Stefan
Guest
Posts: n/a
 
      3rd Mar 2004
Thanks for the hint, but I know as much about to do this as
the man in the moon.
>-----Original Message-----
>as you have the C code, create an assembly (C# or C++)

and create the
>necessary code there.
>create a reference to that assembly, and start using the

code from VB. No
>translation necessary.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call a javascript when i call an aspx page with a form html not running on server Fabio Mastria Microsoft ASP .NET 4 28th Jan 2008 09:05 AM
Warning 1684 CA2214 : Microsoft.Usage : 'RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)' contains a call chain that results in a call to a virtual method defined by the class. Review the following call stack for unintended consequences: steve bull Microsoft C# .NET 4 7th Jul 2005 05:54 PM
Are we new users supposed to call this number? I have auto dial on my XP in the dialer but am I required to call? Windows XP New Users 12 26th May 2005 03:47 PM
An outgoing call cannot be made since the application is dispatching an input-synchronous call Sagaert Johan Microsoft C# .NET 4 6th Apr 2005 12:12 AM
Re: Please help - How to call functions that exists in the main application. The call should be initiated from one of the components. Baavgai Microsoft C# .NET 0 4th Sep 2004 05:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:23 AM.