I am trying to load a C# assembly with _AppDomainPtr
Load_3
method. Do you have some example since I get error:
hr = 0x80131533 : A mismatch has occurred between the runtime type of the array and the sub type recorded in the metadata.
Here is a snippet how do I load the assembly:
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);
}
}
And the call:
hr = spDefaultAppDomain->Load_3(output, &spAssembly);
Anyone used that?
Apparently I've found the problem. I was creating a SafeArray of Real numbers. The correct fix for anyone who needs that is:
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);
}
}
User contributions licensed under CC BY-SA 3.0