How to convert cstrint to char*

Go4Expert Member
9Oct2007,19:01   #1
ankurk's Avatar
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!!!
Go4Expert Founder
9Oct2007,21:03   #2
shabbir's Avatar
Use the GetBuffer function but remember to use the ReleaseBuffer after you are done.
Go4Expert Member
10Oct2007,12:57   #3
ankurk's Avatar
could you give me a snippet plz. i am working on windows ce actually
Go4Expert Member
10Oct2007,13:34   #4
ankurk's Avatar
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?
Go4Expert Founder
10Oct2007,13:40   #5
shabbir's Avatar
If you are using some compiler and an IDE you should be fine using the . to get the function.
Go4Expert Member
10Oct2007,15:55   #6
ankurk's Avatar
i am using microsoft embedded c++ , compiler
n no probs with .(dot).
Go4Expert Founder
10Oct2007,15:58   #7
shabbir's Avatar
So you should be able to use the functions I mention above. Why don't you give a try.
Go4Expert Member
10Oct2007,16:59   #8
ankurk's Avatar
i tried but getbuffer() only gives me the first character of the string not the whole string
Go4Expert Founder
10Oct2007,18:48   #9
shabbir's Avatar
It has a parameter where you can specify the number of characters. Refer - http://msdn2.microsoft.com/en-us/library/ms928943.aspx
Go4Expert Member
11Oct2007,12:41   #10
ankurk's Avatar
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