473,695 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LPTSTR to char *.. How

Hi ,
is this correct to have final LPTSTR to char *

CString fname(argv [1]);
LPTSTR p1 = fname.GetBuffer (fname.GetLengt h());
char teststr[1000];
sprintf(teststr ,"%s",p1); //or
strcpy(teststr, p1);

is this code to have my null terminated teststr.
Thanks
free2cric
Jul 23 '05 #1
3 12581

free2cric wrote:
Hi ,
is this correct to have final LPTSTR to char *

CString fname(argv [1]);
LPTSTR p1 = fname.GetBuffer (fname.GetLengt h());
char teststr[1000];
sprintf(teststr ,"%s",p1); //or
strcpy(teststr, p1);

is this code to have my null terminated teststr.
Thanks
free2cric


Much better is to use std::string class and c_str() method.

Jul 23 '05 #2
free2cric wrote:
Hi ,
is this correct to have final LPTSTR to char *

CString fname(argv [1]);
LPTSTR p1 = fname.GetBuffer (fname.GetLengt h());
char teststr[1000];
sprintf(teststr ,"%s",p1); //or
strcpy(teststr, p1);

is this code to have my null terminated teststr.
Thanks
free2cric


LPTSTR and CString are Microsoft specific types,
and best discussed in a Microsoft newsgroup.
Read the FAQs and welcome.txt below for newsgroup
suggestions.

A more portable type is std::string from the
STL.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Jul 23 '05 #3
I agree with the others regarding string. However, if you are stuck on
CString's, you can do

CString fname(argv[1]);
char teststr[1000];
strcpy( teststr, (LPCTSTR) fname );
"free2cric" <fr*******@yaho o.com> wrote in message
news:e8******** *************** ***@posting.goo gle.com...
Hi ,
is this correct to have final LPTSTR to char *

CString fname(argv [1]);
LPTSTR p1 = fname.GetBuffer (fname.GetLengt h());
char teststr[1000];
sprintf(teststr ,"%s",p1); //or
strcpy(teststr, p1);

is this code to have my null terminated teststr.
Thanks
free2cric

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
10183
by: sorty | last post by:
Hi, I have read in many places that TCHAR can be 'char' or 'wchar_t' depending on ANSI or UNICODE. I have also read that LPTSTR is a long pointer to a TCHAR. I am confused about the following. Please answer with yes/no and then elaborate as you please..
9
25846
by: alex | last post by:
how do i initialize an LPTSTR variable? i'm trying to call a microsoft function LONG QueryStringValue( LPCTSTR pszValueName, LPTSTR pszValue, ULONG* pnChars ) throw( );pszValue is supposed to get the value i want but i need to initialize it before i pass it to QueryStringValue, how do i initialize
3
1351
by: free2cric | last post by:
Hi , is this correct to have final LPTSTR to char * CString fname(argv ); LPTSTR p1 = fname.GetBuffer(fname.GetLength()); char teststr; sprintf(teststr,"%s",p1); //or strcpy(teststr,p1); is this code to have my null terminated teststr.
1
5981
by: Steven Blair | last post by:
Hi there. Having a problem calling a win32 function from a dll. Here is the function header: DWORD thrdGetHcNum (DWORD nPort, DWORD nBaudrate, LPTSTR lpszHcNum) //Description of the 3rd parameter LpszHcNum: The head of the buffer area used to store the serial number of the terminal, 9 bytes at least.
3
4371
by: Mark | last post by:
Help please... i am VERY new to the managed C++ and i need to take a System::String* and cast it to an LPTSTR how might i do this? I have searched the web and groups but cannot find any examples. -thanks
1
2614
by: Lewap | last post by:
Hi! I've piece of code like follow: <code> LPTSTR lpszPipename = (LPTSTR) "\\\\.\\pipe\\testpipe"; hPipe = CreateNamedPipe(
8
5765
by: **Developer** | last post by:
Been reading some of the Marshal doc and am a little confused. Anyway, I've been using the following and it works OK. Public Declare Auto Function SHGetFolderPath Lib "shell32.dll" (ByVal hWnd As Integer, _ ByVal nFolder As Integer, ByVal nToken As Integer, _ ByVal dwFlags As Integer, _
6
14341
by: pskumaran | last post by:
Hi All, I am trying to convert LPTSTR to char* by using sprintf, But sprintf copies only the first character from the string. i tried both array and pointer also , but the result is same. Here is my code... LPTSTR TestStr= _T("Test String"); char s1; char *s2; s2 = (char *) malloc(1000*sizeof(char)); sprintf(s1,"%s",TestStr);
2
17713
by: sudhivns | last post by:
Hi, How to convert LPTSTR to char*.? Thanks in advance. Bye
0
8587
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9140
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9005
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8867
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8841
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3025
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2291
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.