473,769 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_DOUBL E_T, dblData);
} END(G_DATA_VALU E);

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_USHOR T_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_HGR ID_T hGrid,
G_PRANGE_T pRangeIn,
G_PPDATA_T ppDataIn);

G_FUNC_M GGetResults(G_H GRID_T hGrid,
G_ULONG_T ulOptions,
G_PRANGE_T pRangeOut,
G_PUSHORT_T pState);

G_FUNC_M GGetRows(G_HGRI D_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->ulColumnStar t = 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_PP DATA_T ppDataToFree, G_ULONG_T ulRows)
{
G_ULONG_T ulIndex;

for (ulIndex = 0; ulIndex < ulRows; ulIndex++)
{
if(ppDataToFree[ulIndex]->usType ==
G_DT_STRING)
{
free(ppDataToFr ee[ulIndex]-
Value.pszStr );

}
free(ppDataToFr ee[ulIndex]);
}
free(ppDataToFr ee);
}
-----------------------------------------------------------
----------

G_PPDATA_T ppDataIn;
G_PPDATA_T ppDataOut;
G_RANGE_T rDataRangeIn, rDataRangeOut,
rDataRangeReque sted;
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(&rRa ngeDataIn);
/* Send the entire grid to define the query */
sts = GSendRows(hGrid , &rRangeDataI n, ppDataIn);
/* Free the data */
FreeTwoDim(ppDa taIn, rRangeDataIn.ul NumRows);
/* Determine the results of the retrieve and how much data
is being returned.*/
sts = GGetResults(hGr id, 0, &rRangeDataO ut, &usState);
/* Get all of the data */
sts = GGetRows(hGrid, 0, &rDataRangeRequ ested,
&rRangeDateO ut, &ppDataOut);

Nov 20 '05 #1
2 2252
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_DOUBL E_T, dblData);
} END(G_DATA_VALU E);

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_USHOR T_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_HGR ID_T hGrid,
G_PRANGE_T pRangeIn,
G_PPDATA_T ppDataIn);

G_FUNC_M GGetResults(G_H GRID_T hGrid,
G_ULONG_T ulOptions,
G_PRANGE_T pRangeOut,
G_PUSHORT_T pState);

G_FUNC_M GGetRows(G_HGRI D_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->ulColumnStar t = 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_PP DATA_T ppDataToFree, G_ULONG_T ulRows)
{
G_ULONG_T ulIndex;

for (ulIndex = 0; ulIndex < ulRows; ulIndex++)
{
if(ppDataToFree[ulIndex]->usType ==
G_DT_STRING)
{
free(ppDataToFr ee[ulIndex]-
Value.pszStr );

}
free(ppDataToFr ee[ulIndex]);
}
free(ppDataToFr ee);
}
-----------------------------------------------------------
----------

G_PPDATA_T ppDataIn;
G_PPDATA_T ppDataOut;
G_RANGE_T rDataRangeIn, rDataRangeOut,
rDataRangeReque sted;
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(&rRa ngeDataIn);
/* Send the entire grid to define the query */
sts = GSendRows(hGrid , &rRangeDataI n, ppDataIn);
/* Free the data */
FreeTwoDim(ppDa taIn, rRangeDataIn.ul NumRows);
/* Determine the results of the retrieve and how much data
is being returned.*/
sts = GGetResults(hGr id, 0, &rRangeDataO ut, &usState);
/* Get all of the data */
sts = GGetRows(hGrid, 0, &rDataRangeRequ ested,
&rRangeDateO ut, &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
5184
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
10792
by: hasho | last post by:
Why is "call by address" faster than "call by value"?
13
4150
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 sense to punch out from managed code to native code (I was using IJW) in order to do some amount of floating point work and, if so, what that certain amount of floating point work was approximately. To attempt to do this I made a program that...
4
4291
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 I know I need to call a function that will save data but I'm not sure exactly when to call this function. I've tried two ways and both seem to have 'gotcha's':
5
3780
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 as to what this means? I am not trying to alter a table. This particular CL merely generates the next voucher number in a sequence. "SQL0204: HRCU030P in HRZNCUSOBJ type *N not found. Cause . . . . . : HRCU030P in HRZNCUSOBJ type *N was...
13
26596
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
9725
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 initialized properly as constructor same is not get called ( as per the behavior). How to call a constructor explicitly if we want to allocate memory using malloc ?
3
4785
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 results into another DB? I know from Wscripts and MS-Sql that you can build just two objects but I did not see something like that in REXX. Thanks in advance for your help
9
3277
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 function are of type int. (My question has nothing to do with the definition of the function foo, so don't bother about it.) If I call the function as: foo(2,3,4,5,6,7,8);/*More arguments than expected*/
12
7214
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? class Trial { public: Trial() {
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.