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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:50:15+00:00 2026-05-19T23:50:15+00:00

I’m not a C++ developer, so I guess it’s just my fault that my

  • 0

I’m not a C++ developer, so I guess it’s just my fault that my program doesn’t work.
I want to look up the SID for a windows group and return a readable SID.

wchar_t* SpcLookupName(LPCTSTR lpszSystemName, LPCTSTR lpszAccountName) {

PSID         Sid;
DWORD        cbReferencedDomainName, cbSid;
LPTSTR       ReferencedDomainName;
SID_NAME_USE eUse;

cbReferencedDomainName = cbSid = 0;
if (LookupAccountName(lpszSystemName, lpszAccountName, 0, &cbSid,
                    0, &cbReferencedDomainName, &eUse)) {
    SetLastError(ERROR_NONE_MAPPED);
    return 0;
}

if (GetLastError(  ) != ERROR_INSUFFICIENT_BUFFER) return 0;

if (!(Sid = (PSID)LocalAlloc(LMEM_FIXED, cbSid))) return 0;

ReferencedDomainName = (LPTSTR)LocalAlloc(LMEM_FIXED, cbReferencedDomainName);

if (!ReferencedDomainName) {
    LocalFree(Sid);
    return 0;
}

if (!LookupAccountName(lpszSystemName, lpszAccountName, Sid, &cbSid,
                     ReferencedDomainName, &cbReferencedDomainName, &eUse)) {
    LocalFree(ReferencedDomainName);
    LocalFree(Sid);
    return 0;
}

wchar_t* psz;

// Loading ConvertSidToStringSid
typedef BOOL (WINAPI *tConvertSidToStringSid)(PSID,wchar_t*);

tConvertSidToStringSid pConvertSidToStringSid=0;

HINSTANCE handle = ::LoadLibrary("Advapi32.dll");

pConvertSidToStringSid = (tConvertSidToStringSid) ::GetProcAddress(handle, "ConvertSidToStringSidA");

if(pConvertSidToStringSid(Sid, psz)){                               
    return psz;
}
}

My problem is that the function returns only some strange characters and not the SID, 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-19T23:50:16+00:00Added an answer on May 19, 2026 at 11:50 pm

    There are a couple of obvious things wrong with your code…

    1) the prototype for ConvertSidToStringSid() is BOOL ConvertSidToStringSid(PSID Sid, LPTSTR *StringSid); which means that your typedef should be typedef BOOL (WINAPI *tConvertSidToStringSid)(PSID,LPTSTR *);

    2) you are looking up the ANSI version and passing a wchar_t *… You should either look up the wide character version ConvertSidToStringSid() or, a better solution, IMHO, look up ConvertSidToStringSid and use a TCHAR * rather than a wchar_t * as this will work no matter what your unicode compile settings are, and it matches the typedef.

    3) finally due to the broken typedef you’re being allowed to pass the wrong data type to the function. It wants a LPTSTR * and you’re passing it a LPTSTR (well, actually you’re passing a wchar_t *… The LPTSTR is in fact the unicode aware type that maps to a wchar_t * if you’re using wide characters but the function that you are calling wants a pointer to that pointer and not the pointer itself.

    So, the fixed code is:

    typedef BOOL (WINAPI *tConvertSidToStringSid)(PSID,LPTSTR*);
    
    tConvertSidToStringSid pConvertSidToStringSid=0;
    
    HINSTANCE handle = ::LoadLibrary("Advapi32.dll");
    
    
    
    pConvertSidToStringSid = (tConvertSidToStringSid) ::GetProcAddress(handle, #ConvertSidToStringSid);
    
    if(pConvertSidToStringSid(Sid, &psz)){                               
        return psz;
    }
    

    Note the change to the typedef, the change to the GetProcAddress call (where we use the # to stringize the function name (which will either be ConvertSidToStringSidA or ConvertSidToStringSidW depending on your unicode settings) and the change to pass the address of psz rather than the pointer itself.

    And now your only problem is that you’re potentially leaking that psz unless you are making sure you free it in the caller with a call to LocalFree().

    Note that depending on the calling code, you might want to convert the typedef into wchar_t ** rather than LPTSTR * and then use the ConvertSidToStringSidW version to force the result to always be a wide character string.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported

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.