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

  • Home
  • SEARCH
  • 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 6053379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:02:02+00:00 2026-05-23T08:02:02+00:00

This is the signature of the native c method: bool nativeMethod1 (unsigned char *arrayIn,

  • 0

This is the signature of the native c method:

bool nativeMethod1
(unsigned char *arrayIn,
unsigned int arrayInSize,
unsigned char *arrayOut,
unsigned int *arrayOutSize);

I have no idea why arrayOutSize is a pointer to unsigned int but not int itself.

This is how I invoke it from C#:

byte[] arrayIn= Encoding.UTF8.GetBytes(source);
uint arrayInSize = (uint)arrayIn.Length;
byte[] arrayOut = new byte[100];
uint[] arrayOutSize = new uint[1];
arrayOutSize[0] = (uint)arrayOut.Length;

fixed (byte* ptrIn = arrayIn, ptrOut = arrayOut)
{
    if (nativeMethod1(ptrIn, arrayInSize, ptrOut, arrayOutSize))
    {
        Console.WriteLine("True");
    }
    else
    {
        Console.WriteLine("False");
    }
}

and some DllImport code

[DllImport(@"IcaCert.dll", EntryPoint = "CreateCert2", CallingConvention = CallingConvention.Cdecl)]<br>
public unsafe static extern bool CreateCert2WithArrays(
        byte* data, uint dataSize,<br>
        byte* result, uint[] resultSize);

According to the documentation, native method should return arrayOut fulfilled with the values depending on arrayIn. If its size is less than needed, it returns false. True otherwise. I figured that it’s needed 850 elements in arrayOut. So, when I create new byte[100] array, function should return false, but it always returns true. WHY?

  • 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-05-23T08:02:02+00:00Added an answer on May 23, 2026 at 8:02 am

    You don’t need unsafe code and fixed here. The standard P/Invoke marshaller is more than up to the task:

    [DllImport(@"IcaCert.dll", EntryPoint = "CreateCert2", CallingConvention = CallingConvention.Cdecl)]
    public static extern bool CreateCert2WithArrays(
        byte[] arrayIn, 
        uint arrayInSize,
        byte[] arrayOut,
        ref uint arrayOutSize
    );
    
    byte[] arrayIn = Encoding.UTF8.GetBytes(source);
    uint arrayInSize = (uint)arrayIn.Length;
    uint arrayOutSize = 0;
    
    CreateCert2WithArrays(arrayIn, arrayInSize, null, ref arrayOutSize);
    byte[] arrayOut = new byte[arrayOutSize];
    CreateCert2WithArrays(arrayIn, arrayInSize, arrayOut, ref arrayOutSize);
    

    I don’t know for sure what the protocol of the function is, but it is normal for such functions to be able to receive NULL if the output array has size 0.

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

Sidebar

Related Questions

I have a method which have this signature public static IList<T> GetBy<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression)
I have this function signature I have to match typedef int (*lua_CFunction) (lua_State *L);//target
I have a constructor signature like this public NavigationLink(Func<String> getName, Func<UrlHelper, String> getURL, Func<bool>
I have a C++ method signature that looks like this: static extern void ImageProcessing(
I have a method with this signature: protected final Map<String, Object> buildOutputMappings( AbstractDataObject ado,
i have a sub with this signature Public Sub Save(ByVal obj As IPta) now
In AS3 you have a function on a string with this signature: function replace(pattern:*,
In App Engine, according to the JavaDoc , the getTypeRank method has this signature:
i find this question tricky but what files store method signature info for xml
A function with this signature: unsigned _stdcall somefunction (LPVOID lParam); does it mean that

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.