代码之家  ›  专栏  ›  技术社区  ›  arul

托管CLR-错误参数

  •  3
  • arul  · 技术社区  · 17 年前

    入口点的定义与通常一样:

    static void Main(string[] args)
    

    下面是实际的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
    }
    

    0x80131538:

    数组和列组的运行时列组 记录在元数据中。

    1 回复  |  直到 17 年前
        1
  •  3
  •   Daniel Vassallo    17 年前

    在这两种情况下,SafeArrayCreateVector的第二个参数不应该都是0吗?MSDN将该值列为“数组的下限。可以为负值。”