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 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: change of question if my code is like this: <form name=login action=https://login.extremebb.net/login method=post
Edit: This question was written in 2008, which was like 3 internet ages ago.
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
EDIT : It turned out that this can only be done through an external
EDIT After staring at this for 2 days, I do see one issue. I
EDIT : I've gotten the famous question badge with this question, so I figured
EDIT: it is necessary for this to be a series of 1d Arrays. 2d
Edit: Seems numerous people think this is a dumb idea, so I would appreciate
EDIT:This did it: SELECT DISTINCT profileid FROM profilesrelevation WHERE profileid NOT IN ( SELECT
Edit: Updating post based on Martins comments below Hello, I'm just trying to get

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.