








另外,關于cocos2d-x在android上添加第三方庫的問題,6群網友塞風朔雪寫了一個文檔,很有參考價值。我已把它上傳到附件中。
posted @ 2013-06-01 10:04 鄭興鋒 閱讀(1190) | 評論 (0) | 編輯 收藏
服務器









另外,關于cocos2d-x在android上添加第三方庫的問題,6群網友塞風朔雪寫了一個文檔,很有參考價值。我已把它上傳到附件中。
posted @ 2013-06-01 10:04 鄭興鋒 閱讀(1190) | 評論 (0) | 編輯 收藏
環境winxp + android sdk + ndk r8b+ cygwin 1.7.16-1 + cocos2d-1.0.1-x-0.12.0
1.下載android sdk、ndk、cygwin
http://dl.google.com/android/android-sdk_r20.0.1-windows.zip
http://dl.google.com/android/ndk/android-ndk-r8b-windows.zip
2.android sdk的安裝就不多說了,網上多的是。
將ndk解壓到不含空格的目錄下,下文用<ndk_dir>來表示解壓后的ndk根目錄。
下載好cygwin后,運行setup.exe。需要安裝的組件有:
autoconf automake binutils gcc-core gcc-g++ gcc4-core gcc4-g++ gdb pcre pcre-devel gawk make
可以在上方search處進行查找安裝,下文用<cyg_dir>表示cygwin的安裝目錄。
3.cygwin安裝好后,在windows下編輯<cyg_dir>\home\Administrator\.bash_profile文件
在文件最后添加如下內容
這樣,環境基本上就搭建好了,下面需要建一個hello world工程來驗證一下環境是否可用。
1.運行cocos2dx目錄下的create-android-project.bat文件,根據提示輸入包名(例如:cn.wey.android)、項目名稱(例如:hello2dx)、所使用的android sdk版本。
2.運行cygwin,在命令窗口中進入剛剛新建的hello2dx目錄下的android目錄,運行命令
3.打開eclipse,導入hello2dx項目,編譯并運行。即可看到經典的cocos2dx的hello world界面
posted @ 2013-06-01 10:02 鄭興鋒 閱讀(1900) | 評論 (0) | 編輯 收藏
posted @ 2011-11-21 10:39 鄭興鋒 閱讀(338) | 評論 (0) | 編輯 收藏
posted @ 2011-11-20 13:52 鄭興鋒 閱讀(376) | 評論 (0) | 編輯 收藏
posted @ 2011-11-16 20:57 鄭興鋒 閱讀(427) | 評論 (0) | 編輯 收藏


