Solved

CString to const unsigned short

Posted on 2004-09-07
11
1,426 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 40 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 40 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 40 total points
ID: 11995731
#include <atlbase.h>


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

lpPersistFile->Save( T2CW((LPCTSTR)s) );
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to determine file rename from EventLog ? 2 54
Smart Camera scanning and reading information 3 113
sum13 challenge 24 120
noX challenge 17 129
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.

809 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