CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2006
    Posts
    300

    [RESOLVED] msoftcon.h error

    I'm trying to build this project from a lecture but ran into a problem. The code I wrote requires me to add msoftcon.cpp and msoftcon.h to the project and I received an error trying to build it.

    Code:
    'HANDLE CreateFileW(LPCWSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE)': cannot convert argument 1 from 'const char [8]' to 'LPCWSTR'
    
    Severity	Code	Description	Project	File	Line	Suppression State	Details
    Error (active)	E0167	argument of type "const char *" is incompatible with parameter of type "LPCWSTR" (aka "const WCHAR *")	Project2	C:\Users\rooth\source\repos\Project2\Project2\msoftcon.cpp	16
    Mind you it's referring to msoftcon.cpp, which I found and didn't do anything to except update _getch() because the former has been depreciated, but I can't move on until i figure this out.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,906

    Re: msoftcon.h error

    What is the line causing the error? Would you post it please.

    It looks like you're trying to pass a pointer to a char (char *) as a parameter to CreateFileW that is expecting a Unicode pointer (WCAHR*).

    Is your project set to use Unicode or ASCII? Usually you wouldn't use CreateFIleW() you'd just use CreateFile().
    If your project is set to use Unicode (and that is wanted) and you want to pass a char* then use CreateFIleA() instead of CreateFIleW()
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Nov 2006
    Posts
    300

    Re: msoftcon.h error

    Quote Originally Posted by 2kaud View Post
    What is the line causing the error? Would you post it please.

    It looks like you're trying to pass a pointer to a char (char *) as a parameter to CreateFileW that is expecting a Unicode pointer (WCAHR*).

    Is your project set to use Unicode or ASCII? Usually you wouldn't use CreateFIleW() you'd just use CreateFile().
    If your project is set to use Unicode (and that is wanted) and you want to pass a char* then use CreateFIleA() instead of CreateFIleW()

    It was the call to CreateFile in this code. Both the .cpp and .h files are required in your project to draw colorful circles in the console.

    Solution: 1. Use Wide String Literals: If you're using string literals, prefix them with L to create wide string literals. For example, "Hello" becomes L"Hello".

    Code:
    hConsole = CreateFile(L"CONOUT$", GENERIC_WRITE | GENERIC_READ,
                       FILE_SHARE_READ | FILE_SHARE_WRITE,
                       0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L);  // This is the line that throws an error
    As it turns out trying to build this will yield a bunch of errors, putch() is depreciated so you have to use _putch and you have to add L for Wide String Literals. See Microsoft Learn for more details.
    Solved.
    Last edited by dellthinker; June 30th, 2025 at 09:32 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured