65,210
社区成员
发帖
与我相关
我的任务
分享int main()
{
int a =0; //这值经常变化的
}int main()
{
cout<<a; //我要怎么得到这个 a 值
}
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
cout<<"server start ..."<<endl;
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
if(WM_USER+1000 == msg.message)
{
cout<<"get client msg and parameter is "<<msg.lParam<<endl;
}
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
cout<<"server exit ..."<<endl;
return 0;
}
#include "stdafx.h"
#include <Windows.h>
#include <Tlhelp32.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
HANDLE hProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
PROCESSENTRY32 info;
info.dwSize = sizeof(PROCESSENTRY32);
BOOL bGetmore = Process32First(hProcess,&info);
BOOL bfind = FALSE;
DWORD taget = 0;
while(bGetmore && !bfind)
{
if(0==strcmp("myserver.exe",info.szExeFile))
{
cout<<"process id "<<info.th32ProcessID<<endl;
HANDLE hModule = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0);
THREADENTRY32 tinfo;
tinfo.dwSize = sizeof(THREADENTRY32);
bGetmore = Thread32First(hModule, &tinfo);
while(bGetmore)
{
if(info.th32ProcessID==tinfo.th32OwnerProcessID)
{
cout<<"thread id is "<<tinfo.th32ThreadID<<endl;
bfind = TRUE;
taget = tinfo.th32ThreadID;
break;
}
bGetmore = Thread32Next(hModule,&tinfo);
}
CloseHandle(hModule);
break;
}
bGetmore = Process32Next(hProcess, &info);
}
CloseHandle(hProcess);
if(!bfind)
{
return 0;
}
int i = 0;
while(1)
{
if(::PostThreadMessage(taget,WM_USER+1000,0,++i))
{
cout<<"send message "<<i<<endl;
}
else
{
cout<<"fail at "<<i<<","<<GetLastError()<<endl;
}
Sleep(1000);
}
return 0;
}