C++ url String replacement

Hi,
I need to execute a shell command in c++ from a window's application written in c++:
ShellExecute( NULL, _T("open"), s_param, NULL, NULL, SW_SHOW);

The s_param contains a url and the complete file path to my converted output file from this application. What I need is, say, the url = "http://www.myapp.com/home.html" and the file path is "22C:/Documents%20and%20Settings/admin/Desktop/image1.tiff". I need the s_param to be:

http://www.myapp.com/home.html?path=C:/Documents%20and%20Settings/admin/Desktop/image1.tiff

But at this moment, url displayed is:
http://www.myapp.com/home.html%22%22C:/Documents%20and%20Settings/admin/Desktop/image1.tiff

How can I get rid of the "%22%22 "and replace it with "?path=" string?

Thanks a lot!

Ming
LVL 1
mybluegrassAsked:
Who is Participating?
 
jkrCommented:
Overhurried:
BOOL loadProcess(TCHAR s_process[MAX_PATH*4],TCHAR s_param[MAX_PATH*4])
{

TCHAR acFullUrl[MAX_PATH*4];
TCHAR* pSep = _T("%%22%%22");
TCHAR* pPath = _tcsstr(s_param,pSep);
size_t szUrLLen;

if (!pPath) return FALSE;

szUrlLen = pPath - s_param;

_stprintf(acFullUrl,_T("%*.*s?path=%s"),szUrlLen,szUrlLen,s_param,pPath + _tcslen(pSep));

ShellExecute( NULL, _T("open"), acFullUrl, NULL, NULL, SW_SHOW);

return TRUE;
}

Open in new window

0
 
evilrixSenior Software Engineer (Avast)Commented:
%22 is just the stadnard URL encoding for a slash and %20 is a space. This are perfectly value URLS.
0
 
evilrixSenior Software Engineer (Avast)Commented:
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
evilrixSenior Software Engineer (Avast)Commented:
>> %22 is just the stadnard URL encoding for a slash
Oops, that should be double quote :)
0
 
mybluegrassAuthor Commented:
It's true that it's a valid url but not useful for me. I need the file path to be a parameter of the url:

http://www.myapp.com/home.html?path=C:/Documents%20and%20Settings/admin/Desktop/image1.tiff

The s_param is of type TCHAR s_param[MAX_PATH*4].

Thanks!

Ming
0
 
jkrCommented:
Just concatenate the strings the right way:
TCHAR* pPath = _T("22C:/Documents%20and%20Settings/admin/Desktop/image1.tiff");
TCHAT* pUrl = _T("http://www.myapp.com/home.html");

TCHAR s_param[MAX_PATH*4];

