J
John Smith
I wrote some code in C in a dll which I would like to call from C#.
However I'm stuck because of the strongly typed behavior of C# which makes
limitations.
Here are the prototypes for two functions which I have trouble mapping:
int _SetOption(int nOption, void *pSetting);
void *_GetDataField(int nType, int *npLength);
For the first function depending on the variable nOption it accepts either a
string, function pointer (for callbacks) or an integer.
In C you can just typecast anything to (void *) but unfortunatly it's not
that easy in C#.
For the 2nd function it can return either a unsigned char * array or a char
* zero terminated string depending on nType. Again in C you can just
typecast it to anything.
Any suggestions how to map my functions? The worst case scenario is to
create one prototype for each possible behavior for both functions. This is
tiredsome and errorprone to create 20+ prototypes for the same function.
Thanks in advance for any advice
-- John
However I'm stuck because of the strongly typed behavior of C# which makes
limitations.
Here are the prototypes for two functions which I have trouble mapping:
int _SetOption(int nOption, void *pSetting);
void *_GetDataField(int nType, int *npLength);
For the first function depending on the variable nOption it accepts either a
string, function pointer (for callbacks) or an integer.
In C you can just typecast anything to (void *) but unfortunatly it's not
that easy in C#.
For the 2nd function it can return either a unsigned char * array or a char
* zero terminated string depending on nType. Again in C you can just
typecast it to anything.
Any suggestions how to map my functions? The worst case scenario is to
create one prototype for each possible behavior for both functions. This is
tiredsome and errorprone to create 20+ prototypes for the same function.
Thanks in advance for any advice

-- John