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 / January 2005

Tip: Looking for answers? Try searching our database.

Marshalling Array In/Out C++ COM Control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
KidO - 09 Nov 2004 03:07 GMT
I have been researching this problem for some time, and I am hoping someone
here can help.  I have more detailed code examples in a previous post
"Problem using ocx in VS.Net".

The COM obejct (OCX) I am trying to use has a method that accepts an array
and a size as input.

bool SimpleMethod(float* array, long* size)

When I use aximp on the control, it generates the wrapper dll, which using
ildasm shows the method as Simple Method(float32& array, int32& size)

When executed, the array is dimensioned to a max size, and the size is set.  
The method fills the pre-created array, and the size reports the number of
actual elements in the array.

I have been pulling my hair out on this one.  I have tried a number of
different changes in the wrapper with no luck.  Any help is greatly
appreciated.

Thanks in advance...
Mattias Sj?gren - 13 Nov 2004 01:17 GMT
You don't clearly state what the problem is, but I assume it's the
fact that the array parameter appears as a single ref parameter
instead of an array in managed code. If so, tyou can find the solution
at

http://msdn.microsoft.com/library/en-us/cpguide/html/cpconeditinginteropassembly.asp

in the exction "Conformant C-Style Arrays". Just make sure you specify
the [out] attribute as well since you're working with output
parameters.

Mattias

Signature

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

KidO - 17 Nov 2004 14:54 GMT
Mattias,

Thank you for your response, and I hope you may still be watching this thread.

I have previously tried the code in the link you recommended, and have
created a number of variations, including fixing a pointer to the array,
using Marshal.AllocCoTaskMem to allocate memory for the array, etc.

When using the method described in the link  
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconeditinginteropassembly.asp
the method call fails and a System.Runtime.InteropServices.COMException
occurs in mscorlib.dll, with the Additional information: Type Mismatch.

When the method of the OCX returns succesfully (no error), only the first
value in the array is passed back.  Even with the untouched interop assembly
generated by aximp, this is the case, although I can not use an array larger
than 4 items.

Using OLEView, the the method looks like:

VARIANT_BOOL DetectCode(long* codeArray, short* arraySize)

The orginal IL of the interop assembly generated by aximp looks like:

instance bool DetectCode(int32& codeArray, int16& arraySize) runtime managed
preservesig internalcall

When the method is called, codeArray is intialized, and contains all 0's.  
arraySize is the number of elements in codeArray.  If the method call is
succesful, it returns true, and codeArray contains a number of values up to
the size set in arraysize, and arraySize is the actual (useful) number of
elements in the array.

Thanks in advance for your help.

John

"Mattias Sjögren" wrote:

> You don't clearly state what the problem is, but I assume it's the
> fact that the array parameter appears as a single ref parameter
[quoted text clipped - 8 lines]
>
> Mattias
MarkM - 13 Jan 2005 20:45 GMT
I am having this exact problem. Did you ever solve it? What is the solution?

Mark

> Mattias,
>
[quoted text clipped - 47 lines]
> >
> > Mattias

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.