Solved

Error

Posted on 2004-04-22
8
534 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 clear a vector as well as how to detect empty vectors in C++.

770 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