title: Access violation writing location 0x00000000 when using LookupAccountName
body: <p>After creating a user account with <code>NetUserAdd</code>, I found out that I would need to use <code>NetLocalGroupAddMembers</code> to add the user to the Users group, so I called <code>CreateWellKnownSid</code> to get the Users' SID, LookupAccountSid to get the string name from that SID and pass it to <code>NetLocalGroupAddMembers.</code></p>
  <p>I also needed to specify the user name, but the function required <strong>domain\name</strong> format as <code>level 3</code> (<code>LOCALGROUP_MEMBERS_INFO_3</code>), but I did not have that. I decided to call <code>LookupAccountName</code> to get the user name SID and pass it to <code>level 0</code> (<code>LOCALGROUP_MEMBERS_INFO_0</code>).</p>
  <p>This is how I did it:</p>
  <pre><code>//LocalAlloc
      UINT memAttributes = LMEM_FIXED;
      SIZE_T sidSize = SECURITY_MAX_SID_SIZE;
  
  //LookupAccountName
      PSID accountSID;
      SID_NAME_USE typeOfAccount;
  
  //NetLocalGroupAddMembers
      NET_API_STATUS localGroupAdd;
      DWORD levelOfData = 0;  //LOCALGROUP_MEMBERS_INFO_0
      LOCALGROUP_MEMBERS_INFO_0 localMembers;
      DWORD totalEntries = 0;
  
  
  
  //Allocate memory for LookupAccountName
          if (!(accountSID = LocalAlloc(memAttributes, sidSize)))
          {
              wprintf(L&quot;\nMemory allocation for account SID failed: \n&quot;);
              ShowError(GetLastError());
              exit(1);
  
          }
  
  
  if (!LookupAccountNameW(NULL, argv[1], accountSID,
                                      (LPDWORD)&amp;sidSize, NULL, 0, &amp;typeOfAccount))
              {
                  fwprintf(stderr, L&quot;Error getting SID from name: \n&quot;);
                  ShowError(GetLastError());
                  return 1;
  
              }
  
  //Here I should be able to use NetLocalGroupAddMembers
              //to add the user passed as argument to the Users group. 
              localMembers.lgrmi0_sid = accountSID;
  
              localGroupAdd = NetLocalGroupAddMembers(NULL, name, levelOfData, (LPBYTE)&amp;localMembers, totalEntries);
  
              if (localGroupAdd != NERR_Success)
              {
                  fwprintf(stderr, L&quot;Error adding member to the local group: \n&quot;);
                  ShowError(GetLastError());
                  return 1;
              }
              else
              {
                  wprintf(L&quot;\nUser %s has been successfully added.\n&quot;, argv[1]);
  
              }
  </code></pre>
  <p>This is the error I am getting:</p>
  <blockquote>
  <p>Exception thrown at 0x743F059A (sechost.dll) in UserCreator.exe:
  0xC0000005: Access violation writing location 0x00000000.</p>
  </blockquote>
  <p>Any clues?</p>