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

  • Home
  • SEARCH
  • 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 278515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:15:04+00:00 2026-05-12T01:15:04+00:00

EDIT: I’ve written the results up as a blog post . The C# compiler

  • 0

EDIT: I’ve written the results up as a blog post.


The C# compiler treats COM types somewhat magically. For instance, this statement looks normal…

Word.Application app = new Word.Application();

… until you realise that Application is an interface. Calling a constructor on an interface? Yoiks! This actually gets translated into a call to Type.GetTypeFromCLSID() and another to Activator.CreateInstance.

Additionally, in C# 4, you can use non-ref arguments for ref parameters, and the compiler just adds a local variable to pass by reference, discarding the results:

// FileName parameter is *really* a ref parameter
app.ActiveDocument.SaveAs(FileName: "test.doc");

(Yeah, there are a bunch of arguments missing. Aren’t optional parameters nice? 🙂

I’m trying to investigate the compiler behaviour, and I’m failing to fake the first part. I can do the second part with no problem:

using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

[ComImport, GuidAttribute("00012345-0000-0000-0000-000000000011")]
public interface Dummy
{
    void Foo(ref int x);
}

class Test
{
    static void Main()
    {
        Dummy dummy = null;
        dummy.Foo(10);
    }
}

I’d like to be able to write:

Dummy dummy = new Dummy();

though. Obviously it’ll go bang at execution time, but that’s okay. I’m just experimenting.

The other attributes added by the compiler for linked COM PIAs (CompilerGenerated and TypeIdentifier) don’t seem to do the trick… what’s the magic sauce?

  • 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-05-12T01:15:05+00:00Added an answer on May 12, 2026 at 1:15 am

    By no means am I an expert in this, but I stumbled recently on what I think you want: the CoClass attribute class.

    [System.Runtime.InteropServices.CoClass(typeof(Test))]
    public interface Dummy { }
    

    A coclass supplies concrete
    implementation(s) of one or more
    interfaces. In COM, such concrete
    implementations can be written in any
    programming language that supports COM
    component development, e.g. Delphi,
    C++, Visual Basic, etc.

    See my answer to a similar question about the Microsoft Speech API, where you’re able to “instantiate” the interface SpVoice (but really, you’re instantiating SPVoiceClass).

    [CoClass(typeof(SpVoiceClass))]
    public interface SpVoice : ISpeechVoice, _ISpeechVoiceEvents_Event { }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: This question was written in 2008, which was like 3 internet ages ago.
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: This question is more about language engineering than C++ itself. I used C++
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
Edit: I have solved this by myself. See my answer below I have set
EDIT: upgraded this question to MVC 2.0 With asp.net MVC 2.0 is there an
Edit: This is technically a 2 part question. I've chosen the best answer that
EDIT: had to retag this, because, it's rather a Sweave / R question since
EDIT: This is with Rails 2.3.5 For some reason, when I try to associate
EDIT: Please note that this question is OUTDATED; RVM got way easier to use

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.