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 :
#include<windows.h>
#include<iomanip>
#include<string>
#include<iostream>
usingnamespace 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