Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem dealing with a function definition

Status
Not open for further replies.

NietzscheDisciple

Programmer
Oct 28, 2004
2
0
0
US
Hi,

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:

Code:
public Array Read(
int bufferStartingLocation,
Type returnedDataType,
LockFlag flag,
int[] ranks
);

My code has the following usage of the Read method.

Code:
MemBuffShort = (short[])(StreamCaptureBuffer.Read(StreamCapBuffReadPos, typeof(short), LockFlag.None, 50000));

where MemBuffShort = new short[100000];

In C++, the function prototype is:
Code:

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:
Code:

// 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);

CapBuffPara[] has been declared as a private variable and then instantiated in the Form1 constructor as follows:

Form1(void)
{
CapBuffPara = new int __gc[1];
CapBuffPara[0] = 5000;
InitializeComponent();
}

However, I get the following error message:

error C2440: '=' : cannot convert from 'System::Array __gc *' to 'int __gc[]'

1. The tooltip on CapBuffPara shows:
int (ProjName)::Form1::CapBuffPara __gc[]

2. The function definition requires the last argument to be int __gc[]

So I don't understand why the compiler says it cannot convert from System::Array __gc * to int __gc.

How do I solve this problem? What needs to be changed?

Thanks for your help!
 
CapBuffPara should be a pointer to a System::Array __gc. You can use the pointer like an array, it just can't be declared as one.
 
Hi Timmay, you're right...and I think I fixed it when I went over the code.

I forgot the typecast that was present in my C# code.

The line should read:

MemBuff = (System::Int32[])( StreamCapBuffer->Read(StreamCapBuffReadPos, __typeof(int), LockFlag::None, CapBuffPara));

It compiles ok now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top