473,387 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

A caveat for all of you who need to use C++ COM objects that return VARIANT* (containing SAFEARRAYs)...

WTH
....and you get safe array type mismatch exceptions from the marshaller.

I have a C++ COM object (thank God I could find the source) that was
declared properly in the IDL for [out, retval] and requiring a VARIANT*,
everytime I tried to use this object from C# the marshaller would throw up
marshalling the return value. Now, I should mention that this COM object
works great in when used by C++ code which has to marshall the data as well.

I googled my rear off learning all kinds of interesting stuff which I hope
I'll never have to use in real life (editing CIL files the recompiling them
in order to trick the runtime marshaller), none of it worked.

I had, or course, already checked to see how the SAFEARRAYs were passed back
and, being an old time COM developer, I didn't notice anything unusual.
VT_ARRAY were declared with the appropriate type info. Bounds were set
properly, et cetera.

I checked for VTDISPATCH, I tried important the type lib with /sysarray, all
to no effect.

Basically I tried everything I could google.

Then I noticed that the memory for the array was allocated in a relatively
old fashioned manner in the C++ COM object. It didn't use SafeArrayCreate
(sp?) it did a system allocation like you used to always do in the earlier
days of automation and then setup the array (properly) with elements and
bounds et al.

Changing the data allocation to use SafeArrayCreate solved the C#
marshalling issue for me entirely.

I just wanted to put this out there so that in 3 years when I run into this
again and forget how I solved the problem I can google myself ;).

WTH

--
"I will always remain a fan of Liverpool Football Club. I'll come here again
as a friend and a fan and I will cheer the boys on." - Gérard Houllier
Jul 29 '06 #1
0 1213

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jeff Wagner | last post by:
I am in the process of learning Python (obsessively so). I've been through a few tutorials and read a Python book that was lent to me. I am now trying to put what I've learned to use by rewriting...
2
by: Thilanga | last post by:
Hi, I want to access a VARIANT array returned by a method in VC++, that is supposed to be a long array. Can anybody suggest me a way of access this array and get the values in it. ...
106
by: xtra | last post by:
Hi Folk I have about 1000 procedures in my project. Many, many of them are along the lines of function myfuntion () as boolean on error goto er '- Dim Dbs as dao.database Dim Rst as...
3
by: Gabe Covert | last post by:
I'm a new C# developer, and am developing an application which will utilize a COM library from a third party. I have two following SDK calls from the 3rd-party SDK which I can't get to work under...
0
by: mseeger | last post by:
My concrete problem is this (it is a bit special, but there may be other instances of it): I'd like to create a class for vectors (say: Vector), exporting math. methods, say v.foo(...). I'd like...
0
by: MikalE | last post by:
I’m using a third-party ActicveX component that has the following description for one of its events: They mean by this that LocationType is an array of VARIANTS (containing enumeration) When...
10
by: CuTe_Engineer | last post by:
hii, i have cs assignment i tried to solve it but i still have many errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote the prog. i just wanna you to show me my mistakes ...
2
by: Bjoern | last post by:
Hi I have a COM object which fires an event where I have to pass an array of SHORTs as a parameter to the listening object. The array of SHORTs is encapsulated in a the CComSafeArray-class and...
2
by: Coxmg | last post by:
Here is the code, ACCESS 2007: Hello, I have a dialog box that opens on a form that lets the user browse files. I simply want to limit it to Folders, how can I do that? Need ASAP. Thanks. ACCESS...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.