How to convert cstrint to char*

ankurk's Avatar, Join Date: Aug 2007
Go4Expert Member
hi i want a to convert cstring variable contents into char *;


how can i convert it, actually problem is that cstring variable is of textbox n i want to pass the contents to a function which takes parameters as char *.



Thanks!!!
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Use the GetBuffer function but remember to use the ReleaseBuffer after you are done.
ankurk's Avatar, Join Date: Aug 2007
Go4Expert Member
could you give me a snippet plz. i am working on windows ce actually
ankurk's Avatar, Join Date: Aug 2007
Go4Expert Member
getbuffer does'nt work , i get only the first character of string not the whole string, could there be any problem due to character set in windows ce?
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
If you are using some compiler and an IDE you should be fine using the . to get the function.
ankurk's Avatar, Join Date: Aug 2007
Go4Expert Member
i am using microsoft embedded c++ , compiler
n no probs with .(dot).
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
So you should be able to use the functions I mention above. Why don't you give a try.
ankurk's Avatar, Join Date: Aug 2007
Go4Expert Member
i tried but getbuffer() only gives me the first character of the string not the whole string
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
It has a parameter where you can specify the number of characters. Refer - http://msdn2.microsoft.com/en-us/library/ms928943.aspx
ankurk's Avatar, Join Date: Aug 2007
Go4Expert Member
look i have this problem
Code:
int let;
 CString browse_file_name = " \\system\\texFile.TXT";

const char * argument = browse_file_name.Getbuffer(browse_file_name.GetLength());

FILE * file = fopen(argument,"r");
	if(!file)
	{
		let = GetLastError();
		MessageBox(_T("ERROR! file not found ..."));
		exit(0);
	}
	else
		MessageBox(_T("OK File found ..."));
now the thing is that the variable argument does not get the whole path , just "\" only....
please help

i am using microsoft embedded vc++ compiler.

Last edited by shabbir; 11Oct2007 at 13:01.. Reason: Code block