PPOLICY_PRIMARY_DOMAIN_INFO PrimaryDomain; LPWSTR szPrimaryDomainName = NULL; LPWSTR DomainController = NULL; // // get the primary domain // Status = LsaQueryInformationPolicy( PolicyHandle, PolicyPrimaryDomainInformation, &PrimaryDomain ); if(Status != STATUS_SUCCESS) goto cleanup; // // if the primary domain Sid is NULL, we are a non-member, and // our work is done. // if(PrimaryDomain->Sid == NULL) { LsaFreeMemory(PrimaryDomain); bSuccess = TRUE; goto cleanup; } AddTrustToList(&PrimaryDomain->Name); // // build a copy of what we just added. This is necessary in order // to lookup the domain controller for the specified domain. // the Domain name must be NULL terminated for NetGetDCName(), // and the LSA_UNICODE_STRING buffer is not necessarilly NULL // terminated. Note that in a practical implementation, we // could just extract the element we added, since it ends up // NULL terminated. // szPrimaryDomainName = (LPWSTR)HeapAlloc( GetProcessHeap(), 0, PrimaryDomain->Name.Length + sizeof(WCHAR) // existing length + NULL );