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. AllocConsole

AllocConsole

Scheduled Pinned Locked Moved C / C++ / MFC
csharpvisual-studioquestion
3 Posts 2 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.
  • M Offline
    M Offline
    mcsherry
    wrote on last edited by
    #1

    When I use the WriteConsole method I always get a "First-chance exception in FileBinary.exe (KERNEL32.DLL): 0xC0000005: Access Violation." in the output window within Visual Studio, however the text that I sent in the WriteConsole method appears correctly on the console window. Does anyone know what I am doing wrong (I've attatched some sample code below which just sends an end of line to the console, AllocConsole has already been called elsewhere in my program)? LPDWORD s = 0 ; CString myStr = "\n" ; HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE ) ; WriteConsole ( h, myStr , myStr.GetLength ( ), s, NULL ) ; cheers, Andy

    O 1 Reply Last reply
    0
    • M mcsherry

      When I use the WriteConsole method I always get a "First-chance exception in FileBinary.exe (KERNEL32.DLL): 0xC0000005: Access Violation." in the output window within Visual Studio, however the text that I sent in the WriteConsole method appears correctly on the console window. Does anyone know what I am doing wrong (I've attatched some sample code below which just sends an end of line to the console, AllocConsole has already been called elsewhere in my program)? LPDWORD s = 0 ; CString myStr = "\n" ; HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE ) ; WriteConsole ( h, myStr , myStr.GetLength ( ), s, NULL ) ; cheers, Andy

      O Offline
      O Offline
      One Stone
      wrote on last edited by
      #2

      LPDWORD is a pointer. You need to pass a valid memory location to the WriteConsole function, not just a random pointer. Also, cast the CString to a LPCTSTR manually, before turning it into a VOID*.

      DWORD s = 0 ;
      CString myStr = "\n";
      HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
      WriteConsole(h, (LPCTSTR)myStr, myStr.GetLength(), &s, NULL);

      M 1 Reply Last reply
      0
      • O One Stone

        LPDWORD is a pointer. You need to pass a valid memory location to the WriteConsole function, not just a random pointer. Also, cast the CString to a LPCTSTR manually, before turning it into a VOID*.

        DWORD s = 0 ;
        CString myStr = "\n";
        HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
        WriteConsole(h, (LPCTSTR)myStr, myStr.GetLength(), &s, NULL);

        M Offline
        M Offline
        mcsherry
        wrote on last edited by
        #3

        thanks for your very quick reply, I'll give that a try. Andy

        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