Показать сообщение отдельно

  #2403  
Старый 20.02.2009, 14:11
Kuzya
Участник форума
Регистрация: 27.04.2008
Сообщений: 224
С нами: 9494306

Репутация: 313
По умолчанию

Недавно занялся C++(совсем недавно), и сегодня попытался написать обычную работу с сокетами - открытие порта и его прослушиваение. Подключил winsock2.h, вроде сделал все как нужно, но на вызове функции socket компилятор выдаёт ошибку.
Цитата:
1>------ Build started: Project: test, Configuration: Debug Win32 ------
1>Compiling...
1>test.cpp
1>Linking...
1>test.obj : error LNK2028: unresolved token (0A00000F) "extern "C" unsigned int __stdcall socket(int,int,int)" (?socket@@$$J212YGIHHH@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
1>test.obj : error LNK2028: unresolved token (0A000010) "extern "C" int __stdcall WSAStartup(unsigned short,struct WSAData *)" (?WSAStartup@@$$J18YGHGPAUWSAData@@@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
1>test.obj : error LNK2019: unresolved external symbol "extern "C" unsigned int __stdcall socket(int,int,int)" (?socket@@$$J212YGIHHH@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
1>test.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall WSAStartup(unsigned short,struct WSAData *)" (?WSAStartup@@$$J18YGHGPAUWSAData@@@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
1>C:\Projects\test\Debug\test.exe : fatal error LNK1120: 4 unresolved externals
1>Build log was saved at "file://c:\Projects\test\test\Debug\BuildLog.htm"
1>test - 5 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
А вот сам исходник.

Код:
#include "stdafx.h"
#include "Form1.h"
#include "winsock2.h"

using namespace test;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
	WSADATA wsaData;
        SOCKET s;

        WSAStartup(MAKEWORD(2,2), &wsaData);
	s = socket(AF_INET,SOCK_STREAM,0);
    
	// Enabling Windows XP visual effects before any controls are created
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 

	// Create the main window and run it
	Application::Run(gcnew Form1());

	return 0;
}
Помогите пожалуйста разобраться.
 
Ответить с цитированием