Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 118207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:27:29+00:00 2026-05-11T03:27:29+00:00

I’m trying to host the CLR inside my C++ application and I’m having problems

  • 0

I’m trying to host the CLR inside my C++ application and I’m having problems invoking the entry point of the managed application. The entry point is defined as usual:

static void Main(string[] args) 

And here’s the actual C++ code:

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 } 

The errorcode I’m getting is -2146233032, which according to corerror.h corresponds to:

for decimal -2146233032 / hex 0x80131538 :
COR_E_SAFEARRAYRANKMISMATCH
A mismatch has occured between the runtime rank of the array and the rank recorded in the metadata.

Can anyone see the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:27:30+00:00Added an answer on May 11, 2026 at 3:27 am

    Shouldn’t the second parameter to SafeArrayCreateVector be 0 in both cases? MSDN lists that value as ‘The lower bound for the array. Can be negative.’

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.