no conversion from 'const char *' to 'TCHAR *'

Hi, I am trying to build this program,but I got this error :error C2446: ':' : no conversion from 'const char *' to 'TCHAR *'
I wonder if anyone could help me
kind regards,
mina


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Remote_test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "BCI2000Remote.h"
#include <string>
#include <vector>
#include <iostream>
int _tmain(int argc, TCHAR* argv[])
{
	// Instantiate a BCI2000Remote object
  BCI2000Remote bci;
  // Assume that Operator executable resides in the same directory as this program.
  std::string path = ( argc > 0 ) ? argv[0] : "";
  size_t pos = path.find_last_of( "\\/" );
  path = ( pos != std::string::npos ) ? path.substr( 0, pos + 1 ) : "";
  // Start the Operator module, and connect
  bci.OperatorPath( path + "Operator" );
  if( !bci.Connect() )
  {
    std::cerr << bci.Result();
    return -1;
  }
  // Startup modules
  const char* modules[] = { "SignalGenerator --LogMouse=1", "ARSignalProcessing", "CursorTask" };
  std::vector<std::string> vModules( &modules[0], &modules[0] + sizeof( modules ) / sizeof( *modules ) );
  if( !bci.StartupModules( vModules ) )
  {
    std::cerr << bci.Result();
    return -1;
  }
  // Load a parameter file, and set subject information
  bci.LoadParametersRemote( "../parms/examples/CursorTask_SignalGenerator.prm" );
  bci.SubjectID( "SUB" );
  // Start a run
  if( !bci.Start() )
  {
    std::cerr << bci.Result();
    return -1;
  }
  // Print feedback signal
  std::string state;
  while( bci.GetSystemState( state ) && state == "Running" )
  {
    double value = 0;
    bci.GetControlSignal( 1, 1, value );
    std::cout << "Control signal: " << value << ", press Enter to proceed" << std::flush;
    std::string line;
    std::getline( std::cin, line );
  }
	return 0;
}
The compiler is inticating a string conversion error; specifically, it says you're trying to mix narrow and wide strings. Those are, strings based on char and strings based on wchar_t.

That macro, TCHAR, varies depending on whether _UNICODE is defined or not.

In your case, you don't really care about converting from one string type to the next. You should switch off Unicode strings in your project. If you're using Visual Studio:
1. Open Project Properties
2. Go to Configuration Properties -> General
3. Go to Character Set setting
4. Select Not Set

If you're not using Visual Studio, do something similar to your environment. If you can't fiugure out what ot do, you can force it in your code by adding this to the top of your program:
1
2
3
4
#ifdef _UNICODE
#undef _UNICODE
#undef UNICODE
#endif 
thanks for quick answer! it help me to solve issue.
Last edited on
Yout should also replace

int _tmain(int argc, TCHAR* argv[])

with

int main(int argc, char* argv[])

if you just want to build ANSI (normal chars)

If BCI2000Remote is expecting chars, this should make the Unicode setting irrelevant.

Andy

PS it looks like your error prob occured on line 14 ? (of the posted code)
Last edited on
Topic archived. No new replies allowed.