Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   How to convert cstrint to char* (http://www.go4expert.com/forums/convert-cstrint-char-t6753/)

ankurk 9Oct2007 19:01

How to convert cstrint to char*
 
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!!! :D

shabbir 9Oct2007 21:03

Re: How to convert cstrint to char*
 
Use the GetBuffer function but remember to use the ReleaseBuffer after you are done.

ankurk 10Oct2007 12:57

Re: How to convert cstrint to char*
 
could you give me a snippet plz. i am working on windows ce actually

ankurk 10Oct2007 13:34

Re: How to convert cstrint to char*
 
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 10Oct2007 13:40

Re: How to convert cstrint to char*
 
If you are using some compiler and an IDE you should be fine using the . to get the function.

ankurk 10Oct2007 15:55

Re: How to convert cstrint to char*
 
i am using microsoft embedded c++ , compiler
n no probs with .(dot).

shabbir 10Oct2007 15:58

Re: How to convert cstrint to char*
 
So you should be able to use the functions I mention above. Why don't you give a try.

ankurk 10Oct2007 16:59

Re: How to convert cstrint to char*
 
i tried but getbuffer() only gives me the first character of the string not the whole string

shabbir 10Oct2007 18:48

Re: How to convert cstrint to char*
 
It has a parameter where you can specify the number of characters. Refer - http://msdn2.microsoft.com/en-us/library/ms928943.aspx

ankurk 11Oct2007 12:41

Re: How to convert cstrint to char*
 
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.


All times are GMT +5.5. The time now is 07:22.