_stprintf(s_param,_T("%s?path=%s",pUrl,pPath);

ShellExecute( NULL, _T("open"), s_param, NULL, NULL, SW_SHOW);

Open in new window

0
 
mybluegrassAuthor Commented:
The problem is that the s_param is passed as a parameter to this method. All I know that it's composed of two parts: url and the file path with %22%22 (double quote) separating them.

BOOL loadProcess(TCHAR s_process[MAX_PATH*4],TCHAR s_param[MAX_PATH*4])
{
   ....
    ShellExecute( NULL, _T("open"), s_param, NULL, NULL, SW_SHOW);
   ....
}

Thanks!

Min
0
 
jkrCommented:
Ah, OK - then you need to split up that one first:
BOOL loadProcess(TCHAR s_process[MAX_PATH*4],TCHAR s_param[MAX_PATH*4])
{

TCHAR acUrl[MAX_PATH*4];
TCHAR acPath[MAX_PATH*4];
TCHAR pSep = _T("%%22%%22");
TCHAR* pPath = _tcsstr(s_param,pSep);
size_t szUrLLen;

if (!pPath) return FALSE;

szUrlLen = pPath - s_param;

_stprintf(s_param,_T("%*.*s?path=%s",szUrlLen,szUrlLen,s_path,pPath + _tcslen(pSep));

ShellExecute( NULL, _T("open"), s_param, NULL, NULL, SW_SHOW);

return TRUE;
}

Open in new window

0
 
mybluegrassAuthor Commented:
Thank you for your patience. But this line always gives me error.

_stprintf(s_param,_T("%*.*s?path=%s",szUrlLen,szUrlLen,s_path,pPath + _tcslen(pSep));

Error:

pcl/rpcl.cpp: In function `BOOL loadProcess(TCHAR*, TCHAR*)':
pcl/rpcl.cpp:6: error: invalid conversion from `const wchar_t*' to `TCHAR'
pcl/rpcl.cpp:7: error: invalid conversion from `TCHAR' to `const wchar_t*'
pcl/rpcl.cpp:7: error:   initializing argument 2 of `wchar_t* std::wcsstr(wcha
r_t*, const wchar_t*)'
pcl/rpcl.cpp:14: error: `szUrlLen' undeclared (first use this function)
pcl/rpcl.cpp:14: error: (Each undeclared identifier is reported only once for e
ach function it appears in.)
mingw32-make: *** [.obj/rpcl.o] Error 1
0
 
jkrCommented:
Sorry, missing bracket in the format string, that should be

_stprintf(s_param,_T("%*.*s?path=%s"),szUrlLen,szUrlLen,s_path,pPath + _tcslen(pSep));
0
 
mybluegrassAuthor Commented:
But it seems that it's stuck on this line: TCHAR pSep = _T("%%22%%22");

With the error:   invalid conversion from `const wchar_t*' to `TCHAR'

And this line: TCHAR* pPath = _tcsstr(s_param,pSep);

With the error:
invalid conversion from `TCHAR' to `const wchar_t*'
 initializing argument 2 of `wchar_t* std::wcsstr(wchar_t*, const wchar_t*)'

And so on.

Thanks!

Ming
0
 
jkrCommented:
Another sorry, that line should be

TCHAR* pSep = _T("%%22%%22");

Or, the whole thing:
BOOL loadProcess(TCHAR s_process[MAX_PATH*4],TCHAR s_param[MAX_PATH*4])
{

TCHAR acUrl[MAX_PATH*4];
TCHAR acPath[MAX_PATH*4];
TCHAR* pSep = _T("%%22%%22");
TCHAR* pPath = _tcsstr(s_param,pSep);
size_t szUrLLen;

if (!pPath) return FALSE;

szUrlLen = pPath - s_param;

_stprintf(s_param,_T("%*.*s?path=%s"),szUrlLen,szUrlLen,s_path,pPath + _tcslen(pSep));

ShellExecute( NULL, _T("open"), s_param, NULL, NULL, SW_SHOW);

return TRUE;
}

Open in new window

0
 
mybluegrassAuthor Commented:
Sorry that there is another error:

pcl/rpcl.cpp:14: error: `s_path' undeclared (first use this function)

Thanks!

Ming
0
 
jkrCommented:
That should have been 's_param' ;o)
BOOL loadProcess(TCHAR s_process[MAX_PATH*4],TCHAR s_param[MAX_PATH*4])
{

TCHAR acUrl[MAX_PATH*4];
TCHAR acPath[MAX_PATH*4];
TCHAR* pSep = _T("%%22%%22");
TCHAR* pPath = _tcsstr(s_param,pSep);
size_t szUrLLen;

if (!pPath) return FALSE;

szUrlLen = pPath - s_param;

_stprintf(s_param,_T("%*.*s?path=%s"),szUrlLen,szUrlLen,s_param,pPath + _tcslen(pSep));

ShellExecute( NULL, _T("open"), s_param, NULL, NULL, SW_SHOW);

return TRUE;
}

Open in new window

0
 
mybluegrassAuthor Commented:
Thanks a lot! I'm getting close. Is there any way that I can print, say, the acFullUrl, pSep, pPath to a temporary file so I can see what values are stored there?

Thanks!

Ming
0
 
mybluegrassAuthor Commented:
Thanks for the help. I finally made it to work. Here is my complete solution. Again, I cannot do this without your help and I really appreciate it! -Ming

        if (!bs){
           
              TCHAR acFullUrl[MAX_PATH*4];
              TCHAR* pSep = _T("\" \"");

              TCHAR* pPath = _tcsstr(s_param,pSep);
              
              size_t szUrlLen;

              szUrlLen = pPath - s_param;

              _stprintf(acFullUrl,_T("%*.*s?path=%s"),szUrlLen,szUrlLen,s_param,pPath + _tcslen(pSep));

              ShellExecute( NULL, _T("open"), acFullUrl, NULL, NULL, SW_SHOW);

        }
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.