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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:15:53+00:00 2026-06-15T10:15:53+00:00

I am having a data conversion issue that need your help. My project is

  • 0

I am having a data conversion issue that need your help.

My project is an InterOp between C and C#, all the data from C is char * type, the data itself could be binary or displayable chars, I.e. each byte is in 0x00 to 0xFF range.

I am using Data marshal::PtrToStringAnsi to convert the char* to String^ in CLI code, but I found some bytes value changed. for example C382 converted to C32C. I guess it is possibly because ANSI is only capable of converting 7-bit char, but 82 is over the range? Can anyone explain why and what is the best way?

Basically what I want to do is, I don’t need any encoding conversion, I just want to convert any char * face value to a string, e.g. if char *p = "ABC" I want to String ^s="ABC" as well, if *p="C382"(represents binary value) I also want ^s="C382".

Inside my .NET code, two subclasses will take the input string that either represents binary data or real string, if it is binary it will convert "C382" to byte[]=0xC3 0x82;

When reading back the data, C382 will be fetched from database as binary data, eventually it need be converted to char* "C382".

Does anybody have similar experience how to do these in both directions? I tried many ways, they all seem to be encode ways.

  • 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-15T10:15:54+00:00Added an answer on June 15, 2026 at 10:15 am

    The Marshal class will do this for you.

    When converting from char* to byte[] you need to pass the pointer and the buffer length to the managed code. Then you can do this:

    byte[] FromNativeArray(IntPtr nativeArray, int len)
    {
        byte[] retval = new byte[len];
        Marshal.Copy(nativeArray, retval, 0, len);
        return retval;
    }
    

    And in the other direction there’s nothing much to do. If you have a byte[] then you can simply pass that to your DLL function that expects to receive a char*.

    C++

    void ReceiveBuffer(char* arr, int len);
    

    C#

    [DllImport(...)]
    static extern void ReceiveBuffer(byte[] arr, int len);
    ....
    ReceiveBuffer(arr, arr.Length);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a problem with data type conversion that I just can figure
I'm building a program that has several functions that need to read data from
I'm having data as like below. I need to plot graph based on region.
I am fetching some data having UTF8 collation ( utf8_unicode_ci ) from a MySQL
I am having a database in .dbf (FoxPro) format. How to retrieve data from
SQL Server 2005 Question: I'm working on a data conversion project where I'm taking
I am having trouble nailing down the best method for passing data from a
I've been having an issue with an app written in VB.Net that relies on
Hey all, I'm having the following issue converting amr files to mp3 files. When
I'm having trouble with data being exchanged between Perl and Ruby via YAML. I

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.