What is the (fnptr)* type and how to create it?

前端 未结 3 1109
一个人的身影
一个人的身影 2020-12-29 11:02

The following IL code creates a Type instance named (fnptr)* (token 0x2000000 - invalid, module mscorlib.dll).

ldtoken method void* ()*
call cla         


        
3条回答
  •  独厮守ぢ
    2020-12-29 11:59

    I have no real idea what you are asking and why you think there is anything wrong. (fnptr)* is the type name of a pointer to an unmanaged function pointer. That it gets special treatment in the CLR is indeed odd, I suspect it is an archeological artifact. Dating back to a time before .NET and before delegates were invented. The CLR started life as the "universal runtime" in Project 42, a failed project before .NET.

    Maybe some C++/CLI code to demonstrate how to generate one is useful, shows you how to create it:

    #include "stdafx.h"
    
    using namespace System;
    
    typedef void (*functionPointer)(int);
    
    ref class Example {
    public:
        functionPointer* fp;
    };
    
    int main(array ^args)
    {
        auto field = Example::typeid->GetField("fp");
        auto name = field->FieldType->FullName; 
        Console::WriteLine(name);
        return 0;
    }
    

    Output: (fnptr)*

提交回复
热议问题