Solved

Error

Posted on 2004-04-22
8
529 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
Comment Utility
Is "\windows\iexplore.exe" a typo? C strings require \\ instead of \ since backslash is an escape character.
0
 
LVL 13

Expert Comment

by:SteH
Comment Utility
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
Comment Utility
>>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
Comment Utility
>>BOOL RetVal = CallShell(reinterpret_cast<LPCTSTR>("\\windows\\iexplore.exe"), ...);

Won't work - you cannot cast an ANSI string literal to UNICODE...
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 48

Author Comment

by:Mikal613
Comment Utility
Its for Pocket PC thats why theres a \ instead of \\

evc
0
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
Comment Utility
>>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
Comment Utility
ok i will try
0
 
LVL 48

Author Comment

by:Mikal613
Comment Utility
G-d Bless you thanks alot
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

762 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

12 Experts available now in Live!

Get 1:1 Help Now