Solved

Error

Posted on 2004-04-22
8
542 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

739 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