Problem dealing with a function definition
-
I'm trying to port some code I wrote using DirectSound in C# to Visual C++ (managed). I've got most of it done except for this problem I'm stuck at. I understand that this is a newbie question, so please be gentle The function I'm having a problem with is CaptureBufferObject->Read(arguments) in C++. In C#, the function protoype is:
public Array Read(
int bufferStartingLocation,
Type returnedDataType,
LockFlag flag,
int[] ranks
);My code has the following usage of the Read method.
MemBuffShort = (short[])(StreamCaptureBuffer.Read(StreamCapBuffReadPos, typeof(short), LockFlag.None, 50000));
where MemBuffShort = new short[100000]; In C++, the function prototype is:
public: Array* Read(
int bufferStartingLocation,
Type *returnedDataType,
LockFlag flag,
int ranks __gc[]
);My problem is with the last parameter: int ranks __gc[] I tried the following:
// With the variable declarations
static System::Int32 CapBuffPara[] = new System::Int32[] { 50000 };// Calling the Read method
MemBuff = StreamCapBuffer->Read(StreamCapBuffReadPos, __typeof(int), LockFlag::None, CapBuffPara);However, I get the following error message:
error C2440: '=' : cannot convert from 'System::Array __gc *' to 'int __gc[]'
How do I solve this problem? What needs to be changed? Thanks for your help!
-
I'm trying to port some code I wrote using DirectSound in C# to Visual C++ (managed). I've got most of it done except for this problem I'm stuck at. I understand that this is a newbie question, so please be gentle The function I'm having a problem with is CaptureBufferObject->Read(arguments) in C++. In C#, the function protoype is:
public Array Read(
int bufferStartingLocation,
Type returnedDataType,
LockFlag flag,
int[] ranks
);My code has the following usage of the Read method.
MemBuffShort = (short[])(StreamCaptureBuffer.Read(StreamCapBuffReadPos, typeof(short), LockFlag.None, 50000));
where MemBuffShort = new short[100000]; In C++, the function prototype is:
public: Array* Read(
int bufferStartingLocation,
Type *returnedDataType,
LockFlag flag,
int ranks __gc[]
);My problem is with the last parameter: int ranks __gc[] I tried the following:
// With the variable declarations
static System::Int32 CapBuffPara[] = new System::Int32[] { 50000 };// Calling the Read method
MemBuff = StreamCapBuffer->Read(StreamCapBuffReadPos, __typeof(int), LockFlag::None, CapBuffPara);However, I get the following error message:
error C2440: '=' : cannot convert from 'System::Array __gc *' to 'int __gc[]'
How do I solve this problem? What needs to be changed? Thanks for your help!
Well, since no one is going to tackle this :eek: extremely hard :eek: problem, here is the answer. Instead of the line int rank __gc[], try either int rank[] or int *rank. Bottom line, the C# line "int[] rank" defines an array of integers. The line "int rank __gc[]" wants to recast __gc[] from the class System::Array to an int array, and it won't work. Either "int rank[]" or "int *rank" define an array of integers. Geez, people, at least pretend to read the books or understand what the definitions of things are.
-
I'm trying to port some code I wrote using DirectSound in C# to Visual C++ (managed). I've got most of it done except for this problem I'm stuck at. I understand that this is a newbie question, so please be gentle The function I'm having a problem with is CaptureBufferObject->Read(arguments) in C++. In C#, the function protoype is:
public Array Read(
int bufferStartingLocation,
Type returnedDataType,
LockFlag flag,
int[] ranks
);My code has the following usage of the Read method.
MemBuffShort = (short[])(StreamCaptureBuffer.Read(StreamCapBuffReadPos, typeof(short), LockFlag.None, 50000));
where MemBuffShort = new short[100000]; In C++, the function prototype is:
public: Array* Read(
int bufferStartingLocation,
Type *returnedDataType,
LockFlag flag,
int ranks __gc[]
);My problem is with the last parameter: int ranks __gc[] I tried the following:
// With the variable declarations
static System::Int32 CapBuffPara[] = new System::Int32[] { 50000 };// Calling the Read method
MemBuff = StreamCapBuffer->Read(StreamCapBuffReadPos, __typeof(int), LockFlag::None, CapBuffPara);However, I get the following error message:
error C2440: '=' : cannot convert from 'System::Array __gc *' to 'int __gc[]'
How do I solve this problem? What needs to be changed? Thanks for your help!
Hey Anonymous... thanks for the reply! I know that this is a very elementary problem, but I'm new to programming in C++ and learning. I figured out the mistake I was making... I forgot the (System::Int32[]) typecast for MemBuff.
MemBuff = (System::Int32)(StreamCapBuffer->Read(StreamCapBuffReadPos, __typeof(int), LockFlag::None, CapBuffPara));
-
Well, since no one is going to tackle this :eek: extremely hard :eek: problem, here is the answer. Instead of the line int rank __gc[], try either int rank[] or int *rank. Bottom line, the C# line "int[] rank" defines an array of integers. The line "int rank __gc[]" wants to recast __gc[] from the class System::Array to an int array, and it won't work. Either "int rank[]" or "int *rank" define an array of integers. Geez, people, at least pretend to read the books or understand what the definitions of things are.
The function definition (or should I call it "protoype") was specified in the DirectX SDK, so I can't change it. In C#, the argument reuqired was just an integer. In the C++ implementation, it requires an array of a maximum of 3 elements.
-
The function definition (or should I call it "protoype") was specified in the DirectX SDK, so I can't change it. In C#, the argument reuqired was just an integer. In the C++ implementation, it requires an array of a maximum of 3 elements.
NietzcheDisciple - Well, it still goes back to the original solution that I was mentioning, with a little modification. __gc is an Evil Empire class of dynamic arrays, so you'll need to go to this URL to look at them : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmex/html/vclrf__gc.asp[^] Good luck with it.