Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem dealing with a function definition

Problem dealing with a function definition

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++csharpdata-structures
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NietzscheDisciple
    wrote on last edited by
    #1

    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!

    A N 2 Replies Last reply
    0
    • N NietzscheDisciple

      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!

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      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.

      N 1 Reply Last reply
      0
      • N NietzscheDisciple

        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!

        N Offline
        N Offline
        NietzscheDisciple
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • A Anonymous

          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.

          N Offline
          N Offline
          NietzscheDisciple
          wrote on last edited by
          #4

          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.

          A 1 Reply Last reply
          0
          • N NietzscheDisciple

            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.

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups