Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CString to const unsigned short

Posted on 2004-09-07
11
Medium Priority
?
1,472 Views
Last Modified: 2013-11-20
i want to converet from CString to const unsigned short in this :

lpPersistFile->Save(L"C://"+(m_web.GetLocationURL()),0);


0
Comment
Question by:amjedmsa
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 13

Assisted Solution

by:SteH
SteH earned 160 total points
ID: 11995704
Should the constant part read
L"C:/"
or
L"C:\\"
? A slash is not an escape character and doesn't need to be doubled. C://xx is no valid file path under windows.
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 160 total points
ID: 11995722
I think you need something like this:
lpPersistFile->Save(CString(L"C:\\")+m_web.GetLocationURL(),0);
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 160 total points
ID: 11995731
#include <atlbase.h>


USES_CONVERSION;
CString s = _T("C:\\file1.txt"));

lpPersistFile->Save( T2CW((LPCTSTR)s) );
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:amjedmsa
ID: 11995818
CString path;
path = _T("C:\\")+m_web.GetLocationURL;

lpDispatch = m_web.GetDocument();
lpDispatch->QueryInterface(IID_IPersistFile, (void**)&lpPersistFile);
*lpPersistFile->Save(path,0);
lpPersistFile->Release();
lpDispatch->Release();      

i get two errors still :
C:\Program Files\Microsoft Visual Studio\MyProjects\web\webDlg.cpp(193) : error C2664: 'Save' : cannot convert parameter 1 from 'class CString' to 'const unsigned short *'


C:\Program Files\Microsoft Visual Studio\MyProjects\web\webDlg.cpp(189) : error C2297: '+' : illegal, right operand has type 'class CString (__thiscall CWebBrowser2::*)(void)'

the second one i think i can do with strcat



0
 
LVL 48

Expert Comment

by:AlexFM
ID: 11995850
#include <atlbase.h>


USES_CONVERSION;
CString path;
path = _T("C:\\")+m_web.GetLocationURL;

*lpPersistFile->Save( T2CW((LPCTSTR)path) ,0);

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 11995865
Didn't read second error message.

#include <atlbase.h>


USES_CONVERSION;
CString path = _T("C:\\");
path += m_web.GetLocationURL;

*lpPersistFile->Save( T2CW((LPCTSTR)path) ,0);
0
 

Author Comment

by:amjedmsa
ID: 11995880
ok ok i got it. forget about the conversion part i did with (T2OLE)

now i need to do this
path = _T("C:\\s.htm"+m_web.GetLocationURL);
with the strcat i will get cannot do CString to Char* i will increase this to 80 if u can manage to make it work in less than 1/2 houre
0
 

Author Comment

by:amjedmsa
ID: 11995940
this how far i got with it

CString path;
USES_CONVERSION;
path = _T("C:\\");
path += m_web.GetLocationURL();
lpDispatch = m_web.GetDocument();
lpDispatch->QueryInterface(IID_IPersistFile, (void**)&lpPersistFile);
lpPersistFile->Save(T2OLE(path),0);
lpPersistFile->Release();
lpDispatch->Release();      

but it does not save the file to the c drive + the web site url
0
 

Author Comment

by:amjedmsa
ID: 11995975
i gtg now need some sleep(99999999999999999999999999999^32)
0
 

Author Comment

by:amjedmsa
ID: 12007231
ok ok forgot about all the stuff can someone help get this work:
iwantto replace all the illegal characters in file name {/ \ : " * ? < > | }
that may exist in a URL like
http://www.google.com/
i basicly want to replace all the illegal characters with ' _ '
0
 
LVL 13

Expert Comment

by:SteH
ID: 12007254
If using STL string s is an option:

int ind = 0;

while (ind != std::string::npos) {
   ind = str.find_first_of ("{/\:"*?<>|}");
   if (ind != std::string::npos) {
       str[ind] = '_';
   }
}
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question