Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;在动态链接库mscoree.dll中找不到过程入口点CLRCreateInstance_C++_.net_Clr - Fatal编程技术网

C++ C++;在动态链接库mscoree.dll中找不到过程入口点CLRCreateInstance

C++ C++;在动态链接库mscoree.dll中找不到过程入口点CLRCreateInstance,c++,.net,clr,C++,.net,Clr,我有以下代码检查电脑上安装的CLR版本 #include <string> #include <iostream> #include <string> #include <locale> #include <codecvt> #include <iomanip> #include <windows.h> #import <mscorlib.tlb> raw_interfaces_only auto_r

我有以下代码检查电脑上安装的CLR版本

#include <string>
#include <iostream>
#include <string>
#include <locale>
#include <codecvt>
#include <iomanip>
#include <windows.h>
#import <mscorlib.tlb> raw_interfaces_only auto_rename
#include <metahost.h>
#pragma comment( lib, "Mscoree" )

_COM_SMARTPTR_TYPEDEF(ICLRMetaHost, IID_ICLRMetaHost);
_COM_SMARTPTR_TYPEDEF(ICLRRuntimeInfo, IID_ICLRRuntimeInfo);

int checkCLRversion()
{
    ICLRMetaHostPtr pMetaHost{ nullptr };
    HRESULT hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_PPV_ARGS(&pMetaHost));
    if (FAILED(hr))
        return -1;

    IEnumUnknownPtr enumptr{ nullptr };
    hr = pMetaHost->EnumerateInstalledRuntimes(&enumptr);
    if (FAILED(hr))
        return -1;

    while (true)
    {
        ULONG fetched{ 0 };
        IUnknownPtr uptr{ nullptr };
        hr = enumptr->Next(1, &uptr, &fetched);
        if (hr == S_OK)
        {
            ICLRRuntimeInfoPtr crlri{ uptr };
            DWORD size{ 0 };
            hr = crlri->GetVersionString(nullptr, &size);
            if (hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) && size > 0)
            {
                std::wstring version(size, 0);
                hr = crlri->GetVersionString(&version.front(), &size);
                if (SUCCEEDED(hr))
                {
                    std::wcout << version << std::endl;                    
                }
            }
        }
        else
            break;
    };
    return 0;
}

void main()
{
    HMODULE clrInst = LoadLibraryA("C:\\Windows\\System32\\mscoree.dll");
    if (GetProcAddress(clrInst, "CLRCreateInstance") != NULL)
    {
        checkCLRversion();
    }
}

但是它没有帮助。

.NET版本>=4.0必需。Win7最初随3.5一起提供,但由于主函数中的条件,代码采用了另一种方式,不做需要.NET4的事情。无论如何,我有一个错误,你不能走那么远,它在main()开始运行之前失败了。加载程序无法绑定CLRCreateInstance()函数调用。如果要动态检查,则还必须动态调用。@HansPassant,但如何执行?:)您需要一个函数指针。h已经声明了一个,CLRCreateInstanceFnPtr fp=(CLRCreateInstanceFnPtr)GetProcAddress(…);
if (GetProcAddress(clrInst, "CLRCreateInstance") != NULL)