Thread: Data type error when converting an old WinAPI C++ code as a new VS 2022 C++ project

  1. #1
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470

    Question Data type error when converting an old WinAPI C++ code as a new VS 2022 C++ project

    Hi all.

    I'm trying to write this code from an old WinAPI C++ book (code snippet Image at the bottom) into a new C++ project. What it does is create a clone process. But when i code it into VS 2022, I get the error:
    Code:
    "Argument of type "TCHAR *" is incompatible with parameter of type "char *" "
    at line-17 (sprintf, 1st arg, below code). What's causing this please? And how to fix it?

    Data type error when converting an old WinAPI C++ code as a new VS 2022 C++ project-2022-10-14-14-26-37-jpg

    VS 2022

    Data type error when converting an old WinAPI C++ code as a new VS 2022 C++ project-2022-10-14-14-16-18-jpg

    VC 6.0
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    A couple of things.

    1. In modern C++, you should use this in place of include <stdio.h>
    #include <cstdio>

    2. When dealing with anything TCHAR, you need to be aware of the "Generic-Text Routine Mappings"
    _scprintf, _scprintf_l, _scwprintf, _scwprintf_l | Microsoft Learn

    Back in VC6 days, TCHAR was just char, so it was easy to be lazy and use the ISO standard name for the function.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    Quote Originally Posted by Salem View Post
    A couple of things.

    1. In modern C++, you should use this in place of include <stdio.h>
    #include <cstdio>

    2. When dealing with anything TCHAR, you need to be aware of the "Generic-Text Routine Mappings"
    _scprintf, _scprintf_l, _scwprintf, _scwprintf_l | Microsoft Learn

    Back in VC6 days, TCHAR was just char, so it was easy to be lazy and use the ISO standard name for the function.
    Thanks that helped. Sorry, been with C# for last the decade, I lost my touch with C++. Thought to relearn.

    Anyways, when I did this, i got the error:
    Code:
    const variable "szCommandLine" requires an initializer
    Code:
    const char szCommandLine[MAX_PATH];
     _scprintf(szCommandLine, "\"%s\" %d", szfilename, nCloneID);
    And by the way, where can I find out how to properly call the old API functions (back in VC6 days) now in VS 2022? Maybe kinda like a guide for people who're returning to C++?, if there's such a thing.

    Thanks
    Last edited by geek@02; 10-15-2022 at 07:39 AM.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Why would you be declaring it const, if you intend to modify it with the sprintf?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    Quote Originally Posted by Salem View Post
    Why would you be declaring it const, if you intend to modify it with the sprintf?
    My mistake!
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Handling error data type
    By ming..c in forum C Programming
    Replies: 1
    Last Post: 11-17-2013, 03:20 AM
  2. Error to define data type File* ????
    By zmhnak in forum C Programming
    Replies: 1
    Last Post: 03-21-2013, 07:19 AM
  3. Replies: 1
    Last Post: 02-16-2013, 09:44 PM
  4. Data type mismatch in criteria expression ERROR
    By Aga^^ in forum C# Programming
    Replies: 2
    Last Post: 02-11-2009, 01:21 AM
  5. Replies: 6
    Last Post: 07-11-2007, 03:07 AM

Tags for this Thread