Solved

CString to const unsigned short

Posted on 2004-09-07
11
1,443 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

632 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