Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2006

Tip: Looking for answers? Try searching our database.

parsing arrays to COM

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ms - 21 Sep 2006 16:21 GMT
Hello,
i want to use a COM-function who is declared like the following
(IDL)

HRESULT SetPlcData (
   [in] BSTR               bstrPlcString,
   [in] SAFEARRAY(long)    * lPlcMarkers,
   [in] SAFEARRAY(long)    * lPlcDWords );

Since i add a reference to my Studio 2003 Project (c#) to the dll-file
who contains this function the declaration changed to

void SetPlcData(System.String bstrPlcString, System.Array lPlcMarkers,
System.Array lPlcDWords)

That's how the Studio interpret this IDL code; fine.
But when i invoke the function later like this

                Array arrPlcMarkers = null;
                Array arrPlcWords = null;
                               //...fill the arrays with
split-function...

                objPlc.SetPlcData(sParams[2], ref arrPlcMarkers, ref arrPlcWords);

i get the error - "specified array was not of the expected type" !!!
If i invoke it with two long-arrays i can't compile because the
compiler wants two System.Array-types.
I also tried to use a delegate to marshal the parameters - the result
is the same error.

private delegate void MyDelegate(string str,
[MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VarEnum.VT_I4)]
ref System.Array a, [MarshalAs(UnmanagedType.SafeArray,
SafeArraySubType=VarEnum.VT_I4)] ref System.Array b);

hope you can help me
Mattias Sjögren - 21 Sep 2006 21:32 GMT
>                Array arrPlcMarkers = null;
>                Array arrPlcWords = null;
>                                //...fill the arrays with
>split-function...

Split function? Sounds like you're dealing with strings. Did you try
something like

Array arrPlcMarkers = new int[] {1, 2, 3};
Array arrPlcWords = new int[] {4, 5, 6};

Another option is to create a new interop assembly with TlbImp so you
can get strongly typed array parameters.

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

ms - 22 Sep 2006 09:35 GMT
I tried it with int's and long's - no way to get i work.
I also tried it with my delegate.

private delegate void MyDelegate(string str,
[MarshalAs(UnmanagedType.LPArray)] ref System.Array a,
[MarshalAs(UnmanagedType.LPArray)] ref System.Array b);

Always the same error!

> Another option is to create a new interop assembly with TlbImp so you
> can get strongly typed array parameters.
---> ??? How can i do this? I don't have the code - it's from another
company.

Thanks
Mattias Sjögren - 25 Sep 2006 20:32 GMT
>> Another option is to create a new interop assembly with TlbImp so you
>> can get strongly typed array parameters.
> ---> ??? How can i do this? I don't have the code - it's from another
>company.

Run Tlbimp.exe from the command line. You don't need the source code,
just the COM library.

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

ms - 29 Sep 2006 10:48 GMT
That works. Thank you very much for supporting me.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.