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

Tip: Looking for answers? Try searching our database.

returning VARIANT containing SAFEARRAY of bytes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bimish - 05 Oct 2005 14:39 GMT
I am working on a ATL COM project which will be used by both COM-based
clients and .NET clients.  One of the interface methods in the ATL project
returns a VARIANT.  Depending on the input to the method, the VARIANT may
contain a VT_BSTR, VT_I4, etc.  It also may return an array of bytes (
VT_ARRAY | VT_UI1 ).  For some reason, my COM-based clients (Visual Basic 6)
are quite happy receiving the array of bytes, but my .NET clients are
throwing a SafeArrayTypeMismatchException (Specified array was not of the
expected type).  The implementation looks something like the following.  Can
anyone see anything obvious I am doing wrong?

HRESULT CObject::GetData(VARIANT* value)
{
 // build the return array
 CComSafeArray<char> data;
 HRESULT hr = data.Create(10, 0);
 if (FAILED(hr)) return hr;

 ... code to populate array omitted ...

 // stuff the array into a VARIANT
 CComVariant returnValue;
 returnValue.vt = (VT_ARRAY | VT_UI1);
 returnValue.parray = data.Detach();
 return returnValue.Detach(value);
}

Thanks

Bimish
Bimish - 05 Oct 2005 14:57 GMT
Nervermind.  This is a type mismatch between char and BYTE.  The SAFEARRAY
contains chars, but the VARIANT says it contains BYTEs.  I changed the
CComSafeArray declaration to

CComSafeArray<BYTE> data;

Thanks

Bimish

>I am working on a ATL COM project which will be used by both COM-based
>clients and .NET clients.  One of the interface methods in the ATL project
[quoted text clipped - 25 lines]
>
> Bimish

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.