Re: exporting a struct with an array from a C++ dll to be accessed in C#
- From: AM <abhi.menon@xxxxxxxxx>
- Date: 19 Apr 2007 08:41:32 -0700
In that case what should my C# definition look like for the
corresponding C++ definition mentioned below?
C++ struct
struct validationResult
{
int micDataValid; //validity of the microphone data
int rWaveValid; //validity of the r Wave
int signalStatusArray[4]; //validity of each of the channel
data
};
Thanks
On Apr 19, 10:31 am, "Ben Voigt" <r...@xxxxxxxxxxxxx> wrote:
"AM" <abhi.me...@xxxxxxxxx> wrote in message
news:1176921541.639424.294870@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I guess i did not copy my code correctly.
Here is what my C# struct looks like
public struct validationResult
{
public int rWaveValid; //validity of the r Wave
public int[] signalStatusArray; //validity of each of the
//channel data
};
Are you suggesting that the the error is caused by my array definition
in C# is dynamic (because of the []), while my C++ array is of size 4?
I am suggesting looking at the documentation for C# fixed-size buffers which
is here:http://msdn2.microsoft.com/en-us/library/zycewsya(VS.80).aspx
A dynamic (.NET) array carries additional stuff with it like length.
Additionally, since .NET arrays are ref class, only a pointer is stored in
the structure. This is totally different from the layout used by the C++
structure definition you gave.
On Apr 18, 2:01 pm, "Ben Voigt" <r...@xxxxxxxxxxxxx> wrote:
"AM" <abhi.me...@xxxxxxxxx> wrote in message
news:1176913299.669034.41320@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,
I have a C++ Dll that has a function that is being exported as
shown below
extern "C" __declspec(dllexport) validationResult __stdcall
_validateData(double dataToMat[], int time);
A structure is defined in the header(.h file) as shown below
struct validationResult
{
int rWaveValid; //validity of the WAVE
int signalStatusArray[4]; //validity of each of the channel data -
'causing the problems'
};
I need to call the above method from C# in where i have the following
structure defined
public struct validationResult
{
public int micDataValid; //validity of the microphone data
magically appeared?
public int rWaveValid; //validity of the r Wave
public int[] signalStatusArray; //validity of each of the
channel data
No, that doesn't match. A dynamically resizeable array is not the same
as
an inline array of size 4. Look for the 'fixed' keyword in the C# help.
};
And my function call is as shown
validationResult res = new validationResult();
res.signalStatusArray = new int[4];
res = _validateData(dataToMat, 2);
When the last line is reached i get an exception that says"Method's
type signature is not PInvoke compatible"
What am I doing wrong.
I know the issue is at the array inside the struct, as when I remove
the array from the C++ struct and the C# struct I get the right
response.
Thanks in Advance.
abhi M
.
- Follow-Ups:
- References:
- exporting a struct with an array from a C++ dll to be accessed in C#
- From: AM
- Re: exporting a struct with an array from a C++ dll to be accessed in C#
- From: Ben Voigt
- Re: exporting a struct with an array from a C++ dll to be accessed in C#
- From: AM
- Re: exporting a struct with an array from a C++ dll to be accessed in C#
- From: Ben Voigt
- exporting a struct with an array from a C++ dll to be accessed in C#
- Prev by Date: Re: TCP/IP comms problems between WinXP and DOS
- Next by Date: Re: Exporting C++ classes as ordinals (via a def file)
- Previous by thread: Re: exporting a struct with an array from a C++ dll to be accessed in C#
- Next by thread: Re: exporting a struct with an array from a C++ dll to be accessed in C#
- Index(es):
Relevant Pages
|