|
Hello All
I am using english OS WIN XP, in which Japanese character can be used using Microsft IME.
The file names are stored in a text file which is SHIFT-JIS encoding.
when I read the file names form the file using I am getting some encoded file name in a charcter buffer.
fgets( szFilename, pFP );
fills the szFileName with character that is not the same of the filename.
But I want to open the file after reading the filenames from the text file
i.e I want this two step
fgets(szFilename, pFP);
fopen( szFileName, "r");
I know the problem is in character encoding. But can't find any solution. Any hiht to proceed please
Regards
Anil
|
|
|
|
|
Use WideCharToMultiByte()
Rinu Raj
|
|
|
|
|
Thank you very much.
I was able to do it with the above funtion. forgot to thank you on that day
Regards
Anil
|
|
|
|
|
Hello comunity,
it is posible to modify an content from an LPCTSTR variable!?
Example:
<code>
CString csStringContent = "This is an String";
LPCTSTR lpsz = csStringContent;
</code>
with best regards
break;
|
|
|
|
|
break; wrote: CString csStringContent = "This is an String"; // modify to "This is String" or replace a part of themLPCTSTR lpsz = csStringContent;// modify lpsz?
with best regards
csStringContent = "This is String";
LPTSTR lpsz = csStringContent.GetBuffer();
lpsz[0] = _T( 't' );
csStringContent.ReleaseBuffer(); Or
csStringContent = "This is String";
LPCTSTR lpszC = csStringContent;
LPTSTR lpsz[0] = const_cast< LPTSTR >( lpsz );
lpsz[0] = _T( 't' );
|
|
|
|
|
Nibu babu thomas wrote: CString csStringContent = "This is an String"; // modify to "This is String" or replace a part of themLPCTSTR lpsz = csStringContent;// modify lpsz?
Generally, if you want to modify the LPCTSTR, then you are making something wrong.
You can:
1. csStringContent[0] = 'a';
2. use various member function of CString
3. use CString only when necessary:
TCHAR str[100] = "This is a string";<br />
_tcscpy(str[2], "aaa";<br />
CString cstr = str;
4. use CString::GetBuffer() as already described;
Playing with the LPCTSTR ... no way.
|
|
|
|
|
Agreed, casting the const away as done above is not on - I'd fire someone for doing this.
Steve
|
|
|
|
|
Your second method is just plain evil - although you mentioned it sould be avoided I'd go as for as to say you shouldn't have even mentioned it as an option. Even if it works on one MFC verion it may stop working in a later version.
Steve
|
|
|
|
|
Stephen Hewitt wrote: Your second method is just plain evil - although you mentioned it sould be avoided I'd go as for as to say you shouldn't have even mentioned it as an option. Even if it works on one MFC verion it may stop working in a later version.
Sometimes when you don't have any other option you are forced to do this. But it should be avoided. I just mentioned this so that if he didn't have any other option he can use this. I just went for his question.
|
|
|
|
|
Hello,
i dont need to delete some chars from the LPCTSTR, it is ok when i can change them,
my solution is this:
<code>
LPCTSTR lpsz = csContent.GetBuffer();
LPSTR lpstr = (LPSTR) lpsz;
while(*lpstr)
{
if(something)
{
_strnset(lpstr, ' ', 1);
}
}
</code>
regards
break;
|
|
|
|
|
GetBuffer returns a non-const pointer. Make your code look like this:
LPTSTR lpsz = csContent.GetBuffer(100);
csContent.ReleaseBuffer();
You don't need to have a LPCTSTR which you cast to LPSTR ; this is strange and confusing to say the least. Also note that you need to call ReleaseBuffer and that GetBuffer takes a minimum buffer size parameter.
You should not be calling GetBuffer at all however: this is designed when you need to manipulate the contents of a CString with code that doesn't know anything about CString s. If your writing code to manipulate the CString you should use its member functions. Why use a string wrapper if you're just going to get a pointer to the underlying buffer and manipulate it directly?
What exactly are you tring to do?
Steve
|
|
|
|
|
Hello,
i dont need to delete some chars from the LPCTSTR, it is ok when i can change them,
my solution is this:
<code>
LPCTSTR lpsz = csContent.GetBuffer();
LPSTR lpstr = (LPSTR) lpsz;
while(*lpstr)
{
if(something)
{
_strnset(lpstr, ' ', 1);
}
}
</code>
regards
break;
|
|
|
|
|
There are several things wrong with what you are asking, and I'll try to hit on a few of them.
1) You are using CString, which gives you access to the buffer, will manage the memory for you, and can be modified in many ways using its given member functions ... yet you want to grab the buffer from it and operate on it yourself? To me, this indicates that you haven't read the documentation on what CString actually does for you.
2) LPCTSTR stands for "long pointer to a constant t-string". You do NOT want to modify a constant, period. Casting away the const (which is what your "solution" code is doing) is both dangerous and wrong.
3) Because you called GetBuffer, and never called ReleaseBuffer, you created a memory leak. This problem goes away immediately when you fix #1 by using CString's methods.
A much better solution would be to do something along the lines of this:
csContent.Replace(SomeValueIWantChanged, _T(' '));
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hello,
thanx for answer, well, i read about CString and i love it to use, and i use it hier only for posting, in real the source come from a file, open with fopen();
maybe from an html file to.I need some quick method to lookup through a file, and this file can be wery large.
I dont know if the CString functions like CString::Find() or CString::FindFirst() are the quickest for this!
Also, the source is an stream, file stream!
That is the cause why i ask about!
with best regards!
break;
|
|
|
|
|
Consider using OpenFile or ofstream to open the file instead of fopen. Also, if you use ofstream, you can use the string class instead of CString. It has similar functions to CString, and you also gain the ability to use some of the more complex STL algorithms if you need them.
I'm assuming this is an actual file you are opening (that is, it isn't a serial port) so if you wanted to, you could easily load the entire file into memory to parse it.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi all,
I have designed a MFC based Dialog application. I have a parent dialog and a corresponding child dialog.
My requirement is this. My parent dialog has a edit box. Which should display value form 0 to n without stopping although the child window is opened or closed.
Just like a clock it should be incrementing the value by itself. Which function do u suppose can be used to achieve this?
I tried WM_TIMER but to no avail. It increments once and then stops.
Please some one tell me as to which function or handle can accomplish this.
Thanks and Regards in Advance
Kenny
|
|
|
|
|
Use a thread function to implement the edit box updation.
Threadproc()
{
m_edit = 1; // edit box member variable
while( 1 )
{
m_edit++
UpdateData(FALSE);
sleep( 10 )
if( m_edit == n ) // return if n is reached
{
return;
}
}
Rinu Raj
|
|
|
|
|
Hi all,
I want to draw some diagrams (rectangles ...etc) and put text in to it..
I have used TextOut() function to write the text...
But I want to reduce the font size ....
Now it takes current font settings of Device Context...
How do I make it ?
Thanks in advance....
vinsankar
|
|
|
|
|
Hi
Use CreateFont to set font size.
Attach font object to dc using SelectObject
KK
|
|
|
|
|
Are you using the original (default) font in the DC, or have you selected your own in? I'm guessing the former, since if you were selecting them in, you'd just create a smaller one.
Steve S
Developer for hire
|
|
|
|
|
You can use of CreateFont and SelectObject but in the end use CFont::DeleteObject and also you can use of CreateFontIndirect
|
|
|
|
|
I create an 'Win32 Console Application' "Program01" in VC6 as follows,
#include "stdafx.h" #include "Class.h"<br />
int main(int argc, char* argv[]){<br />
Class<int> a;<br />
int b = a.GetValue(1729);<br />
printf("\n\t");<br />
return 0;<br />
}<br />
<br />
#include "stdafx.h" #include "Class.h"<br />
template <class T><br />
Class<T>::Class(){<br />
}<br />
template <class T><br />
Class<T>::~Class(){<br />
}<br />
template <class T><br />
int Class<T>::GetValue(int value){<br />
return value;<br />
}<br />
<br />
template <class T> class Class{<br />
public:<br />
Class();<br />
virtual ~Class();<br />
int GetValue(int value);<br />
};
It shows Linking error for the member functions of class. But when I remove template from Class the program runs well; even when I write all code (Class with template) in single "Program01.cpp" File then also it runs well.
Then what might be the problem in the above code?
-- modified at 4:03 Friday 15th September, 2006
|
|
|
|
|
|
Aniket Salunkhe wrote: It shows Linking error for the member functions of class. But when I remove template from Class the program runs well; even when I write all code (Class with template) in single "Program01.cpp" File then also it runs well.
Then what might be the problem in the above code?
Template classes should be defined and declared in .h files so that the compiler can generate code for these classes when an instantiation is required.
Because templates are compiled when required, this forces a restriction for multi-file projects: the implementation (definition) of a template class or function must be in the same file as its declaration. That means that we cannot separate the interface in a separate header file, and that we must include both interface and implementation in any file that uses the templates.
Remove definitions from .cpp file to .h file.
These days compilers do allow you to forward declare template types, but some compilers don't yet support them.
template < class T >
class AClass
{
int ATemplateFunction( T aObj );
};
template< class T >
int AClass< T >::ATemplateFunction( T aObj )
{
return 1;
}
|
|
|
|
|
Nibu babu thomas wrote: Template classes should be defined and declared in .h files
But I am creating Library ('Wind32 Static Library') using that code, so i can't write implementation of class in .h file.
So what should i do?
|
|
|
|