COM Interop
-
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] -
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]Just guessing here: m_MasDsp.GetMasSysDataS(ref parArray, ref startTime, ref osInfo, ref sysName, ref prtNode); ..without the indexes
-
Just guessing here: m_MasDsp.GetMasSysDataS(ref parArray, ref startTime, ref osInfo, ref sysName, ref prtNode); ..without the indexes
-
Thanks for your reply! That doesn't work because of a compiler error: "Argument '1': cannot convert from 'ref int[]' to 'ref int'"
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);
-
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);
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.
-
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] -
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.
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?
-
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?
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!
-
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]I had to use SafeArrays as described in the msdn.