Click here to Skip to main content
16,011,685 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: IXMLDOMDocument::loadXML() Pin
Michael Dunn1-Jan-03 6:39
sitebuilderMichael Dunn1-Jan-03 6:39 
GeneralCommand Id range Pin
User 98851-Jan-03 6:24
User 98851-Jan-03 6:24 
GeneralRe: Command Id range Pin
Pavel Klocek1-Jan-03 8:37
Pavel Klocek1-Jan-03 8:37 
GeneralMemory consumption Pin
Shah Shehpori1-Jan-03 5:42
sussShah Shehpori1-Jan-03 5:42 
GeneralRe: Memory consumption Pin
Florin Ochiana1-Jan-03 11:48
Florin Ochiana1-Jan-03 11:48 
GeneralRe: Memory consumption Pin
Mike Nordell1-Jan-03 18:56
Mike Nordell1-Jan-03 18:56 
QuestionUnicode comparing of file extensions? Pin
Fahr1-Jan-03 3:55
Fahr1-Jan-03 3:55 
AnswerRe: Unicode comparing of file extensions? Pin
Gary R. Wheeler1-Jan-03 4:42
Gary R. Wheeler1-Jan-03 4:42 
Try this:

_TCHAR *FileExt = new _TCHAR[10];
int FileNameLen = _tcslen(FileName);
for(int x = FileNameLen; x>= 0; x--)
{
    if(FileName[x] == _T('.'))
    {
        // Get the extension
        _tcsncpy(FileExt, FileName + x + 1, FileNameLen - x - 1);
        break;
    }
}

_tcsupr(FileExt);

if ((_tcscmp(FileExt,_T("U")) == 0) || (_tcscmp(FileExt,_T("DLL")) == 0))
{
    delete []FileExt;
    return 1;
}
else if (_tcscmp(FileExt,_T("UNR")) == 0)
{
    delete []FileExt;
    return 2;
}
else
{
    delete []FileExt;
    return 3;
}


First, I replaced the 'unsigned short' with _TCHAR. You're using the tchar.h macros elsewhere, so this will make the code work whether you compile for MBCS or UNICODE. Second, the first if condition wasn't quite right; I changed the character constant from '.' to _T('.'). The '.' is an MBCS character always, even if you are compiling for UNICODE. The statement FileExt = _wcsupr(FileExt) will make the FileExt value upper case, but it may also change the value of FileExt (which you probably don't want). Next, the conditions where you compare the extracted extension weren't right. Using FileExt == _T("U") compares the pointer to the extension value to the pointer to a constant string. You want to do a string comparison here, hence the _tcscmp calls. I also added the delete's before the return's so that this wouldn't leak memory.


Software Zen: delete this;
GeneralRe: Unicode comparing of file extensions? Pin
Fahr1-Jan-03 5:05
Fahr1-Jan-03 5:05 
AnswerRe: Unicode comparing of file extensions? Pin
Michael Dunn1-Jan-03 6:36
sitebuilderMichael Dunn1-Jan-03 6:36 
GeneralRe: Unicode comparing of file extensions? Pin
Fahr1-Jan-03 6:56
Fahr1-Jan-03 6:56 
GeneralRe: Unicode comparing of file extensions? Pin
Michael Dunn1-Jan-03 7:26
sitebuilderMichael Dunn1-Jan-03 7:26 
GeneralRe: Unicode comparing of file extensions? Pin
Fahr1-Jan-03 8:39
Fahr1-Jan-03 8:39 
GeneralRe: Unicode comparing of file extensions? Pin
Michael Dunn1-Jan-03 8:54
sitebuilderMichael Dunn1-Jan-03 8:54 
GeneralRe: Unicode comparing of file extensions? Pin
Fahr1-Jan-03 9:23
Fahr1-Jan-03 9:23 
GeneralRe: Unicode comparing of file extensions? Pin
Michael Dunn1-Jan-03 9:44
sitebuilderMichael Dunn1-Jan-03 9:44 
GeneralRe: Unicode comparing of file extensions? Pin
Fahr1-Jan-03 9:49
Fahr1-Jan-03 9:49 
QuestionHow to find the Network speed (without PDH)? Pin
adara1-Jan-03 3:48
adara1-Jan-03 3:48 
AnswerRe: How to find the Network speed (without PDH)? Pin
Mike Nordell1-Jan-03 19:01
Mike Nordell1-Jan-03 19:01 
Generalexecute program from memory Pin
ncm1-Jan-03 3:25
ncm1-Jan-03 3:25 
GeneralRe: execute program from memory Pin
Mike Nordell1-Jan-03 19:03
Mike Nordell1-Jan-03 19:03 
GeneralRe: execute program from memory Pin
ncm2-Jan-03 1:06
ncm2-Jan-03 1:06 
GeneralProblem with resource id's... [Visual C++.NET] Pin
rkpk1-Jan-03 2:11
rkpk1-Jan-03 2:11 
GeneralCHtmlView Pin
alex.barylski1-Jan-03 1:07
alex.barylski1-Jan-03 1:07 
GeneralKilling a modeless Dialog when it loses focus Pin
Florin Ochiana31-Dec-02 23:43
Florin Ochiana31-Dec-02 23:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.