Chat Program Problem with DLL

Hi I was Creating a Console Application that uses Sockets,I wanted to Create two Threads that each will Load a Function in the DLL ,using Load-time Linking the dll was like :
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<windows.h>
#include<iomanip>
#include<string>
#include<iostream>
using namespace std;
int errorhandler(string,ULONG);

#ifdef _cplusplus

extern "C"
{
#endif

	_declspec(dllexport) int _cdecl ChatInput(int clientsocket)
	{
		char buffer_in[MAX_PATH]="NULL";
		int kbytes,bytesent;
		while(1)
		{
		cout<<"Loading From Library."<<endl;
		//get input from keyboard
		cin>>buffer_in;
		//get size of input buffer
		kbytes=strlen(buffer_in)+1;
		//write data to socket
		//setup the process
		while(1)
		{
			bytesent=send(clientsocket,buffer_in,kbytes,0);
			if(bytesent==kbytes)
			{
				cout<<"Sent!"<<endl;
			}
			if(bytesent==0 ||bytesent==INVALID_SOCKET)
			{
				errorhandler("In ChatIn() :send() ",GetLastError());
			}
		}
		//but the whole of this action will be done repeatedly so we have to set an infinite loop first
		}
	}
	
	_declspec(dllexport) int _cdecl ChatOutput(int serversocket)
	{
		char buffer_out[MAX_PATH]="NULL";
		int bytesred;
	//define the ChatOutput function to read from socket and display result
		while(1)
		{
	bytesred=recv(serversocket,buffer_out,sizeof(buffer_out),0);
	if(bytesred==INVALID_SOCKET)
	{
		closesocket(serversocket);
		cout<<setw(64);
		errorhandler("In ChatOutput():recv()",GetLastError());
		cout<<endl;
		
	}
	else
	{
		//wait for some time and display progress
		Sleep(1500);
		cout<<setw(64)<<buffer_out<<endl;
	}
		}
	}

#ifdef _cplusplus
}
#endif 

the Errohandler function was loaded from another DLL which I arleady Created and I used the Object Library Created to Compile this DLL everything went fine but during function loading because I made it in a Client/Server technique The server Created a Socket and waits for connection with the listen() and the accept() but during the Function Loading from the dll each thread Returns handle value to indicate that the function loading was successfull but after that both Server and Client Terminates with no Error Messages.Am Using VS 2008 Compiler and Windows7 OS .Thanks
Topic archived. No new replies allowed.