GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Sep-2004, 07:04
25jenny 25jenny is offline
New Member
 
Join Date: Sep 2004
Posts: 1
25jenny is on a distinguished road

compiling error


Hi,

My name is jenny

A friend gave me this file to compile.
My goal is to open 4 browser windows and then close them via "end task" with a

delay between them.

When I try to compile it (dev-C++) I'm getting this error message, How can I

solve it?

-------
68: Invalid conversion from 'const char*' to 'CHAR*'
-------

Source file:
---------------------------

CPP / C++ / C Code:
#include <windows.h>
#include <winbase.h>

/* times in miliseconds */
#define INTERMEDIATE_DELAY 2000
#define FINAL_DELAY 15000

/* erm, duh */
#define NUMBER_OF_PROCESSES 4

/* yes yes, a dreaded global variable - speed vs size tradeoff,
who needs to initialize 68 bytes with code inside main when
we've got .data for it? ;) Besides, a smart compiler will
optimize it into .bss anyway */
STARTUPINFO startupInfo = {
sizeof(STARTUPINFO),
NULL,
NULL,
NULL,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
NULL,
NULL,
NULL,
NULL
};

/* const to let the system know it can page out without
hassle if needed, amounts to discardable memory */
const char* cmdLines[] = {
"C:\Program Files\Internet Explorer\iexplore.exe http://www.site1.com";,
"C:\Program Files\Internet Explorer\iexplore.exe http://www.site2.com";,
"C:\Program Files\Internet Explorer\iexplore.exe http://www.site3.com";,
"C:\Program Files\Internet Explorer\iexplore.exe http://www.site4.com";
};

int main()
{
unsigned int i;
HANDLE hProcesses[NUMBER_OF_PROCESSES];
PROCESS_INFORMATION procInfo;

/* add some time verification, etc here (suggest using
GetLocalTime() and checking against the desired stop time,
or GetTickCount() and compare a subtraction if it's just a
relative time instead of absolute hh:mm) */
for(;;)
{ /* infinite cycle doing the whole thing */
for (i=0;i<NUMBER_OF_PROCESSES;i++)
{ /* cycle creating the NUMBER_OF_PROCESSES processes */
if (!CreateProcess(NULL,
cmdLines[i],
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&startupInfo,
&procInfo))
{ /* couldn't run */
/* add code to print an error out based on GetLastError()
here, I'm lazy ;) - suggest using FormatMessage() */
return 2;
}
CloseHandle(procInfo.hThread); /* don't need this */
hProcesses[i]=procInfo.hProcess;
Sleep(INTERMEDIATE_DELAY);
}

/* final delay */
Sleep(FINAL_DELAY - INTERMEDIATE_DELAY);

/* _kill_ all processes */
for (i=0;i<NUMBER_OF_PROCESSES;i++)
{
TerminateProcess(hProcesses[i],0); /* die, you #$%@! */
CloseHandle(hProcesses[i]);
}
}

/* won't ever reach this as it is, it's here for when we actually
implement a stopping condition for the big for */
return 0;
}
------------------


I'd also like to run it for a period of time...
I wonder if someone can complete and test my program.

Thanks,
Jenny

(I don't understand anything about programming)
Last edited by dsmith : 03-Sep-2004 at 08:07. Reason: Please use [c] & [/c] for syntax highlighting
  #2  
Old 03-Sep-2004, 22:08
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Ok, then. Well, since I don't know anything whatsoever about the program, I'll just assume, and this is probably a bad assumption, that the problem is a mismatched type in the CreateProcess function call. So, go ahead and find the line that says:

CPP / C++ / C Code:
const char* cmdLines[] = {
"C:\Program Files\Internet Explorer\iexplore.exe http://www.site1.com";,
"C:\Program Files\Internet Explorer\iexplore.exe http://www.site2.com";,
"C:\Program Files\Internet Explorer\iexplore.exe http://www.site3.com";,
"C:\Program Files\Internet Explorer\iexplore.exe http://www.site4.com";
};

...and just get rid of the word const, and try to compile it again. Come back for help if it gives you more errors.

Question: Why are you trying to compile a program if you don't know anything about programming? Why couldn't your friend compile it for you? You appear to be running on Windows, so I don't see why your friend couldn't just compile it and send you the binary...
__________________
-Aaron
  #3  
Old 04-Sep-2004, 06:52
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
In addition to that, the lines that Aaron identified have some other errors in them that should prevent this thing from compiling anyway:

CPP / C++ / C Code:
const char* cmdLines[] = {
"C:\Program Files\Internet Explorer\iexplore.exe http://www.site1.com";,
"C:\Program Files\Internet Explorer\iexplore.exe http://www.site2.com";,
"C:\Program Files\Internet Explorer\iexplore.exe http://www.site3.com";,
"C:\Program Files\Internet Explorer\iexplore.exe http://www.site4.com";
};

Should be:
CPP / C++ / C Code:
const char* cmdLines[] = {
"C:\\Program Files\\Internet Explorer\\iexplore.exe http://www.site1.com",
"C:\\Program Files\\Internet Explorer\\iexplore.exe http://www.site2.com",
"C:\\Program Files\\Internet Explorer\\iexplore.exe http://www.site3.com",
"C:\\Program Files\\Internet Explorer\\iexplore.exe http://www.site4.com"
};

Note the exclusion of the semicolon at the end of each line as well as the '\\' instead of '\'.

I am not much of windows programmer unfortunately, but I have to agree with Aaron somewhat. It seems that whoever wrote this had a definite plan and could code. (I am actually pretty shocked about the errors int the string literals). Do you not know this person anymore? I will try to find some documentation for the createProcess function.

This is probably the "proper" way to do something like this, but depending on how robust you want the program to be, a simple call to system sure seems easier...

Anyway, sorry for the not so immediate and not so conclusive help. If no one else has any great ideas, I will look into it a bit more...
  #4  
Old 04-Sep-2004, 07:09
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
... and I am sorry for yet another bug in the syntax highlighter. I need to set a thread pointing to all the threads inside this forum, that display C++ syntax highlighting bugs.
  #5  
Old 04-Sep-2004, 07:11
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by JdS
... and I am sorry for yet another bug in the syntax highlighter. I need to set a thread pointing to all the threads inside this forum, that display C++ syntax highlighting bugs.

hehe.

I was going to point that out to you, but I know that you are pretty busy.

Still this is the *best* syntax highlighter on a forum that I have ever seen. (But I don't get out much...)
  #6  
Old 04-Sep-2004, 09:51
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,217
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by aaroncohn
...and just get rid of the word const, and try to compile it again. Come back for help if it gives you more errors.

Question: Why are you trying to compile a program if you don't know anything about programming? Why couldn't your friend compile it for you? You appear to be running on Windows, so I don't see why your friend couldn't just compile it and send you the binary...

I have had to literally sit on my hands and metaphorically bite my tongue to keep from responding, but I can't stand it any more.

Jenny, your friend has given you a program with bugs that make it not compile on any Windows compiler (or any other standard C++ compiler). You don't know much about programming, but you are attempting to compile a program that, when the bugs are fixed, continuously invokes Internet Explorer that attempts to visit four web sites. Do you know what the web sites are? How do you know they are benign? Are you aware that there are Internet Explorer bugs that can be exploited by visiting malevolent web sites? (I don't think site1.com, site2.com and site4.com actually are malevolent. I wasn't able to get site3.com to come up.)

The program loops forever. If you don't know enough about dev-c++ to find the bugs in the program, would you know how to stop the infinite loop of continously visiting the sites?

I don't mean to be unkind, but I have to ask: why would you want someone here to tell you how to fix your friend's program in the first place? Why would you not ask your friend?

To people that are responding to this: am I the only one with misgivings about helping on this? How would you respond if someone said,

"My friend loaned me a gun, but gave me the wrong bullets. I don't know much about guns, so can you help me find out how to obtain the correct ammo so that I can load it?"

Sorry if this is out of place on this forum. Moderators: feel free to delete this if you see fit.

Please consider that I have only good intentions in posting this, and I am sorry if it comes out too harsh.

Dave
  #7  
Old 04-Sep-2004, 10:03
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
You're fine Dave. I think we are all scratching our heads a bit with this one. I don't think that site1, site2, site3, site4 were literal, just examples. Maybe I don't see the same level of malignancy that you do, but I do have to wonder about why this is not being asked of the original writer of this code.

Jenny - if you are still around - I don't want you to get the wrong idea. We are more than willing to help, it is just a strange request and Dave is correct in pointing out that if you don't know *anything* about programming, you may not want to be compiling any code that you get, yet alone C code.
  #8  
Old 04-Sep-2004, 10:14
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,217
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by dsmith
I don't think that site1, site2, site3, site4 were literal, just examples.

But the program, when the bugs are fixed, will actually invoke internet explorer and go to these URLs. My point is: why would someone try to compile and execute a program if they don't understand what the program will do?

Regards,

Dave
  #9  
Old 04-Sep-2004, 12:19
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,217
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
As a follow-up to my negative comments, I would like to offer some positive points.

If I had a friend who was studying Windows programming and wanted to see an example of using CreateProcess() and TerminateProcess() to create and delete Internet Explorer processes, I might do the following:

1. Use indentation to show how to make a program more readable.

2. I would point out that this program has main(), so is a Console application, even though it uses Windows API calls.

3. I would put instructions before the beginning of the for( ; ; ) loop. Something the user can read when the program executes, like

CPP / C++ / C Code:
  printf("\n\n  This program creates an infinite loop that repeatedly does ");
  printf("the following:\n\n");
  printf("    Invoke Internet Explorer four times, then wait a little while\n");
  printf("    and close the four Internet Explorer windows.\n\n\n\n");
  printf("  I am going to give you the opportunity to Press \"Enter\" to do\n");
  printf("  it, or Ctrl-C to forget the whole thing. \n\n");
  printf("  If you decide to proceed, you can stop the program at any time\n");
  printf("  by typing Ctrl-C (in this window). If there are any left-over\n");
  printf("  Internet Explorer windows you can then manually close them.\n\n");
  printf("  Press the \"Enter\" key to start the program, press Ctrl-C to quit: ");

  getchar();
  printf("\n\n");

Note that you have to #include <stdio.h> to use printf();

4. I would put some kind of error message in case the CreateProcess() failed. Something like
CPP / C++ / C Code:
{ /* couldn't run */
  /* add code to print an error out based on GetLastError()
  here, I'm lazy ;) - suggest using FormatMessage() */
  printf("Couldn't run cmdLines[%d]: <%s>\n", i, cmdLines[i]);
  return 2;


5. I would use commands that wouldn't actually go onto the Internet and try to access web sites; If I knew the friend's Windows installation was on drive C: the commands could be something like.

CPP / C++ / C Code:
  char* cmdLines[] = {
      "C:\\Program Files\\Internet Explorer\\iexplore.exe about:Instance1",
      "C:\\Program Files\\Internet Explorer\\iexplore.exe about:Instance2",
      "C:\\Program Files\\Internet Explorer\\iexplore.exe about:Instance3",
      "C:\\Program Files\\Internet Explorer\\iexplore.exe about:Instance4"
  };

If the friend asked what the heck this is doing, I would explain it a little.

6. I would make sure that the program would compile and execute with whatever compiler the friend is using. Here is the message that Jenny asked about:

Quote:
Invalid conversion from 'const char*' to 'CHAR*'

Note that this is an error in C++, but a warning in C. The program with the changes that I have indicated is a valid C program, and is also a valid C++ program (by leaving the const off of the cmdLines[] definition).



Best regards,

Dave
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Operator Overloading: << aaroncohn C++ Forum 36 07-Dec-2004 20:22
error when compiling avi C Programming Language 2 11-Aug-2004 04:17
link error? pablowablo C++ Forum 14 19-Jun-2004 11:00
OpenGL always reports error mvt OpenGL Programming 2 04-Jun-2004 07:42
Visual C++ 6 Compiler error vip3r C++ Forum 2 13-Apr-2004 15:34

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 10:50.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.