I am attempting to write a .NET wrapper in C# for an SDK that has been
supplied as a .LIB file and a .h header file. I have got most of the
functions to work but am really struggling with the functions that require a
structure to be passed to them. The function declaration in the .h file is
of the form:
SDCERR GetConfig(char *name, SDCConfig *cfg);
where SDCConfig is a structure defined in the .h file. I am not much of a C
(or C#) programmer but does the * in front of the cfg signify that the
structure has to be passed using the ref keyword (by reference)?
The other part I am having trouble with is the definition of the actual
structure itself. The .h definition is:
typedef struct _SDCConfig {
char configName[CONFIG_NAME_SZ];
char SSID[SSID_SZ];
int txPower;
....
....
CRYPT WEPKeys;
} SDCConfig;
(where CRYPT is another structure containing a char array). Whatever I seem
to try in the C# definition, I am getting a NotSupportedExc eption when
calling the function. I am attempting to use the MarshalAs keyword in front
of the char array definitions, which I have done successfully when passing
strings, but to be honest I don't really understand what I am doing! I also
have another structure containing DWORDs as well as char arrays that I don't
know what to do with. The code I am using is:
[StructLayout.(L ayoutKind.Seque ntial, CharSet = CharSet.Unicode )]
public struct SDCConfig
{
MarshalAs[UnmanagedType.L PArray, SizeConst=CONFI G_NAME_SZ];
public byte[] configName;
...
...
}
I have tried playing about with the UnmanagedType.L PArray, and passing
char[], string, and StringBuilder instead of the byte array, but always get
the NotSupportedExc eption. I have tried initialising the structure by
filling in the byte array. The call I am using is:
SDCConfig cfg = new SDCConfig(Confi gName);
SDCERR result = GetConfig(Name, ref cfg);
I am using the Compact Framework and VS.NET 2005 if that makes a
difference.
Any help would be appreciated. Thanks in advance.
Andy Baker
supplied as a .LIB file and a .h header file. I have got most of the
functions to work but am really struggling with the functions that require a
structure to be passed to them. The function declaration in the .h file is
of the form:
SDCERR GetConfig(char *name, SDCConfig *cfg);
where SDCConfig is a structure defined in the .h file. I am not much of a C
(or C#) programmer but does the * in front of the cfg signify that the
structure has to be passed using the ref keyword (by reference)?
The other part I am having trouble with is the definition of the actual
structure itself. The .h definition is:
typedef struct _SDCConfig {
char configName[CONFIG_NAME_SZ];
char SSID[SSID_SZ];
int txPower;
....
....
CRYPT WEPKeys;
} SDCConfig;
(where CRYPT is another structure containing a char array). Whatever I seem
to try in the C# definition, I am getting a NotSupportedExc eption when
calling the function. I am attempting to use the MarshalAs keyword in front
of the char array definitions, which I have done successfully when passing
strings, but to be honest I don't really understand what I am doing! I also
have another structure containing DWORDs as well as char arrays that I don't
know what to do with. The code I am using is:
[StructLayout.(L ayoutKind.Seque ntial, CharSet = CharSet.Unicode )]
public struct SDCConfig
{
MarshalAs[UnmanagedType.L PArray, SizeConst=CONFI G_NAME_SZ];
public byte[] configName;
...
...
}
I have tried playing about with the UnmanagedType.L PArray, and passing
char[], string, and StringBuilder instead of the byte array, but always get
the NotSupportedExc eption. I have tried initialising the structure by
filling in the byte array. The call I am using is:
SDCConfig cfg = new SDCConfig(Confi gName);
SDCERR result = GetConfig(Name, ref cfg);
I am using the Compact Framework and VS.NET 2005 if that makes a
difference.
Any help would be appreciated. Thanks in advance.
Andy Baker
Comment