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 348051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:19:43+00:00 2026-05-12T11:19:43+00:00

Every example I can find is in C++, but I’m trying to keep my

  • 0

Every example I can find is in C++, but I’m trying to keep my project in C. Is it even possible to host the CLR in a C program?

If so, can you point me to an example?

  • 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-12T11:19:43+00:00Added an answer on May 12, 2026 at 11:19 am

    As the above comments hint, there is a set of COM APIs for hosting the CLR, and you should be able to call these COM APIs from both C and C++.

    As an example, below is a quick piece of (untested) C code that shows how to start up the CLR and execute a static method of a class in a managed assembly (which takes in a string as an argument and returns an integer). The key difference between this code and its C++ counterpart is the definition of COBJMACROS and the use of the <type>_<method> macros (e.g. ICLRRuntimeHost_Start) to call into the CLR-hosting COM interface. (Note that COBJMACROS must be defined prior to #include‘ing mscoree.h to make sure these utility macros get defined.)

    #include <windows.h>
    
    #define COBJMACROS
    #include <mscoree.h>
    
    int main(int argc, char **argv)
    {
        HRESULT status;
        ICLRRuntimeHost *Host;
        BOOL Started;
        DWORD Result;
    
        Host = NULL;
        Started = FALSE;
    
        status = CorBindToRuntimeEx(
                     NULL,
                     NULL,
                     0,
                     &CLSID_CLRRuntimeHost,
                     &IID_ICLRRuntimeHost,
                     (PVOID *)&Host
                     );
        if (FAILED(status)) {
            goto cleanup;
        }
    
        status = ICLRRuntimeHost_Start(Host);
        if (FAILED(status)) {
            goto cleanup;
        }
    
        Started = TRUE;
    
        status = ICLRRuntimeHost_ExecuteInDefaultAppDomain(
                     Host,
                     L"c:\\path\\to\\assembly.dll",
                     L"MyNamespace.MyClass",
                     L"MyMethod",
                     L"some string argument to MyMethod",
                     &Result
                     );
        if (FAILED(status)) {
            goto cleanup;
        }
    
        // inspect Result
        // ...
    
    cleanup:
        if (Started) {
            ICLRRuntimeHost_Stop(Host);
        }
    
        if (Host != NULL) {
            ICLRRuntimeHost_Release(Host);
        }
    
        return SUCCEEDED(status) ? 0 : 1;
    }
    

    This sample should work with .NET 2.0+, although it looks like .NET 4.0 (not yet released) has deprecated some of these APIs in favor of a new set of APIs for hosting the CLR. (And if you need this to work with .NET 1.x, you need to use ICorRuntimeHost instead of ICLRRuntimeHost.)

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

Sidebar

Related Questions

I've tried every example I can find on the web but I cannot get
It seems like every example I can find of switching between activities involves creating
I am trying to find a function that can fade an element from a
I am trying to work out a few guesses on algorithm complexity, but every
I started a little fun project - collecting a hello World-program for every letter
Every example I've seen of CGI/Perl basically a bunch of print statements containing HTML,
Just about every piece of example code everywhere omits error handling (because it confuses
In the following example should I expect that values.size() will be called every time
I will choose Java as an example, most people know it, though every other
Every time I create a new project I copy the last project's ant file

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.