因此,函数 GetUserName() 的输出将用户名作为 LPTSTR。我需要将其转换为 LPCSTR,因为我希望用户名是 ftp 目录的名称。
TCHAR id [UNLEN+1];
DWORD size = UNLEN+1;
GetUserName(id, &size); // this is an LPTSTR
FtpCreateDirectory(hFtpSession,id) // 2d parameter should be an LPCSTR
Run Code Online (Sandbox Code Playgroud)
问题是我需要将 LPTSTR 字符串转换为 LPCSTR 字符串。现在我知道了:
LPTSTR 是一个(非常量)TCHAR 字符串,而 LPCSTR 是一个常量字符串。
但是如何将 TCHAR 转换为 const 字符串?
我应该注意我没有丰富的编程/C++ 背景,我还应该注意我正在编译多字节,而不是 unicode。
我试图将const char*转换为LPTSTR.但我不想使用USES_CONVERSION来执行此操作.
以下是我用于使用USES_CONVERSION转换的代码.有没有办法转换使用sprintf或tcscpy等..?
USES_CONVERSION;
jstring JavaStringVal = (some value passed from other function);
const char *constCharStr = env->GetStringUTFChars(JavaStringVal, 0);
LPTSTR lpwstrVal = CA2T(constCharStr); //I do not want to use the function CA2T..
Run Code Online (Sandbox Code Playgroud) 我正在将Windows库转换为linux.我需要在linux中找到LPTSTR和LPCSTR.
我知道我可以使用wchar_t可以使用,但我不确定使用它.
使用LPTSTR的方法之一如下:
void ErrorExit(LPTSTR zFunction)
{
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激!
这是我的第一次,我想使用Windows CreateProcess函数进行并行处理.根据MSDN上的示例,我创建了一个LPTSTR
"(非常量)TCHAR字符串" 命令行参数,如下所示
LPTSTR szCmdline[] = _tcsdup(TEXT("\C:\\MyProgram_linux_1.1\\MyProgram.exe") );
Run Code Online (Sandbox Code Playgroud)
这里讨论 LPTSTR和其他char和字符串类型
命令行参数传递给CreateProcess
这样
if (!CreateProcess(NULL, szCmdline, /*...*/) ) cout << "ERROR: cannot start CreateProcess" << endl;
Run Code Online (Sandbox Code Playgroud)
并且这些标题存在
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <strsafe.h>
#include <direct.h>
Run Code Online (Sandbox Code Playgroud)
在编译时这是错误:
error C3861: '_tcsdup': identifier not found
Run Code Online (Sandbox Code Playgroud)
搜索此错误发现相同的错误,但解决方案特定于使用.NET框架而不是解释error C3861: '_tcsdup'
不知道是否有关,但也有一个error C2059: syntax error : ')'
上if (!CreateProcess(NULL, szCmdline, /*...*/) ) cout << "ERROR: cannot start CreateProcess" << endl;
这个错误是如何修复的?而且,这是怎么回事?
此外,我正在使用CreateProcess
学习Linux …
我需要创建一个变量来使用CreateProcess
:
CreateProcess(z7Cmdline, z7Arg, NULL, NULL, FALSE, NULL, NULL, NULL, &startInfo, &processInfo);
Run Code Online (Sandbox Code Playgroud)
变量z7Arg是7 -zip的参数列表,其中包含基于当前日期的文件名,即:2017-12-13.zip.
string buArg = "-o""c:\\moshe"" a " + buDir + buFileName + "c:\\moshe\\*.pdf";
Run Code Online (Sandbox Code Playgroud)
我想将buArg复制到z7Arg作为LPTSTR,以便在CreateProcess例程中使用
我该怎么办呢?
我是C++编码的新手,30年前我使用IBM Fortran和汇编语言为Grumman Aerospace编写程序,但从那以后我做了很少的编码.
我在创建进程时传递一些数字参数(在VC++中)
我坚持将LPTSTR转换为int.
提前致谢.
可能重复:
将lptstr转换为char*
我需要转换LPTSTR p
为CHAR ch[]
.我是C++的新手.
#include "stdafx.h"
#define _WIN32_IE 0x500
#include <shlobj.h>
#include <atlstr.h>
#include <iostream>
#include <Strsafe.h>
using namespace std;
int main(){
int a;
string res;
CString path;
char ch[MAX_PATH];
LPTSTR p = path.GetBuffer(MAX_PATH);
HRESULT hr = SHGetFolderPath(NULL,CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, p);
/* some operation with P and CH */
if(SUCCEEDED(hr))
{ /* succeeded */
cout << ch;
} /* succeeded */
else
{ /* failed */
cout << "error";
} /* failed */
cin >> …
Run Code Online (Sandbox Code Playgroud) 我需要转换:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839(v=vs.85).aspx
lpstrFileTitle
Type: LPTSTR
The file name and extension (without path information) of the selected file. This member can be NULL.
Run Code Online (Sandbox Code Playgroud)
即使在MSVC++ 2012 Express中,它也说它的LPSTR.
至
http://msdn.microsoft.com/en-us/library/windows/desktop/bb172802(v=vs.85).aspx
pSrcFile [in]
Type: LPCTSTR
Pointer to a string that specifies the filename. If the compiler settings require Unicode, the data type LPCTSTR resolves to LPCWSTR. Otherwise, the string data type resolves to LPCSTR. See Remarks.
Run Code Online (Sandbox Code Playgroud)
我非常感谢.:)
char szFileName[MAX_PATH] = {0};
char szFileTitleName[MAX_PATH] = {0};
HRESULT hr = S_OK;
RtlZeroMemory(&gc.ofn, sizeof(gc.ofn));
gc.ofn.lStructSize = sizeof(gc.ofn); …
Run Code Online (Sandbox Code Playgroud) 我似乎在将字节数组(包含word文档中的文本)转换为LPTSTR(wchar_t*)对象时遇到问题.每次代码执行时,我都会收到一堆不需要的Unicode字符.
我认为这是因为我没有在某个地方进行正确的调用,或者没有正确使用变量,但不太确定如何处理这个问题.希望这里有人可以指导我朝着正确的方向前进.
我们首先调用C#代码来打开Microsoft Word并将文档中的文本转换为字节数组.
byte document __gc[];
document = word->ConvertToArray(filename);
Run Code Online (Sandbox Code Playgroud)
文件内容如下:
{84, 101, 115, 116, 32, 68, 111, 99, 117, 109, 101, 110, 116, 13, 10}
Run Code Online (Sandbox Code Playgroud)
最终成为以下字符串:"测试文档".
我们的下一步是分配内存以将字节数组存储到LPTSTR变量中,
byte __pin * value;
value = &document[0];
LPTSTR image;
image = (LPTSTR)malloc( document->Length + 1 );
Run Code Online (Sandbox Code Playgroud)
一旦我们执行了开始分配内存的行,我们的图像变量就会被一堆不需要的Unicode字符填充:
?????????????????
Run Code Online (Sandbox Code Playgroud)
然后我们做一个memcpy来传输所有数据
memcpy(image,value,document->Length);
Run Code Online (Sandbox Code Playgroud)
这只会导致出现更多不需要的Unicode字符:
?????????????????
Run Code Online (Sandbox Code Playgroud)
我认为我们遇到的问题要么与我们如何在字节数组中存储值有关,要么与我们将数据从字节数组复制到LPTSTR变量有关.任何帮助解释我做错了什么,或任何指向我正确方向的任何帮助将不胜感激.
我正在Visual Studio 2013上编写C++ DLL.我的dll应该从ini文件中读取参数.所以,我为此创建了一个函数(ReadConnectionSettings()).我的静态变量serverIP在函数工作期间正确获取值,但是一旦函数完成运行,变量(serverIP)就会丢失其值.什么似乎是问题?
static LPTSTR serverIP = _TEXT("");
void ReadConnectionSettings()
{
TCHAR url[256];
GetPrivateProfileString(_T("Connection"), _T("Url"), _T(""), url, 256, NameOfIniFile);
serverIP = url;
}
Run Code Online (Sandbox Code Playgroud)