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#
  4. COM Interop

COM Interop

Scheduled Pinned Locked Moved C#
comcsharpdatabasedata-structures
9 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.
  • U Offline
    U Offline
    Ungi
    wrote on last edited by
    #1

    I have the following problem: I use an ocx that provides a method with following parameters (from documentation): GetMasSysDataS ( long parArray(4), String startTime, String osInfo, String sysName, String prtNode(2)) The COM interface is created as following: short GetMasSysDataS( long* parArray, BSTR* startTime, BSTR* osInfo, BSTR* sysName, BSTR* prtNode); I try to use this method in my C# application: int[] parArray = new int[4] { -1, -1, -1, -1 }; string startTime = ""; string osInfo = ""; string sysName = ""; string[] prtNode = new string[2] { "", "" }; // instance the wrapperclass m_MasDsp = new cominterop.MasDsp (); /* ... do some configurations ... */ // get the data m_MasDsp.GetMasSysDataS(ref parArray[0], ref startTime, ref osInfo, ref sysName, ref prtNode[0]); Almost all data is passed correctly except of the parameters in the array with an index greater than 0. The first element of the array is correct all other elements stay on initial value. Has anybody a tip what the problem could be? [edit]I forgot to post that I had no problems to call that method from a VB6 Application for testing purposes.[/edit]

    K U 3 Replies Last reply
    0
    • U Ungi

      I have the following problem: I use an ocx that provides a method with following parameters (from documentation): GetMasSysDataS ( long parArray(4), String startTime, String osInfo, String sysName, String prtNode(2)) The COM interface is created as following: short GetMasSysDataS( long* parArray, BSTR* startTime, BSTR* osInfo, BSTR* sysName, BSTR* prtNode); I try to use this method in my C# application: int[] parArray = new int[4] { -1, -1, -1, -1 }; string startTime = ""; string osInfo = ""; string sysName = ""; string[] prtNode = new string[2] { "", "" }; // instance the wrapperclass m_MasDsp = new cominterop.MasDsp (); /* ... do some configurations ... */ // get the data m_MasDsp.GetMasSysDataS(ref parArray[0], ref startTime, ref osInfo, ref sysName, ref prtNode[0]); Almost all data is passed correctly except of the parameters in the array with an index greater than 0. The first element of the array is correct all other elements stay on initial value. Has anybody a tip what the problem could be? [edit]I forgot to post that I had no problems to call that method from a VB6 Application for testing purposes.[/edit]

      K Offline
      K Offline
      killerslaytanic
      wrote on last edited by
      #2

      Just guessing here: m_MasDsp.GetMasSysDataS(ref parArray, ref startTime, ref osInfo, ref sysName, ref prtNode); ..without the indexes

      U 1 Reply Last reply
      0
      • K killerslaytanic

        Just guessing here: m_MasDsp.GetMasSysDataS(ref parArray, ref startTime, ref osInfo, ref sysName, ref prtNode); ..without the indexes

        U Offline
        U Offline
        Ungi
        wrote on last edited by
        #3

        Thanks for your reply! That doesn't work because of a compiler error: "Argument '1': cannot convert from 'ref int[]' to 'ref int'"

        K 1 Reply Last reply
        0
        • U Ungi

          Thanks for your reply! That doesn't work because of a compiler error: "Argument '1': cannot convert from 'ref int[]' to 'ref int'"

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

          Another guessing: also delete the ref for the arrays, (as the arrays vars are references themselves) m_MasDsp.GetMasSysDataS(parArray, ref startTime, ref osInfo, ref sysName, prtNode);

          U 1 Reply Last reply
          0
          • K killerslaytanic

            Another guessing: also delete the ref for the arrays, (as the arrays vars are references themselves) m_MasDsp.GetMasSysDataS(parArray, ref startTime, ref osInfo, ref sysName, prtNode);

            U Offline
            U Offline
            Ungi
            wrote on last edited by
            #5

            Hallo! If I do that the following message occurs: "Argument '1': cannot convert from 'int[]' to 'ref int'" I think I have already tried almost all combinations of parameter and the one I used seems to be the only one that works. I wrote a litte VB6-TestingApplication for the dll. There I passed the arrays in the same way as I did in C#. It is really strange.

            1 Reply Last reply
            0
            • U Ungi

              I have the following problem: I use an ocx that provides a method with following parameters (from documentation): GetMasSysDataS ( long parArray(4), String startTime, String osInfo, String sysName, String prtNode(2)) The COM interface is created as following: short GetMasSysDataS( long* parArray, BSTR* startTime, BSTR* osInfo, BSTR* sysName, BSTR* prtNode); I try to use this method in my C# application: int[] parArray = new int[4] { -1, -1, -1, -1 }; string startTime = ""; string osInfo = ""; string sysName = ""; string[] prtNode = new string[2] { "", "" }; // instance the wrapperclass m_MasDsp = new cominterop.MasDsp (); /* ... do some configurations ... */ // get the data m_MasDsp.GetMasSysDataS(ref parArray[0], ref startTime, ref osInfo, ref sysName, ref prtNode[0]); Almost all data is passed correctly except of the parameters in the array with an index greater than 0. The first element of the array is correct all other elements stay on initial value. Has anybody a tip what the problem could be? [edit]I forgot to post that I had no problems to call that method from a VB6 Application for testing purposes.[/edit]

              U Offline
              U Offline
              Ungi
              wrote on last edited by
              #6

              Could this be a boxing fault??? Gets "ref parArray[0]" boxed before it is passed to the COM-interface and so the other elements get no values.

              K 1 Reply Last reply
              0
              • U Ungi

                Could this be a boxing fault??? Gets "ref parArray[0]" boxed before it is passed to the COM-interface and so the other elements get no values.

                K Offline
                K Offline
                killerslaytanic
                wrote on last edited by
                #7

                Honestly i don´t know what the hell is going on...Definitively the old C has changed.... Sadly i can´t help you with that one...I´m still "cold" with some features. Maybe it is a bug but maybe we should study a little more...LOL:) If you find the solution could you post it here please?

                U 1 Reply Last reply
                0
                • K killerslaytanic

                  Honestly i don´t know what the hell is going on...Definitively the old C has changed.... Sadly i can´t help you with that one...I´m still "cold" with some features. Maybe it is a bug but maybe we should study a little more...LOL:) If you find the solution could you post it here please?

                  U Offline
                  U Offline
                  Ungi
                  wrote on last edited by
                  #8

                  Of course I will post if I have the solution. I really think that it is a boxing failure: I have an array with four elements. To call the method of the ocx I have pass a reference to the first element of the array. But this element is a TypeValue and no reference value. So it is boxed --> put into the heap. But only the first(!!) element!!! So the ocx gets a reference to that element and writes the data into it and also writes data into the next 3 elements. But the other 3 elements aren't in the heap. At the end of the call my first element gets unboxed back into the stack and it has the correct value but the other 3 haven't. Currently I try to pass through a SAFEARRAY. But there is a lot of studiing because I never used to work with MFC and ClassWizard and so on (only C/C++). But I think I am on the right way!

                  1 Reply Last reply
                  0
                  • U Ungi

                    I have the following problem: I use an ocx that provides a method with following parameters (from documentation): GetMasSysDataS ( long parArray(4), String startTime, String osInfo, String sysName, String prtNode(2)) The COM interface is created as following: short GetMasSysDataS( long* parArray, BSTR* startTime, BSTR* osInfo, BSTR* sysName, BSTR* prtNode); I try to use this method in my C# application: int[] parArray = new int[4] { -1, -1, -1, -1 }; string startTime = ""; string osInfo = ""; string sysName = ""; string[] prtNode = new string[2] { "", "" }; // instance the wrapperclass m_MasDsp = new cominterop.MasDsp (); /* ... do some configurations ... */ // get the data m_MasDsp.GetMasSysDataS(ref parArray[0], ref startTime, ref osInfo, ref sysName, ref prtNode[0]); Almost all data is passed correctly except of the parameters in the array with an index greater than 0. The first element of the array is correct all other elements stay on initial value. Has anybody a tip what the problem could be? [edit]I forgot to post that I had no problems to call that method from a VB6 Application for testing purposes.[/edit]

                    U Offline
                    U Offline
                    Ungi
                    wrote on last edited by
                    #9

                    I had to use SafeArrays as described in the msdn.

                    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