473,388 Members | 1,480 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,388 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 12559

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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.