_AppDomainPtr Load_3方法示例

_AppDomainPtr Load_3 method example?

本文关键字:方法 AppDomainPtr Load      更新时间:2023-10-16

我正在尝试使用_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);

有人用过吗?

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

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);
    }
}