.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

.NET Interop and TR1 shared_ptr

Posted By:      Posted Date: August 28, 2010    Points: 0   Category :.NET Framework
Is it possible to marshal a shared_ptr from unmanaged C++ code into C#? I have a function in C++ (exposed through C bindings) that will allocate a new MyObject and return a pointer to it via a shared_ptr. In C++ I can call the function: MyObjHandle* ref = NULL:GetMyObject(&ref); // double ptr... where MyObjHandle is defined: typedef struct obj_t {   shared_ptr<MyObject> objPtr;} MyObjHandle ; How would I PInvoke the call to GetMyObject from C#? I did the obvious of just defining the structure MyObjectHandle pretty much as is in C# expcept I defined the member objPtr as an IntPtr. That failed miserably with a AccessViolationException error. Tried a couple other PInvoke variations which also failed. I can't seem to find any interop samples with shared_ptr and C#. Any help appreciated... Is this even doable? I may be able to simply not expose that shared_ptr across to my unmanaged code but still it bugs me that I can't do it.

View Complete Post

More Related Resource Links

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

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

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

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

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

.NET Remoting: Create a Custom Marshaling Implementation Using .NET Remoting and COM Interop


The .NET Framework offers several methods for customizing the presentation of native .NET and COM object types. One such technique, custom marshaling, refers to the notion of specializing object type presentations. There are times, like when a legacy COM component needs to implement a new interface or when you need to make calls across process or machine boundaries, when custom marshaling saves the day. Elements of COM Interop permit the customizing of COM types while .NET Remoting offers the developer the ability to tailor native .NET types. This article examines these techniques.

Jim Sievert

MSDN Magazine September 2003

DCOM Interop: Generate Custom Managed C++ Wrappers for Easier COM Interoperation Using DCOMSuds


Now that you're writing managed code, you'll certainly want to use your existing COM components, but you can't simply call them directly. Instead, you have to wrap the COM component in a runtime-callable wrapper that acts as a proxy between the component and your managed code. While the CLR provides wrapper classes for this purpose, there will be times when you'll want custom objects to wrap your COM components. One way to get the low-level access you need to precisely control resource cleanup, pass security information, and get access to CLR features is to write your own wrapper class in managed C++. This article shows you how.

Vishwas Lele

MSDN Magazine August 2003

.NET Interop: Get Ready for Microsoft .NET by Using Wrappers to Interact with COM-based Applications


Very soon, the development of Microsoft .NET applications will require interaction between those apps and existing COM components on both the client and the server. The .NET Framework has made provisions for this interaction by implementing various wrappers for COM objects to allow exposure of their properties and methods to .NET components. These wrappers will make it easy to make the connection between COM and .NET. After discussing wrappers, this article discusses other ways for .NET components to take part in COM+ transactions. To top off the tutorial on the interoperation of COM and .NET, the article discusses how ActiveX containers can host .NET controls, and how .NET containers can host ActiveX controls.

David S. Platt

MSDN Magazine August 2001

How to use Microsoft.office interop.word in website

Hi, I have a page which creates a word doc from templet string location = Server.MapPath("~/temp/" + filename); Application app = new Application(); Document doc = app.Documents.Add(location); if(doc != null) { //Some code here } it works fine when i run from visual studio, but when i deploy it as a website in local IIS, its not working.I gave the permissions needed to access the folders in the website. What should i do to make it work. Thanks

Some WIF interop gotchas

WIF is an excellent framework that allows you to develop an STS in just a few minutes if you know exactly what you are doing of course :). In my role as consultant and architect in Tellago, I went through several projects in which some level of customization was required at wire level to accomplish some interoperability between a STS built with WIF and existing federation solutions like ADFS 1.x and OpenSSO. The idea of this post is to show some of extensibility points that you will find in WIF to customize the WS-Trust messages, and issued tokens. 1. Making WIF to speak WS-Trust Feb 2005 WIF uses by default WS-Trust 1.3, which means that all the generated WS-Trust messages will use that spec unless you specify a different one. ADFS 1.x and OpenSSO both uses WS-Trust Feb 2005 (http://schemas.xmlsoap.org/ws/2005/02/trust) for the passive profile to support single sign on over the web. Therefore, if you want to generate WS-Trust messages that follow that spec version in your WIF passive STS, you need to modify a little bit the code you use for processing the RST messages. class FederatedPassiveSecurityTokenServiceOperations{ public static void ProcessRequest(HttpRequest request, IPrincipal principal, SecurityTokenService sts, HttpResponse response, WSFederationSerializer federationSerializer); public static SignInResponseMessage ProcessSignInRequest(

saving docx as pdf with Microsoft.Office.Interop.Word in sharepoint

Hi!Im trying to export my docx file to PDF with Microsoft.Office.Interop.Word but im stuck. Anyone with some great ideas that could save my day.The code that im running is working fine localy but i can´t get it to work in sharepoint.The most commin exception is file not found (the same path is working fine localy)...Pls give me a hint!

64-bit ActiveX Interop Problem

Our sister company wrote an ActiveX component for interfacing to a device that they(we) sell.  I have developed a VS2008 C# interface to the OCX by placing their COM object on a windows form then communicating through the generated interop.  But this is not working when I try to run the application on Win7 64-bit.  When I try to create the form which in turn loads the OCX, I get the following error: COMException was caught.  Class not registered (Exception from HRESULT:0x80040154 (REGDB_E_CLASSNOTREG)) The problem is not that the component is not registered.  I can see that the OCX is properly registered in the registry.  If I run their application it works fine with the registered OCX. I am able to debug the OCX.  I can see the constructor called on a 32-bit OS.  But the constructor is never called on a 64-bit OS.  There appears to be something wrong inside of the AxInterop.  I also tried regenerating the AxInterop in the development system running on a 64-bit OS.  I deleted and readded the component from the form.  But this did not change the problem. I am now at a complete loss as to where to look next.

COM Interop and propput/propputref

Hi everyone ! I want to create a .NET object that supports the following COM interface (IDL declarations) - I MUST insure binary compatibility here : interface IMyInterface { [id(0x000000ff), propputref] HRESULT SomeProperty([in] IDispatch* pvar); [id(0x000000ff), propput] HRESULT SomeProperty([in] VARIANT pvar); [id(0x000000ff), propget] HRESULT SomeProperty([out, retval] VARIANT* pvar); } I try different solutions, but none of them solves my problem... [ComVisible(true)] [Guid("2E913C9C-3C27-49b9-B239-BD026CC04DCE")] public interface IPutGet { [DispId(0xff)] object SomeProperty { [param: In, MarshalAs(UnmanagedType.Struct)] [DispId(0xff)] set; [DispId(0xff)] get; } } [ComVisible(true)] [Guid("0878F7D5-90E8-4729-89D4-66011F9DFEE4")] public interface IPropPutGet { [DispId(0xff)] object SomeProperty { [param: In, MarshalAs(UnmanagedType.IDispatch)] [DispId(0xff)] set; [DispId(0xff)] get; } } which gives the following in the generated TLB : [ odl, uuid(2E913C9C-3C27-49B9-B239-BD026CC04DCE), version(1.0), dual, oleautomation, custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "ComTests.IPutGet") ] interface IPutGet : IDispatch { [id(0x000000ff), propputref] HRESULT SomeProperty([in] VARIAN
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