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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:08:26+00:00 2026-05-23T05:08:26+00:00

I created 2 programs – in C# and C++, both invoke native methods from

  • 0

I created 2 programs – in C# and C++, both invoke native methods from C dll. C++ works fine, because there are the same data types, C# doesn’t work.

And native function parameter is unsigned char*. I tried byte[] in C#, it didn’t work, then I tried:

fixed(byte* ptr = byte_array) {
  native_function(ptr, (uint)byte_array.Length);
}

It also doesn’t work. Is it correct to convert byte array to byte* in such way? Is it correct to use byte in C# as unsigned char in C?

EDIT:
This stuff returns the wrong result:

byte[] byte_array = Encoding.UTF8.GetBytes(source_string);
nativeMethod(byte_array, (uint)byte_array.Length);

This stuff also returns the wrong result:

 byte* ptr;
 ptr = (byte*)Marshal.AllocHGlobal((int)byte_array.Length);
 Marshal.Copy(byte_array, 0, (IntPtr)ptr, byte_array.Length);
  • 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-23T05:08:27+00:00Added an answer on May 23, 2026 at 5:08 am

    You have to marshal the byte[] :

    [DllImport("YourNativeDLL.dll")]
    public static extern void native_function
    (
        [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)]
        byte[] data,
        int count // Recommended
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Many programs have created a huge amount of swap files. They annoy me, because
One of our programs is erroring out because a stored procedure was created with
I have created a few little programs that export data to a text file
I write programs used internally by our company. I've created several support DLLs that
I was wondering how could I select objects which were created during programs runtime.
I created a script in perl to run programs with a timeout. If the
I have created MSI installers for programs compiled with Visual C++ 2008 Express edition
I have 2 programs (.exe) which I've created in .NET. We'll call them the
I am currently writting programs in linux like this: From the command line I
I am a bit rusty with threaded programs especially in windows. I have created

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.