posted @ 2011-03-22 17:38 鄭興鋒 閱讀(723) | 評論 (0) | 編輯 收藏
|
Windows系統編程之進程間通信
|
|
#include <iostream.h>
int main()
{
int a, b ;
while ( cin >> a >> b && ( a || b ) )
cout << a + b << endl ;
return 0;
}
#include <windows.h>
#include <iostream.h>
const int BUFSIZE = 4096 ;
HANDLE hChildStdinRd, hChildStdinWr, hChildStdinWrDup,
hChildStdoutRd,hChildStdoutWr,hChildStdoutRdDup,
hSaveStdin, hSaveStdout;
BOOL CreateChildProcess(LPTSTR);
VOID WriteToPipe(LPTSTR);
VOID ReadFromPipe(LPTSTR);
VOID ErrorExit(LPTSTR);
VOID ErrMsg(LPTSTR, BOOL);
void main( int argc, char *argv[] )
{
// 處理輸入參數
if ( argc != 4 )
return ;
// 分別用來保存命令行,輸入文件名(CPP/C),輸出文件名(保存編譯信息)
LPTSTR lpProgram = new char[ strlen(argv[1]) ] ;
strcpy ( lpProgram, argv[1] ) ;
LPTSTR lpInputFile = new char[ strlen(argv[2]) ];
strcpy ( lpInputFile, argv[2] ) ;
LPTSTR lpOutputFile = new char[ strlen(argv[3]) ] ;
strcpy ( lpOutputFile, argv[3] ) ;
SECURITY_ATTRIBUTES saAttr;
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;
/************************************************
* redirecting child process's STDOUT *
************************************************/
hSaveStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0))
ErrorExit("Stdout pipe creation failed\n");
if (! SetStdHandle(STD_OUTPUT_HANDLE, hChildStdoutWr))
ErrorExit("Redirecting STDOUT failed");
BOOL fSuccess = DuplicateHandle(
GetCurrentProcess(),
hChildStdoutRd,
GetCurrentProcess(),
&hChildStdoutRdDup ,
0,
FALSE,
DUPLICATE_SAME_ACCESS);
if( !fSuccess )
ErrorExit("DuplicateHandle failed");
CloseHandle(hChildStdoutRd);
/************************************************
* redirecting child process's STDIN *
************************************************/
hSaveStdin = GetStdHandle(STD_INPUT_HANDLE);
if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0))
ErrorExit("Stdin pipe creation failed\n");
if (! SetStdHandle(STD_INPUT_HANDLE, hChildStdinRd))
ErrorExit("Redirecting Stdin failed");
fSuccess = DuplicateHandle(
GetCurrentProcess(),
hChildStdinWr,
GetCurrentProcess(),
&hChildStdinWrDup,
0,
FALSE,
DUPLICATE_SAME_ACCESS);
if (! fSuccess)
ErrorExit("DuplicateHandle failed");
CloseHandle(hChildStdinWr);
/************************************************
* 創建子進程(即啟動SAMPLE.EXE) *
************************************************/
fSuccess = CreateChildProcess( lpProgram );
if ( !fSuccess )
ErrorExit("Create process failed");
// 父進程輸入輸出流的還原設置
if (! SetStdHandle(STD_INPUT_HANDLE, hSaveStdin))
ErrorExit("Re-redirecting Stdin failed\n");
if (! SetStdHandle(STD_OUTPUT_HANDLE, hSaveStdout))
ErrorExit("Re-redirecting Stdout failed\n");
WriteToPipe( lpInputFile ) ;
ReadFromPipe( lpOutputFile );
delete lpProgram ;
delete lpInputFile ;
delete lpOutputFile ;
}
BOOL CreateChildProcess( LPTSTR lpProgram )
{
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
BOOL bFuncRetn = FALSE;
ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
siStartInfo.cb = sizeof(STARTUPINFO);
bFuncRetn = CreateProcess ( NULL, lpProgram, NULL, NULL, TRUE, \
0, NULL, NULL, &siStartInfo, &piProcInfo);
if (bFuncRetn == 0)
{
ErrorExit("CreateProcess failed\n");
return 0;
}
else
{
CloseHandle(piProcInfo.hProcess);
CloseHandle(piProcInfo.hThread);
return bFuncRetn;
}
}
VOID WriteToPipe( LPTSTR lpInputFile )
{
HANDLE hInputFile = CreateFile(lpInputFile, GENERIC_READ, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
if (hInputFile == INVALID_HANDLE_VALUE)
return ;
BOOL fSuccess ;
DWORD dwRead, dwWritten;
CHAR chBuf[BUFSIZE] = {0} ;
for (;;)
{
fSuccess = ReadFile( hInputFile, chBuf, BUFSIZE, &dwRead, NULL) ;
if ( !fSuccess || dwRead == 0)
break;
fSuccess = WriteFile( hChildStdinWrDup, chBuf, dwRead, &dwWritten, NULL) ;
if ( !fSuccess )
break;
}
if (! CloseHandle(hChildStdinWrDup))
ErrorExit("Close pipe failed\n");
CloseHandle ( hInputFile ) ;
}
VOID ReadFromPipe( LPTSTR lpOutputFile )
{
HANDLE hOutputFile = CreateFile( lpOutputFile, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hOutputFile == INVALID_HANDLE_VALUE)
return ;
BOOL fSuccess ;
DWORD dwRead, dwWritten;
CHAR chBuf[BUFSIZE] = { 0 };
if (!CloseHandle(hChildStdoutWr))
ErrorExit("Closing handle failed");
for (;;)
{
fSuccess = ReadFile( hChildStdoutRdDup, chBuf, BUFSIZE, &dwRead, NULL) ;
if( !fSuccess || dwRead == 0)
{
break;
}
fSuccess = WriteFile( hOutputFile, chBuf, dwRead, &dwWritten, NULL) ;
if ( !fSuccess )
break;
}
CloseHandle ( hOutputFile ) ;
}
VOID ErrorExit (LPTSTR lpszMessage)
{
MessageBox( 0, lpszMessage, 0, 0 );
}
void CMyDlg::OnSubmit()
{
// 打開管道
HANDLE hPipe = CreateFile("\\\\.\\Pipe\\NamedPipe", GENERIC_READ | GENERIC_WRITE, \
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL) ;
if ( hPipe == INVALID_HANDLE_VALUE )
{
this->MessageBox ( "打開管道失敗,服務器尚未啟動,或者客戶端數量過多" ) ;
return ;
}
DWORD nReadByte, nWriteByte ;
char szBuf[1024] = {0} ;
// 把兩個整數(a,b)格式化為字符串
sprintf ( szBuf, "%d %d", this->nFirst, this->nSecond ) ;
// 把數據寫入管道
WriteFile ( hPipe, szBuf, strlen(szBuf), &nWriteByte, NULL ) ;
memset ( szBuf, 0, sizeof(szBuf) ) ;
// 讀取服務器的反饋信息
ReadFile ( hPipe, szBuf, 1024, &nReadByte, NULL ) ;
// 把返回信息格式化為整數
sscanf ( szBuf, "%d", &(this->nResValue) ) ;
this->UpdateData ( false ) ;
CloseHandle ( hPipe ) ;
}
// 啟動服務
void CMyDlg::OnStart()
{
CString lpPipeName = "\\\\.\\Pipe\\NamedPipe" ;
for ( UINT i = 0; i < nMaxConn; i++ )
{
// 創建管道實例
PipeInst[i].hPipe = CreateNamedPipe ( lpPipeName, PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED, \
PIPE_TYPE_BYTE|PIPE_READMODE_BYTE|PIPE_WAIT, nMaxConn, 0, 0, 1000, NULL ) ;
if ( PipeInst[i].hPipe == INVALID_HANDLE_VALUE )
{
DWORD dwErrorCode = GetLastError () ;
this->MessageBox ( "創建管道錯誤!" ) ;
return ;
}
// 為每個管道實例創建一個事件對象,用于實現重疊IO
PipeInst[i].hEvent = CreateEvent ( NULL, false, false, false ) ;
// 為每個管道實例分配一個線程,用于響應客戶端的請求
PipeInst[i].hTread = AfxBeginThread ( ServerThread, &PipeInst[i], THREAD_PRIORITY_NORMAL ) ;
}
this->SetWindowText ( "命名管道實例之服務器(運行)" ) ;
this->MessageBox ( "服務啟動成功" ) ;
}
// 停止服務
void CMyDlg::OnStop()
{
DWORD dwNewMode = PIPE_TYPE_BYTE|PIPE_READMODE_BYTE|PIPE_NOWAIT ;
for ( UINT i = 0; i < nMaxConn; i++ )
{
SetEvent ( PipeInst[i].hEvent ) ;
CloseHandle ( PipeInst[i].hTread ) ;
CloseHandle ( PipeInst[i].hPipe ) ;
}
this->SetWindowText ( "命名管道實例之服務器" ) ;
this->MessageBox ( "停止啟動成功" ) ;
}
// 線程服務函數
UINT ServerThread ( LPVOID lpParameter )
{
DWORD nReadByte = 0, nWriteByte = 0, dwByte = 0 ;
char szBuf[MAX_BUFFER_SIZE] = {0} ;
PIPE_INSTRUCT CurPipeInst = *(PIPE_INSTRUCT*)lpParameter ;
OVERLAPPED OverLapStruct = { 0, 0, 0, 0, CurPipeInst.hEvent } ;
while ( true )
{
memset ( szBuf, 0, sizeof(szBuf) ) ;
// 命名管道的連接函數,等待客戶端的連接(只針對NT)
ConnectNamedPipe ( CurPipeInst.hPipe, &OverLapStruct ) ;
// 實現重疊I/0,等待OVERLAPPED結構的事件對象
WaitForSingleObject ( CurPipeInst.hEvent, INFINITE ) ;
// 檢測I/0是否已經完成,如果未完成,意味著該事件對象是人工設置,即服務需要停止
if ( !GetOverlappedResult ( CurPipeInst.hPipe, &OverLapStruct, &dwByte, true ) )
break ;
// 從管道中讀取客戶端的請求信息
if ( !ReadFile ( CurPipeInst.hPipe, szBuf, MAX_BUFFER_SIZE, &nReadByte, NULL ) )
{
MessageBox ( 0, "讀取管道錯誤!", 0, 0 ) ;
break ;
}
int a, b ;
sscanf ( szBuf, "%d %d", &a, &b ) ;
pMyDlg->nFirst = a ;
pMyDlg->nSecond = b ;
pMyDlg->nResValue = a + b ;
memset ( szBuf, 0, sizeof(szBuf) ) ;
sprintf ( szBuf, "%d", pMyDlg->nResValue ) ;
// 把反饋信息寫入管道
WriteFile ( CurPipeInst.hPipe, szBuf, strlen(szBuf), &nWriteByte, NULL ) ;
pMyDlg->SetDlgItemInt ( IDC_FIRST, a, true ) ;
pMyDlg->SetDlgItemInt ( IDC_SECOND, b, true ) ;
pMyDlg->SetDlgItemInt ( IDC_RESULT, pMyDlg->nResValue, true ) ;
// 斷開客戶端的連接,以便等待下一客戶的到來
DisconnectNamedPipe ( CurPipeInst.hPipe ) ;
}
return 0 ;
}
posted @ 2011-02-15 12:30 鄭興鋒 閱讀(813) | 評論 (0) | 編輯 收藏
posted @ 2010-11-04 14:32 鄭興鋒 閱讀(640) | 評論 (0) | 編輯 收藏
posted @ 2010-11-04 12:13 鄭興鋒 閱讀(566) | 評論 (0) | 編輯 收藏
通信模塊圖
通信關系圖
其中有不足的地方, 希望朋友們提出意見.
posted @ 2010-10-21 17:51 鄭興鋒 閱讀(300) | 評論 (0) | 編輯 收藏
| |||||||||
| 日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
|---|---|---|---|---|---|---|---|---|---|
| 26 | 27 | 28 | 29 | 30 | 31 | 1 | |||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | |||
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | |||
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | |||
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | |||
| 30 | 1 | 2 | 3 | 4 | 5 | 6 | |||
