473,382 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

C Api call from VB.Net

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);

Nov 20 '05 #1
2 2234
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" <s.*******@web.de> wrote in message
news:2a****************************@phx.gbl...
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);

Nov 20 '05 #2
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 thenecessary code there.
create a reference to that assembly, and start using the code from VB. Notranslation necessary.


Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
35
by: hasho | last post by:
Why is "call by address" faster than "call by value"?
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
4
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage...
5
by: Amaryllis | last post by:
I'm trying to call a CL which is located on our AS400 from a Windows application. I've tried to code it in different ways, but I seem to get the same error every time. Does anyone have any clue...
13
by: mitchellpal | last post by:
i am really having a hard time trying to differentiate the two..........i mean.....anyone got a better idea how each occurs?
13
by: shsingh | last post by:
I have a class A containing some map as data variables. I creat an object of class A on heap by allocatiing memory by using "malloc". This will return me the required memory but the object is not...
3
by: cberthu | last post by:
Hi all, Is it possible to have two connects in the same rexx script to different DB's? I have to get data form on DB (with specifics selects and filter out some values with RExx) and save the...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.