Hospedagem CLR - Bad parâmetros
-
22-07-2019 - |
Pergunta
Eu estou tentando hospedar o CLR dentro do meu aplicativo C ++ e estou tendo problemas invocando o ponto de entrada do aplicativo gerenciado. O ponto de entrada é definida como de costume:
static void Main(string[] args)
E aqui está o real código C ++:
CComPtr<_MethodInfo> entryPoint;
hr = assembly->get_EntryPoint(&entryPoint); // this works just fine
if (FAILED(hr))
return hr;
SAFEARRAY *args =
SafeArrayCreateVector(VT_VARIANT, 1, 1); // create an array of the length of 1 ( Main(string[]) )
int argc;
LPWSTR cmdLine = GetCommandLineW();
LPWSTR *argv = CommandLineToArgvW(cmdLine, &argc); // get an array of arguments to this function
VARIANT vtPsa;
vtPsa.vt = (VT_ARRAY | VT_BSTR);
vtPsa.parray = SafeArrayCreateVector(VT_BSTR, 1, argc); // create an array of strings
for (long i = 0; i < argc; i++)
{
SafeArrayPutElement(vtPsa.parray, &i, SysAllocString(argv[i])); // insert the string from argv[i] into the safearray
}
long idx[1] = {0};
SafeArrayPutElement(args, idx, &vtPsa); // insert an array of BSTR into the VT_VARIANT args array
VARIANT obj, result;
VariantInit(&obj);
VariantInit(&result);
try
{
hr = entryPoint->Invoke_3(obj, args, &result); // call the entry point
}
catch(_com_error ex)
{
MessageBox(NULL, ex.ErrorMessage(), "Error", 0);
}
if(FAILED(hr))
{
hr = hr; // added just so I can set a breakpoint
}
O código de erro que estou recebendo é -2146233032, que segundo corresponde corerror.h a:
para decimal -2146233032 / hex 0x80131538:
COR_E_SAFEARRAYRANKMISMATCH
A falta de correspondência entre a Ocorreu Hierarquia de tempo de execução da matriz e o posto registrada nos metadados.
Alguém pode ver o problema?
Solução
não deve o segundo parâmetro para SafeArrayCreateVector ser 0 em ambos os casos? listas MSDN esse valor como "o limite inferior para a matriz. Pode ser negativo."
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow