Home

Forums

Web development

 

 

 

 
     
 
dna88 Web development and Technology Forum
 
Profile   Register   Memberlist   Usergroups   FAQ   Search  Log in
compiling error

 
Post new topic   Reply to topic    dna88 Forum Index -> Programming in Java, C, C#, VB, .NET Discussion Forum
Author Message
25jenny
Just In
Just In


Joined: 03 Sep 2004
Posts: 1

Post Post subject: compiling error Reply with quote

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:
---------------------------
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)
Fri Sep 03, 04 5:48 am
Back to top
25jenny View user's profile Send private message
dinangkur
Super Moderator
Super Moderator


Joined: 24 Mar 2004
Posts: 491
Location: Dhaka, Bangladesh

Post Post subject: Reply with quote

Hi I just looked in your code and I've found 13 errors in it. So, according to you information, that "const" is just another code among those 13. By the way, I fix it and it's going to work now. If you want implement the second part - why don't you exercise a bit about it? Bring some code, then I will look into it. Enjoy.
I tested this code in VC++ 6 in console mode application.

Have fun.

-DK.

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 */
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;
}

_________________
...we too are stardust...
Sat Sep 04, 04 8:17 pm
Back to top
dinangkur View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    dna88 Forum Index -> Programming in Java, C, C#, VB, .NET Discussion Forum All times are GMT - 7 Hours
Page 1 of 1

 

Partners and Resources

Bangladesh hosting company

Bangladesh web design

Driven by phpBB © phpBB Group