Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:19:07+00:00 2026-06-12T00:19:07+00:00

I am trying to use InteropServices.Marshal.QueryInterface to convert a COM object to a specific

  • 0

I am trying to use InteropServices.Marshal.QueryInterface to convert a COM object to a specific type in C#, but I am having trouble to pass in the first and last parameters.

I am assuming that IntPtr is a reference, but I cannot get IntPtr to reference my classes to use QueryInterface due to syntax errors.

Of course, the code that is shown below does not have the correct syntax, but it gives you an idea of what I am trying to do.

set
{
    ClassA a;
    Guid guid = Guid.Parse("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
    System.Runtime.InteropServices.Marshal.QueryInterface(ref value, 
        ref guid, out a);
}

EDIT:

[ComVisible(true), Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")]
public ClassA : COMInterface{ ... }

ClassA is the C# class, and COMInterface is the COM interface. It is the only class that implements COMInterface. value in the set scope is the reference to the COM Interface, COMInterface

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:19:09+00:00Added an answer on June 12, 2026 at 12:19 am

    You’re not going to be able to do this.

    The IntPtr that you have is a pointer to the implementation of the COMInterface. It’s perfectly feasible that you could have a completely separate class implementing COMInterface and that’s what you’re holding a pointer to.

    That said, the call to QueryInterface can only be used to get a reference to the .NET representation of COMInterface, not an instance of ClassA; it would require you to shape the contents of the class implementing COMInterface in unmanaged code into something that managed code can understand and then write it to ClassA which is a completely different thing altogether.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use System.Runtime.InteropServices.ComTypes.IStream from C#, but I'm having some trouble. According to
It is first time I am trying to use DllImort in C#. But it
Im trying use a Java annotation in a Groovy class but have trouble to
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
Trying to use Powershell to script the removal of specific custom errors from an
I'm trying to use System.Windows.Forms.HTMLDocument in a console application. First, is this even possible?
I am trying use filehelpers class builder but I am kinda confused on what
I was trying use svn to find a checkin using svn log, but it
I am trying use std::copy to copy from two different iterator. But during course

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.