The majority of forums are now only available as archives, which means posting/editing is disabled.
The Anything and Everything forum is still open.
The Anything and Everything forum is still open.
compiling error
|
|||
|
Rank: ? (1)
Member #: 20636 |
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: --------------------------- #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? 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 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)
Jenny
|
||
|
|||
|
|||
|
Rank: ? (4827)
Member #: 3416 |
the problem must be with CreateProcess(). it's expecting a char* and you're giving it const char* -- or at least that's my guess from the error message. it may work if you remove const from cmdLines' definition
my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
|
||
|
|||
|
|||
|
Rank: ? (533)
Member #: 8648 |
Just to poitn out another error, in that array of sites, you have a semicolon after the quotes, and before the commas. You don't need semicolons after the ending quote.
ZapX Technologies - We have the solution for you! See zapx.net for web hosting, design, graphics, custom applications, and a forum!
Affordable web hosting guaranteeing 99.9% uptime, quality 24/7 support, and a 30-day money back guarantee. hosting.zapx.net
|
||
|
Please login or register to post a reply.
