_AppDomainPtr Load_3 方法示例?

_AppDomainPtr Load_3 method example?

我正在尝试使用 _AppDomainPtr Load_3 方法加载 C# 程序集。自从我收到错误后,您有一些示例吗: hr = 0x80131533 : A mismatch has occurred between the runtime type of the array and the sub type recorded in the metadata. 这是我如何加载程序集的片段:

static void binarray(SAFEARRAY** output, const char* data, size_t size)
{
    SAFEARRAYBOUND  Bound;
    Bound.lLbound = 0;
    Bound.cElements = size;

    *output = SafeArrayCreate(VT_R8, 1, &Bound);

    double HUGEP *pdFreq;
    HRESULT hr = SafeArrayAccessData(*output, (void HUGEP* FAR*)&pdFreq);
    if (SUCCEEDED(hr))
    {
        // copy sample values from data[] to this safearray
        for (DWORD i = 0; i < size; i++)
        {
            *pdFreq++ = data[i];
        }
        SafeArrayUnaccessData(*output);
    }
}

然后调用:

hr = spDefaultAppDomain->Load_3(output, &spAssembly);

有人用过吗?

显然我已经找到了问题所在。我正在创建一个实数 SafeArray。对于任何需要它的人来说,正确的解决方法是:

static void binarray(SAFEARRAY** output, const unsigned  char* data, size_t size)
{
    SAFEARRAYBOUND  Bound;
    Bound.lLbound = 0;
    Bound.cElements = size;
//  VT_I1
    *output = SafeArrayCreate(VT_UI1, 1, &Bound);
    //VT_R8
    unsigned char *pdFreq;
    HRESULT hr = SafeArrayAccessData(*output, (void* FAR*)&pdFreq);
    if (SUCCEEDED(hr))
    {
        // copy sample values from data[] to this safearray
        for (DWORD i = 0; i < size; i++)
        {
            *pdFreq++ = data[i];
        }
        SafeArrayUnaccessData(*output);
    }
}