Работа с процессами С++ / Помогите исправить ошибку
Код:
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <windows.h>
#include <string.h>
#define LOOP for(;;)
CRITICAL_SECTION cs;
DWORD WINAPI NewThread2Func(TCHAR lpParam[]);
DWORD WINAPI NewThreadFunc(TCHAR lpParam[]);
int main(void)
{
LPVOID pData=0;
DWORD dwNewThreadId;
HANDLE hNewThread;
HANDLE hNewThread2;
char pchNewThreadParams[30];
char chKey;
system("color b0");
printf("Enter param string:\n");
gets(pchNewThreadParams);
InitializeCriticalSection(&cs);
printf("\n1-Start thread I. 2-Pause thread I. ESC-Exit.\n");
printf("3-Start thread II. 4-Pause thread II.");
printf("\n5-Delete thread I. 6-Delete thread II.\n");
printf("7-Create thread I. 8-Create thread II.\n");
printf("---------------------------------------------\n");
hNewThread=CreateThread(
NULL,
0,
(unsigned long (__stdcall *)(void *))NewThreadFunc,
pchNewThreadParams,
CREATE_SUSPENDED,
&dwNewThreadId
);
hNewThread2=CreateThread(
NULL,
0,
(unsigned long (__stdcall *)(void *))NewThread2Func,
pchNewThreadParams,
CREATE_SUSPENDED,
&dwNewThreadId
);
// Control loop
do
{
chKey=_getch();
// Start NT
switch (chKey)
{
case '1':
ResumeThread(hNewThread);
break;
case '2':
SuspendThread(hNewThread);
break;
case '3':
ResumeThread(hNewThread2);
break;
case '4':
SuspendThread(hNewThread2);
break;
case '5':
if(TerminateThread(hNewThread,0))
printf("T1.Deleted.\n");
break;
case '6':
if(TerminateThread(hNewThread2,0))
printf("T2.Deleted.\n");
break;
case '7':
hNewThread=CreateThread(
NULL,
0,
(unsigned long (__stdcall *)(void *))NewThreadFunc,
pchNewThreadParams,
CREATE_SUSPENDED,
&dwNewThreadId
);
printf("T1.Created.\n");
break;
case '8':
hNewThread2=CreateThread(
NULL,
0,
(unsigned long (__stdcall *)(void *))NewThread2Func,
pchNewThreadParams,
CREATE_SUSPENDED,
&dwNewThreadId
);
printf("T2.Created.\n");
}
}
while(chKey!=27);
DeleteCriticalSection(&cs);
CloseHandle(hNewThread);
CloseHandle(hNewThread2);
return 0;
}
//DWORD WINAPI NewThread2Func(LPVOID lpParam)
DWORD WINAPI NewThread2Func(TCHAR lpParam[])
{
//TCHAR tcParam[30];
//strcpy(tcParam,(char *)lpParam);
LOOP
{
EnterCriticalSection(&cs);
{
printf("T2:Param is \"%s\" : ",lpParam);
for(int i=0;lpParam[i];i++)
{
if(!(lpParam[i]=rand()%255)) lpParam[i]=32;
}
printf("new str : '%s'\n",lpParam);
LeaveCriticalSection(&cs);
}
Sleep(300);
}
return 0;
}
DWORD WINAPI NewThreadFunc(TCHAR tcParam[])
{
unsigned uBigLetters=0;
//TCHAR tcParam[30];
//strcpy(tcParam,(char *)lpParam);
LOOP
{
uBigLetters=0;
EnterCriticalSection(&cs);
{
printf("T1:Param is \"%s\" : ",tcParam);
for(int i=0;tcParam[i];i++)
{
if(tcParam[i]>='A' && tcParam[i]<='Z') uBigLetters++;
}
LeaveCriticalSection(&cs);
printf("zaglavnih bukv:%d\n",uBigLetters);
}
Sleep(500);
//SwitchToThread();
}
return 0;
}
#include <conio.h>
#include <process.h>
#include <windows.h>
#include <string.h>
#define LOOP for(;;)
CRITICAL_SECTION cs;
DWORD WINAPI NewThread2Func(TCHAR lpParam[]);
DWORD WINAPI NewThreadFunc(TCHAR lpParam[]);
int main(void)
{
LPVOID pData=0;
DWORD dwNewThreadId;
HANDLE hNewThread;
HANDLE hNewThread2;
char pchNewThreadParams[30];
char chKey;
system("color b0");
printf("Enter param string:\n");
gets(pchNewThreadParams);
InitializeCriticalSection(&cs);
printf("\n1-Start thread I. 2-Pause thread I. ESC-Exit.\n");
printf("3-Start thread II. 4-Pause thread II.");
printf("\n5-Delete thread I. 6-Delete thread II.\n");
printf("7-Create thread I. 8-Create thread II.\n");
printf("---------------------------------------------\n");
hNewThread=CreateThread(
NULL,
0,
(unsigned long (__stdcall *)(void *))NewThreadFunc,
pchNewThreadParams,
CREATE_SUSPENDED,
&dwNewThreadId
);
hNewThread2=CreateThread(
NULL,
0,
(unsigned long (__stdcall *)(void *))NewThread2Func,
pchNewThreadParams,
CREATE_SUSPENDED,
&dwNewThreadId
);
// Control loop
do
{
chKey=_getch();
// Start NT
switch (chKey)
{
case '1':
ResumeThread(hNewThread);
break;
case '2':
SuspendThread(hNewThread);
break;
case '3':
ResumeThread(hNewThread2);
break;
case '4':
SuspendThread(hNewThread2);
break;
case '5':
if(TerminateThread(hNewThread,0))
printf("T1.Deleted.\n");
break;
case '6':
if(TerminateThread(hNewThread2,0))
printf("T2.Deleted.\n");
break;
case '7':
hNewThread=CreateThread(
NULL,
0,
(unsigned long (__stdcall *)(void *))NewThreadFunc,
pchNewThreadParams,
CREATE_SUSPENDED,
&dwNewThreadId
);
printf("T1.Created.\n");
break;
case '8':
hNewThread2=CreateThread(
NULL,
0,
(unsigned long (__stdcall *)(void *))NewThread2Func,
pchNewThreadParams,
CREATE_SUSPENDED,
&dwNewThreadId
);
printf("T2.Created.\n");
}
}
while(chKey!=27);
DeleteCriticalSection(&cs);
CloseHandle(hNewThread);
CloseHandle(hNewThread2);
return 0;
}
//DWORD WINAPI NewThread2Func(LPVOID lpParam)
DWORD WINAPI NewThread2Func(TCHAR lpParam[])
{
//TCHAR tcParam[30];
//strcpy(tcParam,(char *)lpParam);
LOOP
{
EnterCriticalSection(&cs);
{
printf("T2:Param is \"%s\" : ",lpParam);
for(int i=0;lpParam[i];i++)
{
if(!(lpParam[i]=rand()%255)) lpParam[i]=32;
}
printf("new str : '%s'\n",lpParam);
LeaveCriticalSection(&cs);
}
Sleep(300);
}
return 0;
}
DWORD WINAPI NewThreadFunc(TCHAR tcParam[])
{
unsigned uBigLetters=0;
//TCHAR tcParam[30];
//strcpy(tcParam,(char *)lpParam);
LOOP
{
uBigLetters=0;
EnterCriticalSection(&cs);
{
printf("T1:Param is \"%s\" : ",tcParam);
for(int i=0;tcParam[i];i++)
{
if(tcParam[i]>='A' && tcParam[i]<='Z') uBigLetters++;
}
LeaveCriticalSection(&cs);
printf("zaglavnih bukv:%d\n",uBigLetters);
}
Sleep(500);
//SwitchToThread();
}
return 0;
}
main.obj - 1 error(s), 0 warning(s)
УМВР.