Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Accessing C++ Structure Array values in C# Client

$
0
0

The following is my C++ declaration of the function:

unsigned moduleDescription (unsignedmodulnumber,char*constname,t_c_pindescription*constp_inputs,t_c_pindescription*constp_outputs,t_c_pindescription*constp_intern);

The following is my C++ Structure Definition:

#pragma pack(push,4)

typedef struct

{

charname[256];

chardim[64];

enum SigTypetype;

} t_c_pindescription;

typdef enum SigType

{ T_ANALOG = 1, T_BINARY = 2, T_OPTIONAL };

#pragma pack(pop)

The following is my C# Client  code:

public classProgram

{

[StructLayoutAttribute(LayoutKind.Sequential,Pack=1)]

publicstructt_c_pindescription

{

[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 256)]

publicstringpinname;

[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 64)]

public stringDimension;

public SigTypemType;

}

public enumSigType

 {

  T_ANALOG = 1,

  T_BINARY = 2,

  T_OPTIONAL = 4,

 }

      

[System.Runtime.InteropServices.DllImportAttribute("abc.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "moduleDescription",CharSet=CharSet.Ansi)]

publicstaticexternintmoduleDescription(intmodulnumber,StringBuildername,[Out]t_c_pindescription[] ppsainputs, [Out] t_c_pindescription[] ppsaoutputs, [Out] t_c_pindescription[] ppsaintern);

publicstaticvoidMain(string[] args)

{

t_c_pindescription[] inputdesarray =newt_c_pindescription[200];

t_c_pindescription[] outputdesarray =newt_c_pindescription[200];

t_c_pindescription[] interndesarray =newt _c_pindescription[200];

StringBuilder sb = newStringBuilder();

for(inti = 0; i < num; i++)

{

 moduleDescription(i, sb, inputdesarray,outputdesarray, interndesarray);

}

}

}

Here I am unable to get my structure array values i.e values inside inputdesarray, outputdesarray and interndesarray. Please help me.

          


Viewing all articles
Browse latest Browse all 31927

Trending Articles