这个socket程序错在哪里?
程序很简单的,就两个文件。把dll.cpp编译成dll,然后在exe.cpp中调用。哪位帮忙编译运行一下看看是不是也出错?先谢过啦!
源代码"exe.cpp"
__declspec(dllimport) void NullFun();
#pragma comment(lib,"dll.lib")
void main(){NullFun();}
源代码"dll.cpp"
#include <windows.h>
#include <stdio.h>
#include <winsock.h>
#pragma comment(lib,"wsock32.lib")
SOCKET sServer=NULL;
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
WSADATA ws;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
WSAStartup(0x0101,&ws);
sServer=socket(AF_INET,SOCK_STREAM,0);
break;
case DLL_PROCESS_DETACH:
if(closesocket(sServer)!=0) printf("Error:%d\n",WSAGetLastError());
else printf("Success!");
WSACleanup();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
__declspec(dllexport) void NullFun(){}