.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

COM Interop, Marshal C# IEnumerator->Native C++ IEnumVARIANT?

Posted By:      Posted Date: October 27, 2010    Points: 0   Category :.NET Framework

Hi folks,

I have a C# Windows Service which hosts a COM class whose client is C++ native code. On one method of the interface, there is the potential for a lot of data to be returned. Internally, the method is using an ArrayList of structs. The method has an [out] parameter typed as IEnumerator. In the method, I assign ArrayList.GetEnumerator() to this out parameter. The Type library export is getting it right; it is typing the out parameter as IEnumVARIANT, as expected.

However, on the client side, when I try to call Next() on the IEnumVARIANT interface pointer, I get an E_INVALIDARG HRESULT. Since the arguments to Next() are of the correct types, I'm at a loss as to what the problem is, and am thinking I'm doing something wrong on the Host side. Can anyone help me out here?

Many thanks!

Regards, D. T. Doutel

View Complete Post

More Related Resource Links

.NET - native interop: how do I pass a .NET form to a native PROPSHEETPAGE



I'm writing a Shell property sheet extension in .NET 4. It requires a PROPSHEETPAGE object. When I construct a PROPSHEETPAGE object in .NET, how do I set its pszTemplate field with a .NET form?

Marshal a C# struct to native C++


Platform is WS 2008 RC2, VS 2010.

I have what I think should be a pretty straightforward marshalling situation, but it just isn't working as expected.

Native Code:

#pragma pack(push, 8)
struct Handle
unsigned long Type;
void* Value;
void* Owner;
#pragma pack(pop)

__declspec(dllexport) Handle __cdecl CreateStyleProvider(const wchar_t* provider);
__declspec(dllexport) Handle __cdecl CreateOutputGroup(long ordinal, Handle style);

The Handle struct is really just opaque data that gets passed around.

C# code:

[StructLayout(LayoutKind.Sequential, Pack=8)]

COM Interop in C# 4.0

Let's take a bit of a recap of how far we've come. We've chatted about dynamic binding in C# and how that all plays in with the DLR, and about named and optional arguments and how they change the way methods are bound. The only other major piece in C# 4.0 is this notion of COM interop. We chatted about how dynamic really is a gateway to interop with different object models and languages (ie interacting with dynamic languages, dynamic object models, javascript objects, HTML DOM etc), but in C# 4.0, we want to go a bit further and provide you a few more tools to help make your interop life much easier.

Excel Interop Save as



I want to Save excel workbook using Excel interop in 97-2003 format. Currently I have Office 2007 installed on my machine.

below is the code I am using.

_book.SaveAs("New.xls", Excel.XlFileFormat.xlWorkbookDefault, Missing.Value, Missing.Value, false, false, Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

The solution is little urgent.


.NET Interop: Automate Acceptance Testing With IronRuby


Acceptance testing verifies that the system under development meets the customer's requirements. Learn the benefits here.

Ben Hall

MSDN Magazine March 2009

.NET Interop: Getting Started With IronRuby And RSpec, Part 1


See how IronRuby lets you employ the straightforward Ruby language to create acceptance tests that interoperate with .NET-compliant code.

Ben Hall

MSDN Magazine February 2009

CLR Inside Out: Best Practices For Managed And Native Code Interoperability


There are many factors to consider when building your app with both managed and native code. Find out how to employ interop and how to choose the interop that's right for you.

Jesse Kaplan

MSDN Magazine January 2009

Visual Studio OBA Tools: Simplify OBA Development With Interop API Extensions


To introduce you to VSTO Power Tools Office interop API extensions, we'll walk through the development of an application that automates Outlook, Excel, and Word.

Andrew Whitechapel, Phillip Hoff, and Vladimir Morozov

MSDN Magazine December 2008

GUI Library: Bring the Simplicity of Windows Forms to Native Apps


In this article, author John Torjo presents a guide to his C++ GUI library called eGUI++ and explains how it makes user interface programming easier.

John Torjo

MSDN Magazine June 2008

WinUnit: Simplified Unit Testing for Native C++ Applications


Maria Blees introduces WinUnit, a handy new unit testing tool for native C++ projects.

Maria Blees

MSDN Magazine February 2008

Interop: Connect To Mainframe Apps With BizTalk Adapters and .NET


If you have a significant investment in legacy COBOL applications running on mainframes, you need the BizTalk Adapters for Host Integration Server .

Bashar "Bash" Badawi

MSDN Magazine December 2007

XmlLite: A Small And Fast XML Parser For Native C++


XmlLite provides a high-performance, low-overhead XML reader and writer geared for applications written in native C++. Learn more here.

Kenny Kerr

MSDN Magazine April 2007

Netting C++: Mapping Native C++ to the Common Type System


This month Stanley Lippman begins translating the Text Query Language Query class hierarchy from C++ to the .NET Common Type System.

Stanley B. Lippman

MSDN Magazine February 2007

CLR Inside Out: Introduction to COM Interop


The CLR allows seamless interactions between Microsoft .NET applications and COM. But how, exactly? The CLR team knows.

Thottam R. Sriram

MSDN Magazine January 2007

Wrappers: Use Our ManWrap Library to Get the Best of .NET in Native C++ Code


By now you're probably used to reaching into the .NET Framework using Managed Extensions with your C++ code. But what do you do if you have legacy apps that use older versions of the compiler, or if you want to avoid some of the CLR requirements? Well, you can wrap Framework classes in a native way so you can use them in any C++/MFC app without /clr. Paul DiLascia shows you how.

Paul DiLascia

MSDN Magazine April 2005

Interop: Get Seamless .NET Exception Logging From COM Clients Without Modifying Your Code


Using .NET objects from ASP can help you gain experience with the .NET Framework before migrating to ASP.NET. Your ASP pages will make use of the new .NET components through COM-callable wrappers (CCW). But how will you handle exceptions? This article fills you in.

Matt Adamson

MSDN Magazine January 2005

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend