Solved

CString to const unsigned short

Posted on 2004-09-07
11
1,430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 47
Question regarding Copy/Paste 16 98
haveThree challenge 22 123
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 1,294
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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