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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:08:43+00:00 2026-05-24T04:08:43+00:00

In .NET programs I can create a generic type by: System::Type::MakeGenericType(…) There must be

  • 0

In .NET programs I can create a generic type by:

 System::Type::MakeGenericType(...)

There must be a way to do that in native C++ for a .NET type (with _TypePtr). I am hosting my own CLR instance and not using C++/CLI. (Here’s an example of how that can be done.) My approach for that is:

_TypePtr BuildGenericType(_TypePtr spGenericType, _TypePtr spTypeArgs[]) 
{
    return spGenericType-> ..... ???
}

But there is no method like MakeGenericType, and I don’t know where to find it. Any ideas on how to solve this?

  • 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-24T04:08:44+00:00Added an answer on May 24, 2026 at 4:08 am

    Finally i found a workaround myself.
    At first i need an additional assembly that wraps System::TypeBuilder

    /// <summary>
    /// Wrapper for System::TypeBuilder
    /// </summary>
    public class TypeBuilder
    {
        /// <summary>
        /// Creates a generic type out of the given arguments.
        /// </summary>
        /// <param name="generic">The unqualified generic type.</param>
        /// <param name="typeArgs">The typearguments for the generic type.</param>
        /// <returns>The qualified generic type.</returns>
        public static Type MakeGenericType(Type generic, params Type[] typeArgs)
        {
            return generic.MakeGenericType(typeArgs);
        }
    }
    

    This additional assemly i load from c++

    And there i run these sexy lines, where CLRAssembly is an abstraction layer for clr.

    _TypePtr CLRAssembly::BuildType(_TypePtr spGenericType, _TypePtr spTypeArgs[]) 
    {
        LONG index = 0;
        SAFEARRAY* psaArgs = SafeArrayCreateVector(VT_VARIANT, 0, 1 + (sizeof(spTypeArgs)/sizeof(_TypePtr)));
        SafeArrayPutElement(psaArgs, &index, &_variant_t((IUnknown*)spGenericType, true));
        for(int i = 0; i < sizeof(spTypeArgs)/sizeof(_TypePtr); i++) {
            index++;
            SafeArrayPutElement(psaArgs, &index, &_variant_t((IUnknown*)spTypeArgs[i], true));
        }
    
        return (_TypePtr)clraAssemblyHelper->RunMethod(L"AssemblyHelper.TypeBuilder", L"MakeGenericType", psaArgs); 
    }
    

    Finally i can run my example method like this:

    DDDElements::Defs* ListDefs::AddNew()
    {
        _TypePtr params[1];
        params[0] = clra->BuildType(L"DDD.Elements.Defs");
        _TypePtr spType = clra->BuildType(clra->BuildType(L"DDD.ElementList`1"), params);
        return new DDDElements::Defs(clr, clra, 
            clra->RunMethod(spType, vtCLRObject, L"AddNew")
        );
    }
    

    Finally it works pretty good. 🙂

    /Solved

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

Sidebar

Related Questions

I can view C# code from .NET ddl's with ILSpy. Are there any programs
I have a C#/.NET program that can run both as a console application and
I have an ASP.NET web service that I can access via a windows program
I would like to compile and distribute (on .net) some python programs that work
Can anyone recommend a tool (ideally FOSS) that can analyse an .NET assembly and
CruiseControl.net creates (by default) for each project a subdirectory under: c:\Program File\CruiseControl.NET\server How can
I can access the database either from a .NET program (using ODBC) or through
Newbie here...can I write one program which incorporates .NET LINQ and also various Java
I would like to distribute my .NET programs without the .NET framework. Is it
What profilers have you used when working with .net programs, and which would you

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.