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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:59:47+00:00 2026-05-11T19:59:47+00:00

I have a bit of a weird problem. I have a form with a

  • 0

I have a bit of a weird problem.
I have a form with a Label in it for outputting text at certain points in the program instead of console output.
Given the following code:

result = SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref tBuff, 
                                          (uint)SPDRP.DEVICEDESC,
                                          out RegType, ptrBuf, 
                                          buffersize, out RequiredSize); 

if (!result)
{
    errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
    statusLabel.Text += "\nSetupDiGetDeviceRegistryProperty failed because "
                        + errorMessage.ToString();
}
else
{
    statusLabel.Text += "\nPtr buffer length is: " + ptrBuf.Length.ToString();

    sw.WriteLine(tCode.GetString(ptrBuf) );

    sw.WriteLine("\n");
    // This is the only encoding that will give any legible output.
    // Others only show the first character "U"
    string tmp = tCode.GetString(ptrBuf) + "\n"; 

    statusLabel.Text += "\nDevice is: " + tmp + ".\n";                    
}

I get just the one hardware ID output on the label. This piece of code is at the end of my loop. at 1st this made me think that my loop was some how hanging, but when I decided to direct output to a file I get almost what I want and the output outside the loop.
Can anyone tell me what’s going on here?
All I want is to get the string representing the hardware ID from the []byte (ptrBuf).
Can some explain what’s going on here, please?
My working environment is MSVstudio 2008 express. In windows 7.

Thanks

  • 1 1 Answer
  • 1 View
  • 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-11T19:59:47+00:00Added an answer on May 11, 2026 at 7:59 pm

    You haven’t shown what tCode is, unfortunately.

    Looking at the docs for the API call it looks like it should be populated with a REG_SZ. I suspect that’s Unicode, i.e.

    string property = Encoding.Unicode.GetString(ptrBuf, 0, RequiredSize);
    

    should convert it.

    However, if you’re expecting multiple values, I wonder if it’s a '\0'-separated string: trying to output that in a Win32 control will indeed stop at the first '\0'.

    Try this:

    string property = Encoding.Unicode.GetString(ptrBuf, 0, RequiredSize);
                                      .Replace('\0', ' ');
    

    That should (if I’m guessing correctly) space-separate the values.

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

Sidebar

Related Questions

all. I'm having a bit of weird problem with client server program. I have
I have a bit of a weird problem. I developed an app with MVC
I have a bit of a weird problem here! I am trying to write
This is a little bit of weird problem here. Say I have a C++
This is a bit weird, but I have no idea where the problem is.
Hey guys, I have a bit of a weird problem. I have a jquery
Ok I have a bit of a weird scenario, and I can't change the
i'm having a bit of a weird problem. I programmed a asp.net mvc app
I have really weird problem with colors in interface builder. I set a color
I have a weird problem building a release of an erlang application that I'm

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.