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. Managed C++/CLI
  4. Error 1 error C2664 : 'cannot convert parameter 1 from 'gcroot<T>' to 'System::IO::Stream ^%' [modified]

Error 1 error C2664 : 'cannot convert parameter 1 from 'gcroot<T>' to 'System::IO::Stream ^%' [modified]

Scheduled Pinned Locked Moved Managed C++/CLI
helpcsharpc++
6 Posts 3 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.
  • K Offline
    K Offline
    KASR1
    wrote on last edited by
    #1

    I am using C# class library in C++ using C++/CLI mode. I have declared a class member as follows gcroot <> m_objTest; And the following call gives compilation error m_myInterface->GetResults(m_objTest); Error 1 error C2664 : 'cannot convert parameter 1 from 'gcroot<T>' to 'System::IO::Stream ^%' The following is the prototype of GetResults function in C# void GetResults(ref JobResults jobRes); Help me to solve this error.

    modified on Monday, June 28, 2010 12:35 AM

    L N 2 Replies Last reply
    0
    • K KASR1

      I am using C# class library in C++ using C++/CLI mode. I have declared a class member as follows gcroot <> m_objTest; And the following call gives compilation error m_myInterface->GetResults(m_objTest); Error 1 error C2664 : 'cannot convert parameter 1 from 'gcroot<T>' to 'System::IO::Stream ^%' The following is the prototype of GetResults function in C# void GetResults(ref JobResults jobRes); Help me to solve this error.

      modified on Monday, June 28, 2010 12:35 AM

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      A gcroot is not a System::IO::Stream ^. You need to convert your object into the correct type required by the function.

      It's time for a new signature.

      1 Reply Last reply
      0
      • K KASR1

        I am using C# class library in C++ using C++/CLI mode. I have declared a class member as follows gcroot <> m_objTest; And the following call gives compilation error m_myInterface->GetResults(m_objTest); Error 1 error C2664 : 'cannot convert parameter 1 from 'gcroot<T>' to 'System::IO::Stream ^%' The following is the prototype of GetResults function in C# void GetResults(ref JobResults jobRes); Help me to solve this error.

        modified on Monday, June 28, 2010 12:35 AM

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        Before passing it to the by-ref function, you need to use a temp variable. Example:

        ref class Derived : Base
        {
        String^ _s;
        public:
        Derived(String^ s):_s(s){}
        };

        void Foo(Derived^% derived)
        {
        derived = gcnew Derived("From Foo");
        }

        class Native
        {
        gcroot<Derived^> _derived;

        public:
        void Bar()
        {
        _derived = gcnew Derived("Before");
        Derived^ tmp = _derived;
        Foo(tmp);
        _derived = tmp;
        }
        };

        Regards, Nish


        Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application

        K 1 Reply Last reply
        0
        • N Nish Nishant

          Before passing it to the by-ref function, you need to use a temp variable. Example:

          ref class Derived : Base
          {
          String^ _s;
          public:
          Derived(String^ s):_s(s){}
          };

          void Foo(Derived^% derived)
          {
          derived = gcnew Derived("From Foo");
          }

          class Native
          {
          gcroot<Derived^> _derived;

          public:
          void Bar()
          {
          _derived = gcnew Derived("Before");
          Derived^ tmp = _derived;
          Foo(tmp);
          _derived = tmp;
          }
          };

          Regards, Nish


          Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application

          K Offline
          K Offline
          KASR1
          wrote on last edited by
          #4

          Yes Exactly i did the same. So there is no option to pass gcroot object as reference to other function?

          N 1 Reply Last reply
          0
          • K KASR1

            Yes Exactly i did the same. So there is no option to pass gcroot object as reference to other function?

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #5

            As far as I know, no. Remember that the by-ref language behavior is implemented at runtime by the CLR whereas the gcroot is an unmanaged wrapper class. So unless the callee is a C++/CLI method expecting a gcroot argument, what you want to do is quite impossible (in my opinion anyway).

            Regards, Nish


            Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application

            K 1 Reply Last reply
            0
            • N Nish Nishant

              As far as I know, no. Remember that the by-ref language behavior is implemented at runtime by the CLR whereas the gcroot is an unmanaged wrapper class. So unless the callee is a C++/CLI method expecting a gcroot argument, what you want to do is quite impossible (in my opinion anyway).

              Regards, Nish


              Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application

              K Offline
              K Offline
              KASR1
              wrote on last edited by
              #6

              Thanks for your information.

              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