Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error C3861: '_tcsdup': identifier not found

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.

like image 822
forest.peterson Avatar asked Mar 13 '13 18:03

forest.peterson


2 Answers

Add the following include:

#include <tchar.h>
like image 171
Mike Kwan Avatar answered Sep 25 '22 19:09

Mike Kwan


_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

like image 39
Valeri Atamaniouk Avatar answered Sep 25 '22 19:09

Valeri Atamaniouk