Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error

Posted on 2004-04-22
8
Medium Priority
?
556 Views
Last Modified: 2010-04-01
BOOL WINAPI CallShell(LPCTSTR lpFilePath, LPCTSTR lpURL)
{
     SHELLEXECUTEINFO *lpSHInfo;
     BOOL RetVal;
     
     lpSHInfo = (SHELLEXECUTEINFO *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SHELLEXECUTEINFO));
     lpSHInfo->cbSize = sizeof(SHELLEXECUTEINFO);
     lpSHInfo->fMask = SEE_MASK_NOCLOSEPROCESS;
     lpSHInfo->lpFile = lpFilePath;
     lpSHInfo->lpParameters = lpURL;

     RetVal =  ShellExecuteEx(lpSHInfo);

     HeapFree(GetProcessHeap(), 0, lpSHInfo);
     return RetVal;
}


called like this

BOOL RetVal = CallShell("\windows\iexplore.exe", "www.google.com");"


error C2664: 'CallShell' : cannot convert parameter 1 from 'char [20]' to 'const unsigned short *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


How do i fix this error?
0
Comment
Question by:Mikal613
  • 3
  • 3
  • 2
8 Comments
 
LVL 13

Expert Comment

by:SteH
ID: 10890375
Is "\windows\iexplore.exe" a typo? C strings require \\ instead of \ since backslash is an escape character.
0
 
LVL 13

Expert Comment

by:SteH
ID: 10890405
Try to call it like
BOOL RetVal = CallShell((LPCTSTR) "\\windows\\iexplore.exe", (LPCTSTR) "www.google.com");
or
BOOL RetVal = CallShell(reinterpret_cast<LPCTSTR>("\\windows\\iexplore.exe"), ...);

0
 
LVL 86

Expert Comment

by:jkr
ID: 10890414
>>error C2664: 'CallShell' : cannot convert parameter 1 from 'char [20]' to 'const unsigned short *'

It seems your project is set to compile as UNICODE - use the '_T()' macro to take care of that and double the backslashes:

BOOL RetVal = CallShell( _T("\\windows\\iexplore.exe"), _T("www.google.com"));

BTW, you might be better off to simply use

ShellExecute ( NULL, _T("open"), _T("www.google.com"), NULL, NULL, SW_SHOW);


0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 86

Expert Comment

by:jkr
ID: 10890422
>>BOOL RetVal = CallShell(reinterpret_cast<LPCTSTR>("\\windows\\iexplore.exe"), ...);

Won't work - you cannot cast an ANSI string literal to UNICODE...
0
 
LVL 48

Author Comment

by:Mikal613
ID: 10890547
Its for Pocket PC thats why theres a \ instead of \\

evc
0
 
LVL 86

Accepted Solution

by:
jkr earned 1000 total points
ID: 10890632
>>Its for Pocket PC

So, you are referring to http://support.microsoft.com/default.aspx?scid=kb;en-us;275230 ("HOWTO: Specify a URL When Starting Pocket Internet Explorer from eVB")?  Try the '_T()' macro then.
0
 
LVL 48

Author Comment

by:Mikal613
ID: 10890656
ok i will try
0
 
LVL 48

Author Comment

by:Mikal613
ID: 10892492
G-d Bless you thanks alot
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

783 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