tchar

Ejecting CDRom Drive without hardcoding drive letter using Win32 Visual C++

早过忘川 提交于 2021-01-29 06:11:48
问题 I am trying to eject my CDRom Drive at the click of a button. This works when the CDRom drive letter is hardcoded, but I am wanting to do it without hardcoding the CDRom Drive. If I find the CDRom drive on my computer and save it to 'TCHAR drive_letter', how can I pull that in to the code below? For some reason, it does not allow me to do 'EjectCdTray(drive_letter);'. The code is shown below: #include <tchar.h> #include <windows.h> #include <mmsystem.h> // for MCI functions // Link to winmm

How do you convert a 'System::String ^' to 'TCHAR'?

岁酱吖の 提交于 2020-01-11 10:25:32
问题 i asked a question here involving C++ and C# communicating. The problem got solved but led to a new problem. this returns a String (C#) return Marshal.PtrToStringAnsi(decryptsn(InpData)); this expects a TCHAR* (C++) lpAlpha2[0] = Company::Pins::Bank::Decryption::Decrypt::Decryption("123456"); i've googled how to solve this problem, but i am not sure why the String has a carrot(^) on it. Would it be best to change the return from String to something else that C++ would accept? or would i need

Converting _TCHAR* to char*

一曲冷凌霜 提交于 2020-01-11 05:30:10
问题 I'm trying to get a simple OpenCV sample working in C++ on Windows and my C++ is more than rusty. The sample is fairly simple: #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using namespace std; int main( int argc, char** argv ) { if( argc != 2) { cout <<" Usage: display_image ImageToLoadAndDisplay" << endl; return -1; } Mat image; image = imread(argv[1], IMREAD_COLOR); // Read the file if(! image.data ) // Check for invalid

How do I convert from _TCHAR * to char * when using C++ variable-length args?

你离开我真会死。 提交于 2019-12-30 08:20:48
问题 We need to pass a format _TCHAR * string, and a number of char * strings into a function with variable-length args: inline void FooBar(const _TCHAR *szFmt, const char *cArgs, ...) { //... } So it can be called like so: char *foo = "foo"; char *bar = "bar"; LogToFileA(_T("Test %s %s"), foo, bar); Obviously a simple fix would be to use _TCHAR instead of char, but we don't have that luxury unfortunately. We need to use this with va_start, etc so we can format a string: va_list args; _TCHAR szBuf

Is there a format specifier that always means char string with _tprintf?

天涯浪子 提交于 2019-12-23 09:09:51
问题 When you build an app on Windows using TCHAR support, %s in _tprintf() means char * string for Ansi builds and wchar_t * for Unicode builds while %S means the reverse. But are there any format specifiers that always mean char * string no matter if it's an Ansi or Unicode build? Since even on Windows UTF-16 is not really used for files or networking it turns out to still be fairly often that you'll want to deal with byte-based strings regardless of the native character type you compile your

should I eliminate TCHAR from Windows code?

浪子不回头ぞ 提交于 2019-12-22 04:14:19
问题 I am revising some very old (10 years) C code. The code compiles on Unix/Mac with GCC and cross-compiles for Windows with MinGW. Currently there are TCHAR strings throughout. I'd like to get rid of the TCHAR and use a C++ string instead. Is it still necessary to use the Windows wide functions, or can I do everything now with Unicode and UTF-8? 回答1: Windows uses UTF16 still and most likely always will. You need to use wstring rather than string therefore. Windows APIs don't offer support for

How to convert char* to TCHAR[ ]? [duplicate]

穿精又带淫゛_ 提交于 2019-12-19 09:03:24
问题 This question already has answers here : Convert char to TCHAR* argv[] (2 answers) Closed 6 years ago . char* stheParameterFileName = argv[1]; //I'm passing the file name as a parameter. TCHAR szName [512]; How can I convert char* to TCHAR [] ? 回答1: If you include the header file: #include "atlstr.h" Then you can use the A2T macro as below: // You'd need this line if using earlier versions of ATL/Visual Studio // USES_CONVERSION; char* stheParameterFileName = argv[1]; TCHAR szName [512];

cannot convert from 'const char *' to 'LPCTSTR'

雨燕双飞 提交于 2019-12-19 05:10:15
问题 I'm trying to convert string to 'LPCTSTR', but, i got following error. Error : cannot convert from 'const char *' to 'LPCTSTR' code: std::string str = "helloworld"; LPCTSTR lp = str.c_str(); Also, tried : LPCTSTR lp = (LPCTSTR)str.c_str(); But, print garbage value. 回答1: LPCTSTR means (long pointer to constant TCHAR string). A TCHAR can either be wchar_t or char based on what your project settings are. If, in your project settings, in the "General" tab, your character set is "Use Multi-byte

Convert char to TCHAR* argv[]

北城余情 提交于 2019-12-18 08:56:21
问题 How can I input text into TCHAR* argv[] ? OR: How can I convert from char to TCHAR* argv[] ? char randcount[] = "Hello world"; TCHAR* argv[]; argv = convert(randcount); 回答1: One way to do is: char a[] = "Hello world"; USES_CONVERSION; TCHAR* b = A2T(a); 回答2: /*This code did TCHAR in my project without A2T or any other converters. Char text is a some kind of array. So we can take letters one by one and put them to TCHAR. */ #include <iostream> TCHAR* Converter(char* cha) { int aa = strlen(cha)

Converting string to tchar in VC++

僤鯓⒐⒋嵵緔 提交于 2019-12-17 21:08:05
问题 how I can convert string to tchar in VC++? string internetprotocol="127.4.5.6"; TCHAR szProxyAddr[16]; i want to set: szProxyAddr=internetprotocol; how i can do it? 回答1: #include <atlstr.h> string internetprotocol="127.4.5.6"; TCHAR szProxyAddr[16]; _tcscpy_s(szProxyAddr, CA2T(internetprotocol.c_str())); _tcscpy_s is generic strcpy version which works both in Unicode and Multi-Character configurations. CA2T converts const char* to TCHAR* , according to szProxyAddr variable type. Be careful