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. GetUserName() fails in ATL COM object

GetUserName() fails in ATL COM object

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++comquestion
4 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.
  • B Offline
    B Offline
    bryces
    wrote on last edited by
    #1

    Hi All, Does anyone know why I would get a first chance exception occur when I try to get the current Username in a COM object I have? the error message is as follows: First-chance exception in app.exe (SECUR32.DLL): 0xC0000005: Access Violation. The program 'C:\app.exe' has exited with code 0 (0x0). when all I am trying to do is LPTSTR username; DWORD cchBuff = 1024; BOOL result = GetUserName(username, &cchBuff); thanks for your help cheers Bryce

    M B 2 Replies Last reply
    0
    • B bryces

      Hi All, Does anyone know why I would get a first chance exception occur when I try to get the current Username in a COM object I have? the error message is as follows: First-chance exception in app.exe (SECUR32.DLL): 0xC0000005: Access Violation. The program 'C:\app.exe' has exited with code 0 (0x0). when all I am trying to do is LPTSTR username; DWORD cchBuff = 1024; BOOL result = GetUserName(username, &cchBuff); thanks for your help cheers Bryce

      M Offline
      M Offline
      Michael P Butler
      wrote on last edited by
      #2

      bryces wrote: LPTSTR username; DWORD cchBuff = 1024; BOOL result = GetUserName(username, &cchBuff); Well off the top of my head, Doesn't GetUserName require the buffer to have the memory allocated for the username string? I'd double check on MSDN. Michael Blue canary in the outlet by the light switch Who watches over you Make a little birdhouse in your soul - They Might Be Giants

      B 1 Reply Last reply
      0
      • M Michael P Butler

        bryces wrote: LPTSTR username; DWORD cchBuff = 1024; BOOL result = GetUserName(username, &cchBuff); Well off the top of my head, Doesn't GetUserName require the buffer to have the memory allocated for the username string? I'd double check on MSDN. Michael Blue canary in the outlet by the light switch Who watches over you Make a little birdhouse in your soul - They Might Be Giants

        B Offline
        B Offline
        bryces
        wrote on last edited by
        #3

        Hi Michael, Thanks, you are indeed correct. below is what is needed to be done: LPTSTR username; DWORD cchBuff = 1024; TCHAR tchBuffer[1024]; username = tchBuffer; //this is what I was missing... BOOL result = GetUserName(username, &cchBuff); cheers Bryce

        1 Reply Last reply
        0
        • B bryces

          Hi All, Does anyone know why I would get a first chance exception occur when I try to get the current Username in a COM object I have? the error message is as follows: First-chance exception in app.exe (SECUR32.DLL): 0xC0000005: Access Violation. The program 'C:\app.exe' has exited with code 0 (0x0). when all I am trying to do is LPTSTR username; DWORD cchBuff = 1024; BOOL result = GetUserName(username, &cchBuff); thanks for your help cheers Bryce

          B Offline
          B Offline
          BaldwinMartin
          wrote on last edited by
          #4

          #define MAX_LEN 255 CString str; char ch[MAX_LEN]; DWORD dwNameSize = MAX_LEN; GetUserName(ch, &dwNameSize); Best Wishes and Happy Holiday's, ez_way

          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