Solved

CString to const unsigned short

Posted on 2004-09-07
11
1,408 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
Comment Utility
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
Comment Utility
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
Comment Utility
#include <atlbase.h>


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

lpPersistFile->Save( T2CW((LPCTSTR)s) );
0
 

Author Comment

by:amjedmsa
Comment Utility
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
Comment Utility
#include <atlbase.h>


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

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

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
i gtg now need some sleep(99999999999999999999999999999^32)
0
 

Author Comment

by:amjedmsa
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now