Having trouble calling certain functions

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2005
Posts: 6
Reputation: 3nCrypti0n is an unknown quantity at this point 
Solved Threads: 0
3nCrypti0n 3nCrypti0n is offline Offline
Newbie Poster

Having trouble calling certain functions

 
0
  #1
Jul 9th, 2005
Im making this program. But im having trouble calling certain functions. Im having trouble calling ShellExecute, RemoveDirectory, CreateDirectory, FindFirstFile, & DeleteFile.

I get the following errors when trying to compile...

  1. c:\documents and settings\george\my documents\visual studio 2005\projects\mmpc v1.0\mmpc v1.0\prog.cpp(42) : error C2664: 'ShellExecuteW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'
  2. Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
  3. c:\documents and settings\george\my documents\visual studio 2005\projects\mmpc v1.0\mmpc v1.0\prog.cpp(116) : error C2664: 'ShellExecuteW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'
  4. Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
  5. c:\documents and settings\george\my documents\visual studio 2005\projects\mmpc v1.0\mmpc v1.0\prog.cpp(168) : error C2664: 'CreateDirectoryW' : cannot convert parameter 1 from 'const char [8]' to 'LPCWSTR'
  6. Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
  7. c:\documents and settings\george\my documents\visual studio 2005\projects\mmpc v1.0\mmpc v1.0\prog.cpp(214) : error C2664: 'FindFirstFileW' : cannot convert parameter 1 from 'const char [13]' to 'LPCWSTR'
  8. Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
  9. c:\documents and settings\george\my documents\visual studio 2005\projects\mmpc v1.0\mmpc v1.0\prog.cpp(226) : error C2664: 'DeleteFileW' : cannot convert parameter 1 from 'const char [14]' to 'LPCWSTR'
  10. Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

I never had this problen when working with DevC++. But ever since I moved to Microsoft Visual C++ 2005, I cant compile this program. Im calling the functions correctly. For example with the ShellExecute function

  1. ShellExecute(0, "open", "MMPC.html", 0, 0, SW_SHOWNORMAL)

But it still gives me an error.

Please Help! Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,740
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 739
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Having trouble calling certain functions

 
0
  #2
Jul 9th, 2005
  1. ShellExecute(0, "open", TEXT("MMPC.html"), 0, 0, SW_SHOWNORMAL)
The TEXT macro either does nothing to the string literal, or prepends L to make it a wide string literal. The errors suggest, that in your setup, a wide string literal is expected. Now, you could just explicitly make the literal wide:
  1. ShellExecute(0, "open", L"MMPC.html", 0, 0, SW_SHOWNORMAL)
But then it would fail for a setup where a narrow string literal is expected.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 6
Reputation: 3nCrypti0n is an unknown quantity at this point 
Solved Threads: 0
3nCrypti0n 3nCrypti0n is offline Offline
Newbie Poster

Re: Having trouble calling certain functions

 
0
  #3
Jul 9th, 2005
I already tried both methods and I still get the same error.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,740
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 739
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Having trouble calling certain functions

 
0
  #4
Jul 9th, 2005
It sounds like a configuration issue with Visual Studio 2005. Play around with any settings that suggest wchar_t or Unicode.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 218
Reputation: hkdani is an unknown quantity at this point 
Solved Threads: 24
hkdani's Avatar
hkdani hkdani is offline Offline
Posting Whiz in Training

Re: Having trouble calling certain functions

 
0
  #5
Dec 4th, 2007
  1. #include <windows.h>
  2.  
  3. int main()
  4. {
  5.  
  6. ....
  7. }
You need to link against the shell32.lib when compiling.

Not familiar with the IDE, but on the command line

c:\> cl /EHs prog.cpp /link shell32.lib
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Having trouble calling certain functions

 
0
  #6
Dec 4th, 2007
First off, your response has nothing to do with the OP's problem.

Secondly, don't resurrect two year old threads unless you have something amazingly earthshaking to contribute.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 218
Reputation: hkdani is an unknown quantity at this point 
Solved Threads: 24
hkdani's Avatar
hkdani hkdani is offline Offline
Posting Whiz in Training

Re: Having trouble calling certain functions

 
0
  #7
Dec 4th, 2007
Originally Posted by Duoas View Post
First off, your response has nothing to do with the OP's problem.
Had the same problem. Same messages. That was my solution offered up on the friendly, Microsoft Managed newsgroup. It's an answer from my humble experience.

Secondly, don't resurrect two year old threads unless you have something amazingly earthshaking to contribute.
If it works, who needs it be earthshaking?
I'm a newb here. And don't exactly appreciate the 'cold' welcome on my first post.

But I do appreciate the fine article on the site about the fellow who enjoyed the forum because of the friendliness of the people on the forum.

Hank
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Having trouble calling certain functions

 
0
  #8
Dec 4th, 2007
I'm sorry you took my response that way, but you are the one being arrogantly rude.

Since you are new to the forum you might want to take some time to read the Forum Announcements.

Those of us who like to take the time to help people here don't like it when some newbie shows up and in his second post starts doing things universally considered obnoxious. Please take the kind hint.

Had Narue or WaltP or Salem or someone else like them (who are all very knowledgeable and very helpful) responded, you might have gotten a much less friendly response --as they have dealt with a lot more snot than I have, and have a much lower tolerance for it.

If you plan to behave and be nice, welcome. Remember, words online are easily misinterpreted whereas in direct conversation they wouldn't be. Don't assume the worst.

Also, don't assume the OP and Narue are blindingly stupid. They were both well beyond including <windows.h> and linking errors. The question was answered.

I give you this by way of welcome and advice. Take it as you will.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 218
Reputation: hkdani is an unknown quantity at this point 
Solved Threads: 24
hkdani's Avatar
hkdani hkdani is offline Offline
Posting Whiz in Training

Re: Having trouble calling certain functions

 
0
  #9
Dec 4th, 2007
I give you this by way of welcome and advice. Take it as you will.
Thanks, for the welcome.

I feel much better now.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Having trouble calling certain functions

 
0
  #10
Dec 4th, 2007
I've had my bad moments too. I'm fairly new myself, and on my second or third post I managed to offend several people who disagreed with me about something...

Alas.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC