Solved

Error

Posted on 2004-04-22
8
531 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now