473,396 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

LPTSTR to char *.. How

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

CString fname(argv [1]);
LPTSTR p1 = fname.GetBuffer(fname.GetLength());
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 12560

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

CString fname(argv [1]);
LPTSTR p1 = fname.GetBuffer(fname.GetLength());
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.GetLength());
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.learn.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*******@yahoo.com> wrote in message
news:e8**************************@posting.google.c om...
Hi ,
is this correct to have final LPTSTR to char *

CString fname(argv [1]);
LPTSTR p1 = fname.GetBuffer(fname.GetLength());
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
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...
9
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...
3
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); ...
1
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...
3
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....
1
by: Lewap | last post by:
Hi! I've piece of code like follow: <code> LPTSTR lpszPipename = (LPTSTR) "\\\\.\\pipe\\testpipe"; hPipe = CreateNamedPipe(
8
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...
6
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...
2
by: sudhivns | last post by:
Hi, How to convert LPTSTR to char*.? Thanks in advance. Bye
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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...
0
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...

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.