Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GetComputerObjectNameW Win API is failing

GetComputerObjectNameW Win API is failing

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++json
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rajneshmalik
    wrote on last edited by
    #1

    I was trying to use win API

    GetComputerObjectNameW

    as below but I am getting error. Can someone help me.

    #include
    #include
    #include
    typedef enum {
    NameUnknown,
    NameFullyQualifiedDN,
    NameSamCompatible,
    NameDisplay,
    NameUniqueId,
    NameCanonical,
    NameUserPrincipal,
    NameCanonicalEx,
    NameServicePrincipal,
    NameDnsDomain,
    NameGivenName,
    NameSurname
    } EXTENDED_NAME_FORMAT, *PEXTENDED_NAME_FORMAT;

    int main()
    {
    EXTENDED_NAME_FORMAT enf = NameFullyQualifiedDN;
    LPWSTR pwszComputerName;
    DWORD dwLen;

        dwLen = 0;
        GetComputerObjectNameW(enf, NULL, &dwLen);
    
        pwszComputerName = new WCHAR\[dwLen + 1\];
        if(NULL == pwszComputerName)
        {
            return 0;
        }
        if(!GetComputerObjectNameW(NameSamCompatible, pwszComputerName, &dwLen))
        {
            delete pwszComputerName;
            return 0;
        }
    
        sbstrTrustee = pwszComputerName;
        wprintf(L"GetComputerObjectName: %s\\n", pwszComputerName);
        delete pwszComputerName;
    

    }

    Some of Error message is as below.

    C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(117): error C2146: syntax error: missing ';' before identifier 'GetUserNameExA'
    C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(121): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(126): error C2086: 'BOOLEAN SEC_ENTRY': redefinition
    C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(117): note: see declaration of 'SEC_ENTRY'
    C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(126): error C2146: syntax error: missing ';' before identifier 'GetUserNameExW'
    C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(130): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    V L 2 Replies Last reply
    0
    • R rajneshmalik

      I was trying to use win API

      GetComputerObjectNameW

      as below but I am getting error. Can someone help me.

      #include
      #include
      #include
      typedef enum {
      NameUnknown,
      NameFullyQualifiedDN,
      NameSamCompatible,
      NameDisplay,
      NameUniqueId,
      NameCanonical,
      NameUserPrincipal,
      NameCanonicalEx,
      NameServicePrincipal,
      NameDnsDomain,
      NameGivenName,
      NameSurname
      } EXTENDED_NAME_FORMAT, *PEXTENDED_NAME_FORMAT;

      int main()
      {
      EXTENDED_NAME_FORMAT enf = NameFullyQualifiedDN;
      LPWSTR pwszComputerName;
      DWORD dwLen;

          dwLen = 0;
          GetComputerObjectNameW(enf, NULL, &dwLen);
      
          pwszComputerName = new WCHAR\[dwLen + 1\];
          if(NULL == pwszComputerName)
          {
              return 0;
          }
          if(!GetComputerObjectNameW(NameSamCompatible, pwszComputerName, &dwLen))
          {
              delete pwszComputerName;
              return 0;
          }
      
          sbstrTrustee = pwszComputerName;
          wprintf(L"GetComputerObjectName: %s\\n", pwszComputerName);
          delete pwszComputerName;
      

      }

      Some of Error message is as below.

      C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(117): error C2146: syntax error: missing ';' before identifier 'GetUserNameExA'
      C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(121): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(126): error C2086: 'BOOLEAN SEC_ENTRY': redefinition
      C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(117): note: see declaration of 'SEC_ENTRY'
      C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(126): error C2146: syntax error: missing ';' before identifier 'GetUserNameExW'
      C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(130): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      Why do you redefine the EXTENDED_NAME_FORMAT enumeration? :confused:

      R 1 Reply Last reply
      0
      • V Victor Nijegorodov

        Why do you redefine the EXTENDED_NAME_FORMAT enumeration? :confused:

        R Offline
        R Offline
        rajneshmalik
        wrote on last edited by
        #3

        I first try without defining enum after that try with enum. In both case I am getting compilation error.

        V 1 Reply Last reply
        0
        • R rajneshmalik

          I was trying to use win API

          GetComputerObjectNameW

          as below but I am getting error. Can someone help me.

          #include
          #include
          #include
          typedef enum {
          NameUnknown,
          NameFullyQualifiedDN,
          NameSamCompatible,
          NameDisplay,
          NameUniqueId,
          NameCanonical,
          NameUserPrincipal,
          NameCanonicalEx,
          NameServicePrincipal,
          NameDnsDomain,
          NameGivenName,
          NameSurname
          } EXTENDED_NAME_FORMAT, *PEXTENDED_NAME_FORMAT;

          int main()
          {
          EXTENDED_NAME_FORMAT enf = NameFullyQualifiedDN;
          LPWSTR pwszComputerName;
          DWORD dwLen;

              dwLen = 0;
              GetComputerObjectNameW(enf, NULL, &dwLen);
          
              pwszComputerName = new WCHAR\[dwLen + 1\];
              if(NULL == pwszComputerName)
              {
                  return 0;
              }
              if(!GetComputerObjectNameW(NameSamCompatible, pwszComputerName, &dwLen))
              {
                  delete pwszComputerName;
                  return 0;
              }
          
              sbstrTrustee = pwszComputerName;
              wprintf(L"GetComputerObjectName: %s\\n", pwszComputerName);
              delete pwszComputerName;
          

          }

          Some of Error message is as below.

          C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(117): error C2146: syntax error: missing ';' before identifier 'GetUserNameExA'
          C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(121): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
          C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(126): error C2086: 'BOOLEAN SEC_ENTRY': redefinition
          C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(117): note: see declaration of 'SEC_ENTRY'
          C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(126): error C2146: syntax error: missing ';' before identifier 'GetUserNameExW'
          C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(130): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Good morning, You are including the wrong header. Remove secext.h and add:

          #include

          The error message is telling you that it doesn't know the definition of SEC_ENTRY.

          1 Reply Last reply
          0
          • R rajneshmalik

            I first try without defining enum after that try with enum. In both case I am getting compilation error.

            V Offline
            V Offline
            Victor Nijegorodov
            wrote on last edited by
            #5

            Add these definition: #define _WIN32_WINNT 0x0500 #define SECURITY_WIN32 Remove the redefinition of enum. Define the sbstrTrustee variable. // edited: also don't forget to include the Secur32.lib library.

            R 1 Reply Last reply
            0
            • V Victor Nijegorodov

              Add these definition: #define _WIN32_WINNT 0x0500 #define SECURITY_WIN32 Remove the redefinition of enum. Define the sbstrTrustee variable. // edited: also don't forget to include the Secur32.lib library.

              R Offline
              R Offline
              rajneshmalik
              wrote on last edited by
              #6

              Hi Victor, I have modified program according to your suggestion but I am not getting expected result. I want to use NameFullyQualifiedDN enum value and get the fully qualified distinguished name (for example, CN=Jeff Smith,OU=Users,DC=Engineering,DC=Microsoft,DC=Com). Regards, Rajnesh

              V 1 Reply Last reply
              0
              • R rajneshmalik

                Hi Victor, I have modified program according to your suggestion but I am not getting expected result. I want to use NameFullyQualifiedDN enum value and get the fully qualified distinguished name (for example, CN=Jeff Smith,OU=Users,DC=Engineering,DC=Microsoft,DC=Com). Regards, Rajnesh

                V Offline
                V Offline
                Victor Nijegorodov
                wrote on last edited by
                #7

                Sorry, I don't know what is wrong/correct in your test. I've just tested your code and got the result in the form: [my_domain_name].[my_computer_name]$ wich is in my case 100% correct.

                R 1 Reply Last reply
                0
                • V Victor Nijegorodov

                  Sorry, I don't know what is wrong/correct in your test. I've just tested your code and got the result in the form: [my_domain_name].[my_computer_name]$ wich is in my case 100% correct.

                  R Offline
                  R Offline
                  rajneshmalik
                  wrote on last edited by
                  #8

                  Hi Victor, There was configuration issue with my windows laptop, so I was facing issue. Thanks for your feedback.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups