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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:02:41+00:00 2026-06-13T07:02:41+00:00

I have wrapped a C++ API in C#. This API fills the supplied memory

  • 0

I have wrapped a C++ API in C#. This API fills the supplied memory location with a byte array that represents program settings. I need to get Bit 0 to determine its state. Here is the C++ API and usage documentation:

DECL_FOOAPIDLL DWORD WINAPI FOO_GetVal(
VOID *Val,  //pointer to memory where the data will be stored by the function
DWORD Len,  //length of Val in bytes
DWORD Id    //identification number of the parameter
);

Here is my C# wrapper and call (what i assume to be correct):

        [DllImport(FOO_API, CharSet = CharSet.Auto)]
static public extern uint FOO_GetVal(IntPtr val, uint len, uint id);


        IntPtr Ptr = Marshal.AllocHGlobal(5);
        uint hr = NativeWrapper.FOO_GetVal(Ptr, 5, 1181);

        var byteArray = new byte[5];
        Marshal.Copy(Ptr, byteArray, 0, 5);


        Marshal.FreeHGlobal(Ptr);

How do i get bit 0?

I’ve tried (with no success):

bool b = GetBit(bytearray[0],0);

private bool GetBit(byte b, int bitnum)
{
    return (b & (1 << nitnum)) != 0;
}
  • 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-13T07:02:42+00:00Added an answer on June 13, 2026 at 7:02 am

    All my code was correct… the API vendor supplied me with the incorrect ID parameter (the 3rd value)… I appreciate all the comments and my new understanding of least to most significant bit explained by Guvante.

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

Sidebar

Related Questions

I have some images that are wrapped within containers like this: <div id=swatchcontainer> <div
I have 3 gits wrapped by a manifest file (this manifest file is in
I have an existing web application that is used by my coworkers. This web
trying to run this program. I think that to setup all of the web
I have a utility that compares a source and destination file date/time. This works
I have a function called ApiCalls() that is wrapped in a locker because the
let's say I have two shapes wrapped in Movieclip container. How can I detect
I have an asp.net button wrapped inside of an UpdatePanel, and when clicked it
I have a view in which I there is a repeater control wrapped with
I have a large body of text which has several sentences wrapped in yada

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.