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 2007

Tip: Looking for answers? Try searching our database.

Implement non-COM C++ interfaces in .NET C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Shishkin - 17 Jan 2007 23:56 GMT
Looking for help with non-COM C++ interfaces implementation. I can’t
find any reference on how to implement / use non-COM C++ interfaces in C#.

I have an application that uses COM interfaces from one of the Microsoft
services and have no problems using those. However, there are few
interfaces in this service defined as (C++ (not COM) interface)
regarding Microsoft documentation on this service API, also these
interfaces inherit the methods of the standard COM interface IUnknown
(same source).

Making story short, I can successfully call method that returns IntPtr
to the non-COM interface with reasonable pointer value, even
Marshal.QueryInterface works fine and returns proper pointer. My problem
is how to define C# wrapper for this type of interface, looks like
standard way that COM likes, does not work for me.

[ComVisible(false),
ComImport,
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("E561901F-03A5-4afe-86D0-72BAEECE7004")]
public interface IProviderNotifications
{
[PreserveSig()]
      uint OnLoad([MarshalAs(UnmanagedType.IUnknown)] object pCallback);

[PreserveSig()]
      uint OnUnload(int bForceUnload);
}

I tried “Marshal.GetObjectForIUnknown” on returned IntPtr, it just
throws an exception (No such interface) even without me trying to cast
it to specific type. I also tried “Marshal.PtrToStructure” and define my
wrapper class not as interface but as abstract class (blowup with
exception “Cannot create an abstract class”, reasonable).

I hope someone know anything about this issue, any help, suggestion,
hint greatly appreciated. I really stuck now.

Thanks.
mtv - 31 Jan 2007 20:35 GMT
Try this book: Essential Guide to Managed Extensions for C++. You can use "It
Just Works" (IJW) method to wrap your native C++ code w/ managed __gc class.
BTW, the name IJW is quite dump, but the method is nice.

MS does offer a 3-day training course in this topic. Course 2558, but you've
got to make sure instructor is good since there are not that many people
really know about this whole topic.

Good luck.

Signature

Your 2 cents are worth $milion$. Thanks.

> Looking for help with non-COM C++ interfaces implementation. I can’t
> find any reference on how to implement / use non-COM C++ interfaces in C#.
[quoted text clipped - 35 lines]
>
> Thanks.

Rate this thread:







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.