C Wrapper

RobEmDee

Well-known member
Joined
Mar 25, 2003
Messages
130
Location
Richmond, VA
I have downloaded some sample code written in VB.NET which provides a wrapper around methods from a C Library that I need to access.

Sample:

Declare Function CPXaddrows Lib "cplex80.dll" _
(ByVal env_ As Integer, _
ByVal lp_ As Integer, _
ByVal ccnt_ As Integer, _
ByVal rcnt_ As Integer, _
ByVal nzcnt_ As Integer, _
ByVal rhs_ As Double(), _
ByVal sense_ As Byte(), _
ByVal rmatbeg_ As Integer(), _
ByVal rmatind_ As Integer(), _
ByVal rmatval_ As Double(), _
ByVal colname_ As String(), _
ByVal rowname_ As String()) As Integer

My question is how would I accomplish this same kind of functionality using C# syntax. I know I can intermingle VB.NET and C#, but would still like to know how to do this with C#.
 
Rob,

Do you know how the c function is defined within the dll? Im not big on vb but here goes with something that may work.

[DllImport("cplex80.dll", EntryPoint="CPXaddrows", SetLastError=true, CharSet=CharSet.Ansi, ExactSpelling=true, CallingConvention=CallingConvention.Cdecl)]
public static extern int CPXaddrows(int env, int lp, int ccnt, int rcnt, int nzcnt, double rhs, Byte sense, int rmatbeg, int rmatind, double rmatval, string colname, string rowname);

without seeing the c decaration this is a guess from the vb stuff.

Regards
phil
 
From the VB declaration is looks like there are ment to be arrays
Code:
Byval rhs_ As Byte()
The brackets mean Array
 
Here is the corresponding C item from the .h file:

int CPXPUBLIC
CPXaddcols (CPXCENVptr env, CPXLPptr lp, int ccnt, int nzcnt,
const double *obj, const int *cmatbeg,
const int *cmatind, const double *cmatval,
const double *lb, const double *ub, char **colname);

Thanks.
 
Back
Top