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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
evilrixSenior Software Engineer (Avast)Commented:
>> %22 is just the stadnard URL encoding for a slash
Oops, that should be double quote :)
0
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.