error C3861: '_tcsdup': identifier not found

蓝咒 提交于 2019-12-10 13:57:35

问题


This is my first time and I'd like to make a parallel process using the windows CreateProcess function. Based on the example at MSDN I created a LPTSTR "(non-const) TCHAR string" command line argument like this

LPTSTR szCmdline[] = _tcsdup(TEXT("\C:\\MyProgram_linux_1.1\\MyProgram.exe") );

The LPTSTR and other char and string types are discussed here

The command line argument is passed to CreateProcess like this

if (!CreateProcess(NULL, szCmdline, /*...*/) ) cout << "ERROR: cannot start CreateProcess" << endl;

And these headers are present

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <strsafe.h>
#include <direct.h>

On compile this is the error:

error C3861: '_tcsdup': identifier not found

A search for this error found the same error but the solution was specific to using a .NET framework rather than explaining the error C3861: '_tcsdup'

Not sure if it related but there is also an error C2059: syntax error : ')' on the if (!CreateProcess(NULL, szCmdline, /*...*/) ) cout << "ERROR: cannot start CreateProcess" << endl;

How is this error fixed? And, what is going on with this?

Also, I am using the CreateProcess as a learning step towards learning the Linux fork() function - the Visual Studio interface is easier for me to use and once this is debugged and works, I will change to the g++ interface and change to fork() and debug from there - so a solution that leads to fork(), if possible, is the most beneficial.


回答1:


Add the following include:

#include <tchar.h>



回答2:


_tcsdup is a macro, that maps to implementation function depending on your Unicode settings. As you have not included a header file (tchar.h) the compiler thinks it is a symbol and emits wrong code.

Depending on actual locate settings _tcsdump maps to one of those:

  • _strdup
  • _mbsdup
  • _wcsdup

http://msdn.microsoft.com/en-us/library/y471khhc(v=vs.110).aspx



来源:https://stackoverflow.com/questions/15393218/error-c3861-tcsdup-identifier-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!