锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
#ifndef SOCK_CLASS_HPP
#define SOCK_CLASS_HPP
#include <unistd.h>
#include <iostream>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <errno.h>
namespace sockClass
{
void error_info(const char* s);
}
{
void error_info(const char* s)
{
int err_info = errno;
std::cerr << strerror(err_info) << ": errno: " << err_info << std::endl;
if (err_info == 104){
return;
}
exit(1);
}
}
#ifndef SOCK_CLASS_HPP
#define SOCK_CLASS_HPP
#include <iostream>
#include <winsock2.h>
namespace sockClass
{
void error_info(const char* s);
}
win32涓嬬殑婕旂ず浠g爜濡備笅錛?br>
{
void error_info(const char* s)
{
int winsock_err = WSAGetLastError();
perror(s);
std::cerr << "WinSock Error: " << winsock_err << std::endl;
if (winsock_err == WSAECONNRESET) {
std::cerr << "Connection reset by peer." << std::endl;
return;
}
exit(1);
}
}
]]>
#include "windows.h"
class TestClass1{
private:
int x;
public:
explicit TestClass1(int to_x):x(to_x)
{}
~TestClass1()
{
std::cerr << "destruction: 1." << std::endl;
}
void show() const
{
std::cerr << x << std::endl;
}
};
class TestClass2{
private:
int* pX;
public:
explicit TestClass2(int to_x)
{
pX = new int;
*pX = to_x;
}
~TestClass2()
{
delete pX;
std::cerr << "destruction: 2." << std::endl;
}
const int& value() const
{
return *pX;
}
};
DWORD WINAPI thread_func(LPVOID pN)
{
Sleep(200);
TestClass1 test((*((TestClass2*)pN)).value());
test.show();
return 0;
}
int main(int argc, char* argv[])
{
for (int i = 0; i < 3; ++i) {
TestClass2 n(5);
thread_func((LPVOID)&n);
std::cerr << "loop: " << i+1 << std::endl;
}
Sleep(2000);
std::cout << "main() ok." << std::endl;
return 0;
}
destruction: 1.
loop: 1
destruction: 2.
5
destruction: 1.
loop: 2
destruction: 2.
5
destruction: 1.
loop: 3
destruction: 2.
main() ok.
璇鋒寜浠繪剰閿戶緇? . .
#include "windows.h"
class TestClass1{
private:
int x;
public:
explicit TestClass1(int to_x):x(to_x)
{}
~TestClass1()
{
std::cerr << "destruction: 1." << std::endl;
}
void show() const
{
std::cerr << x << std::endl;
}
};
class TestClass2{
private:
int* pX;
public:
explicit TestClass2(int to_x)
{
pX = new int;
*pX = to_x;
}
~TestClass2()
{
delete pX;
std::cerr << "destruction: 2." << std::endl;
}
const int& value() const
{
return *pX;
}
};
DWORD WINAPI thread_func(LPVOID pN)
{
Sleep(200);
TestClass1 test((*((TestClass2*)pN)).value());
test.show();
return 0;
}
int main(int argc, char* argv[])
{
for (int i = 0; i < 3; ++i) {
TestClass2 n(5);
HANDLE hThrd;
DWORD thrdId;
hThrd = CreateThread( NULL,
0,
thread_func,
(LPVOID)&n,
0,
&thrdId);
std::cerr << "loop: " << i+1 << std::endl;
}
Sleep(2000);
std::cout << "main() ok." << std::endl;
return 0;
}
destruction: 2.
loop: 2
destruction: 2.
loop: 3
destruction: 2.
36
destruction: 1.
36
destruction: 1.
36
destruction: 1.
main() ok.
璇鋒寜浠繪剰閿戶緇? . .
]]>
#include <windows.h>
DWORD WINAPI thread_func(LPVOID pN)
{
for (int i = 0; i < *((int*)pN); ++i) {
std::cout << i+1 << "\t";
}
std::cout << std::endl;
throw "ok.";
std::cout << "thread_func() done." << std::endl;
return 0;
}
int main(int argc, char* argv[])
{
int n = 5;
try{
thread_func((LPVOID)&n);
Sleep(2000);
}
catch (const char* s) {
std::cerr << s << std::endl;
exit(1);
}
std::cout << "main() done." << std::endl;
return 0;
}
#include <windows.h>
DWORD WINAPI thread_func(LPVOID pN)
{
for (int i = 0; i < *((int*)pN); ++i) {
std::cout << i+1 << "\t";
}
std::cout << std::endl;
throw "ok.";
std::cout << "thread_func() done." << std::endl;
return 0;
}
int main(int argc, char* argv[])
{
HANDLE hThrd;
DWORD thrdId;
int n = 5;
try{
hThrd = CreateThread( NULL,
0,
thread_func,
(LPVOID)&n,
0,
&thrdId);
Sleep(2000);
}
catch (const char* s) {
std::cerr << s << std::endl;
exit(1);
}
std::cout << "main() done." << std::endl;
return 0;
}
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
璇鋒寜浠繪剰閿戶緇? . .
#include <windows.h>
DWORD WINAPI thread_func(LPVOID pN)
{
try{
for (int i = 0; i < *((int*)pN); ++i) {
std::cout << i+1 << "\t";
}
std::cout << std::endl;
throw "ok.";
}
catch (const char* s) {
std::cerr << s << std::endl;
exit(1);
}
std::cout << "thread_func() done." << std::endl;
return 0;
}
int main(int argc, char* argv[])
{
HANDLE hThrd;
DWORD thrdId;
int n = 5;
hThrd = CreateThread( NULL,
0,
thread_func,
(LPVOID)&n,
0,
&thrdId);
Sleep(2000);
std::cout << "main() done." << std::endl;
return 0;
}
]]>
鎴戜滑鐫鎵嬫瀯寤鴻嚜宸辯殑絎竴涓獁insock紼嬪簭銆?br>棣栧厛win32涓嬩笌Linux涓嬬殑socket API闇瑕佸寘鍚笉鍚岀殑澶存枃浠躲?br>鍦↙inux涓嬫槸榪欎簺錛?br>
#include <sys/socket.h>
#include <arpa/inet.h>
榪欏彲鑳藉彲浠ュ吋瀹歸潪甯稿彜鑰佺殑鐗堟湰涓殑winsock錛屾瘮濡倃in98錛岃屽井杞畼鏂規墍鎺ㄨ崘鐨勬槸錛?br>
涓婇潰鏄井杞殑瀹樻柟璇存槑錛屾垜榪欓噷鏋勫緩涓涓畝鍗曠殑綾伙紝甯屾湜姣忔浣跨敤鐨勬椂鍊欏紩鍏ヤ竴涓被瀵硅薄灝卞彲浠ヤ簡銆?br>
private:
WSADATA wsaData;
public:
WinsockAPI(int low_byte = 2, int high_byte = 2);
~WinsockAPI();
void showVersion() const;
};
WinsockAPI::WinsockAPI(int low_byte, int high_byte)
{
const WORD wVersionRequested = MAKEWORD(low_byte, high_byte);
int wsa_startup_err = WSAStartup(wVersionRequested, &wsaData);
if (wsa_startup_err != 0) {
std::cerr << "WSAStartup() failed." << std::endl;
throw wsa_startup_err;
}
}
WinsockAPI::~WinsockAPI()
{
WSACleanup();
}
void WinsockAPI::showVersion() const
{
std::cout << "The version of Winsock.dll is "
<< int(LOBYTE(wsaData.wVersion))
<< "."
<< int(HIBYTE(wsaData.wVersion))
<< "."
<< std::endl;
return;
}
http://msdn.microsoft.com/en-us/library/ms741580(VS.85).aspx
閿欒浠g爜鎵鍙嶉鐨勪俊鎭煡璇㈠湪榪欓噷錛?br>http://msdn.microsoft.com/en-us/library/ms740668(v=VS.85).aspx
鏈鍚庯紝闇瑕佹敞鎰忕殑闂鏄紝鍥犱負socket鏄瀯寤哄湪UNIX緋葷粺涓嬬殑錛圔SD socket鏄綋浠婃墍鏈塻ocket鐨勫熀紜錛夛紝鎵浠ocket寰堝ソ鐨勫埄鐢ㄤ簡UNIX浣撶郴“涓鍒囬兘鏄枃浠?#8221;鐨勬ц川錛屾瘡涓猻ocket鏈韓涔熷氨鏄竴涓猆NIX鏂囦歡鎻忚堪絎︼紝鍥犳錛孡inux涓嬬殑socket鏄敤鍏抽棴鏂囦歡鐨勫嚱鏁癱lose()鍏抽棴鐨勩備絾鏄痺in32涓嬫病榪欎釜鎬ц川錛屾墍浠insock鏄彟澶栦竴縐嶆娊璞★紝浣嗘槸濂藉湪鍚屾牱鐢╥nt浣滀負鎻忚堪絎︼紝鍏抽棴闇瑕佷笓闂ㄤ負winsock瀹氬仛鐨勫嚱鏁癱losesocket()銆?br>涓嬬瘒鏂囩珷閲嶅啓浜員CP Server鐨勪唬鐮侊紙綾葷殑鎶借薄鍜屾瀯閫犱篃閲嶆柊鍐欎簡錛屽皢鍦ㄤ笅涓绔犺В閲婏級錛屼綔涓簑insock浣跨敤鐨勬紨紺恒?
]]>
1錛歁icrosoft Visual C++ 2008 Express Edition鍙互鍙戝竷杞歡鍚楋紵
鑳斤紒
寰堝浜鴻錛屽洜涓烘槸Express鐗堬紝涓嶆槸Studio錛屾墍浠ュ彧鏄敤鏉ョ粌涔犺璦鐨勶紝涓嶈兘鍙戝竷杞歡鈥斺旈敊錛?br> 闄や簡娌℃湁MFC鍜孉TL錛屽熀鏈笂璺?.net 鐗堟湰鏄竴鏍風殑銆傚彂甯冨嚭鏉ョ殑錛屾槸瀹屾暣鐨勫彲鎵ц鏂囦歡銆?br>
2錛歏C 2008 (2005) 鍙戝竷鍑烘潵鐨勭▼搴忓繀欏婚檮甯︿笂浠栦滑鐗瑰畾鐨刣ll鏂囦歡鍚楋紵
涓嶄竴瀹氥?br> 濡傛灉鐩爣緋葷粺鏄釜緇忓父鍗囩駭鐨勭郴緇燂紝寰蔣宸茬粡涓哄叾鎵撲笂浜嗘墍闇瑕佺殑dll鏂囦歡琛ヤ竵浜嗭紝涓嶉渶瑕佸湪杞歡鍖呴噷闈㈤檮鍔犵壒瀹氱殑dll鏂囦歡銆傜壒鍒湪Vista緋葷粺涓紝浣犳洿鏄笉闇瑕乂C8鍜孷C9鐨刣ll鏂囦歡銆備絾鏄湪涓浜涜佺増鏈殑緋葷粺涓紝榪欎簺鏂囦歡灝辨槸蹇呴』鐨勩?br>
3錛歏C2008鍜孷C2005鐗瑰畾鐨刣ll鏂囦歡鏄摢浜涳紵
VC8: msvcm80.dll, msvcp80.dll, msvcr80.dll
VC9: msvcm90.dll, msvcp90.dll, msvcr90.dll
4錛氬浣曢儴緗叉枃浠訛紵
棣栧厛錛岃閫夋嫨release鐗堟湰錛涘湪鐢熸垚鍙墽琛屾枃浠訛紙exe鏂囦歡錛夌殑鏃跺欙紝浼氬緱鍒扮浉搴旂殑閮ㄧ講鏂囦歡錛坢anifest鏂囦歡錛夈?br>姣斿錛屽緱鍒癮.exe鏂囦歡錛屽氨浼氬悓鏃剁敓鎴恆.exe.intermediate.manifest鏂囦歡銆傝灝嗚繖2涓枃浠舵斁鍦ㄥ悓涓鏂囦歡澶逛笅銆?br>鐒跺悗錛屼綘闇瑕乂C8鍜孷C9鐨勯儴緗叉枃浠訛細Microsoft.VC80.CRT.manifest鍜孧icrosoft.VC90.CRT.manifest銆?br>璇峰埌浣犵殑VC瀹夎鐩綍涓嬪鎵撅紝姣斿錛?br>C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT
鎴戣繖閲屼篃鎶?涓儴緗叉枃浠剁洿鎺ヨ創鍑烘潵錛屾病瑁呯殑鐩存帴鐢ㄥ氨鏄簡錛?br>Microsoft.VC80.CRT.manifest
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<noInheritable></noInheritable>
<assemblyIdentity type="win32" name="Microsoft.VC80.CRT" version="8.0.50727.762" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
<file name="msvcr80.dll" /> <file name="msvcp80.dll" /> <file name="msvcm80.dll" />
</assembly>
<!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<noInheritable/>
<assemblyIdentity
type="win32"
name="Microsoft.VC90.CRT"
version="9.0.21022.8"
processorArchitecture="x86"
publicKeyToken="1fc8b3b9a1e18e3b"
/>
<file name="msvcr90.dll" /> <file name="msvcp90.dll" /> <file name="msvcm90.dll" />
</assembly>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level='asInvoker' uiAccess='false' />
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50727.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
</dependentAssembly>
</dependency>
</assembly>
涔熷氨鏄錛岃繕鍒浣爀xe鏂囦歡澶氬ぇ錛岃淇濊瘉姝e父榪愯錛屾垜浠渶瑕侀鍏堟嫹璐濊繖8涓枃浠?#8230;…
MinGW(gcc)緙栬瘧鐨勫氨娌¤繖浜涢夯鐑︺傛墍浠ワ紝鎴戠幇鍦ㄩ兘鏄敤涓や釜緙栬瘧鍣ㄧ紪璇戜袱涓猠xe浠ヤ緵鍙戝竷浜嗐?
]]>
鎴戠敤VC6瀵煎叆涓涓猧co鏂囦歡錛屽茍寰楀埌浜嗗畠鐨勮祫婧愭枃浠禨cript1.rc銆傚樋鍢匡紝C椋庢牸鐨勶紝閭e氨涓嶅姘旂殑鍒嗘瀽浜嗐傚師鏉ヨ鐢ㄥ埌VC6鐨?涓ご鏂囦歡錛歳esource.h錛宎fxres.h鍜學INRES.H銆傛垜鎶妑c鏂囦歡鍜?涓ご鏂囦歡錛屼互鍙奿co鍥炬爣鏂囦歡閮藉鍏C 2008 Express鐨勯」鐩腑錛屽眳鐒跺氨鏃犳儏鐨勬垚鍔熶簡錛佺湅鏉xpress浠嶇劧涓嶆劎鏄疺S鐨勯槈鍓茬増錛屽叾瀹炲氨鏄皯浜嗙偣鏉愭枡錛屽熀鏈兘鍔涜繕鏄湪鐨勩俕^
鏈鍚庢垜騫茶剢鎶?涓猦鏂囦歡鍚堝茍鍒皉c鏂囦歡涓簡錛屽茍涓旂粰瀹冭搗涓ソ璁扮殑鍚嶅瓧錛歩con.rc錛屽茍鍋氫簡綆鍗曠殑淇敼銆傜幇鍦ㄤ嬌鐢ㄨ搗鏉ュ氨鏇寸畝鍗曚簡錛?br>1銆佸皢icon.rc瀵煎叆VC2008鐨勮祫婧愶紙Resource Files錛変腑錛?br>2銆佸皢ico鏂囦歡鏇村悕涓簂ogo.ico騫舵斁鍒伴」鐩枃浠跺す涓嬶紙鍗沖瓨鏀綾pp鍜宧鏂囦歡鐨勬枃浠跺す錛夛紱
3銆佺紪璇戯紝OK浜嗭紒
鎴戝湪婕旂ず紼嬪簭涓寘鍚簡榪欎釜濂界敤鐨刬con.rc錛屾湁鍏磋叮鐨勬湅鍙嬪彲浠ョ洿鎺ヤ笅杞芥潵浣跨敤浜嗭紝鎮ㄧ敋鑷抽兘涓嶉渶瑕佽VC6銆備笅杞藉湴鍧錛氾紙鍦╮c鏂囦歡澶逛笅錛?br>http://www.fs2you.com/zh-cn/files/62f0acf0-ff11-11dc-a4f4-0014221b798a/
]]>