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 9019823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:51:58+00:00 2026-06-16T04:51:58+00:00

I have a C# function with following signature: int Get1251Bytes(string source, byte[] result, Int32

  • 0

I have a C# function with following signature:

int Get1251Bytes(string source, byte[] result, Int32 lengthOfResult)

I call it from C++. I was informed by compiler that 2-nd param must have SAFEARRAY* type. So I call it in this way:

SAFEARRAY* safeArray = SafeArrayCreateVector(VT_UI1, 0, arrayLength);
char str[] = {'s', 't', 'a', 'c', 'k', '\0'};
converter->Get1251Bytes(str, safeArray, arrayLength);

But safeArray is not updated, it still contains zores. But I tested Get1251Bytes function in C# unit-test. It works properly and updates result array. What am I doing wrong?

  • 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. Editorial Team
    Editorial Team
    2026-06-16T04:51:59+00:00Added an answer on June 16, 2026 at 4:51 am

    Your problem is related to Blittable and Non-Blittable Types (Byte is blittable):

    As an optimization, arrays of blittable types and classes that contain only blittable members are pinned instead of copied during marshaling. These types can appear to be marshaled as In/Out parameters when the caller and callee are in the same apartment. However, these types are actually marshaled as In parameters, and you must apply the InAttribute and OutAttribute attributes if you want to marshal the argument as an In/Out parameter.

    To fix your code you need to apply an [Out] attribute to the result parameter in the C# code:

    int Get1251Bytes(string source, [Out] byte[] result, Int32 lengthOfResult)
    

    Also, you don’t need to pass lengthOfResult. In .NET you can use the Length property to get the size of the array.

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

Sidebar

Related Questions

I have a C function with the following signature: int my_function(int n, struct player
I have a unmanaged C++ function with the following signature: int function(char* param, int
I have been trying to call a C function that has the following signature
I have a function with following signature char requestApiCall(int num, const wchar_t* pParams =
I have the following function: func fitrange(a, x, b int) int { if a
I have the following function in a PHP script, which returns and API call:
I have the following function using Excel 2010: Private Function MakeAllSheetsValuesOnly(targetBookName As String) If
I'm getting a strange error. I have a function of the following signature: template
I have the following recursive function: ALTER FUNCTION [dbo].[ListAncestors] ( @Id int ) RETURNS
Note that the following two functions have the same type and signature: void foo1(int

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.