It is difficult to find a completely VS2010 C# example, that creates the dll in c/c++ and loads from C#.
So DIY it.
Notes:
dumpbin must be run from Microsoft Visual studio 2010 -> Visual studio tools -> visual studio 2010 command prompt. The dll EntryPoint need be found by this tool.
CallingConvention Type see this reference.
The following is the example solution, which includes two projects ( dll creating, C# call).
Clinet
#include
#include
#pragma comment(lib,”ws2_32.lib”)
int main(void)
{
WSADATA WsaDat;
if(WSAStartup(MAKEWORD(2,2),&WsaDat)!=0)
{
std::cout<<"Winsock error - Winsock initialization failed\r\n";
WSACleanup();
system("PAUSE");
return 0;
}
// Create our socket
SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(Socket==INVALID_SOCKET)
{
std::cout<<"Winsock error - Socket creation Failed!\r\n";
WSACleanup();
system("PAUSE");
return 0;
}
// Resolve IP address for hostname
struct hostent *host;
if((host=gethostbyname("localhost"))==NULL)
{
std::cout<<"Failed to resolve hostname.\r\n";
WSACleanup();
system("PAUSE");
return 0;
}
// Setup our socket address structure
SOCKADDR_IN SockAddr;
SockAddr.sin_port=htons(8888);
SockAddr.sin_family=AF_INET;
SockAddr.sin_addr.s_addr=*((unsigned long*)host->h_addr);
// Attempt to connect to server
if(connect(Socket,(SOCKADDR*)(&SockAddr),sizeof(SockAddr))!=0)
{
std::cout<<"Failed to establish connection with server\r\n";
WSACleanup();
system("PAUSE");
return 0;
}
// If iMode!=0, non-blocking mode is enabled.
u_long iMode=1;
ioctlsocket(Socket,FIONBIO,&iMode);
// Main loop int nError=WSAGetLastError(); // Close our socket entirely break; WSACleanup(); server int main() SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); SOCKADDR_IN serverInf; if(bind(Socket,(SOCKADDR*)(&serverInf),sizeof(serverInf))==SOCKET_ERROR) listen(Socket,1); SOCKET TempSock=SOCKET_ERROR; // If iMode!=0, non-blocking mode is enabled. Socket=TempSock; // Main loop int nError=WSAGetLastError(); // Shutdown our socket // Close our socket entirely break; Sleep(1000); WSACleanup(); _____________
for(;;)
{
// Display message from server
char buffer[1000];
memset(buffer,0,999);
int inDataLength=recv(Socket,buffer,1000,0);
std::cout<
if(nError!=WSAEWOULDBLOCK&&nError!=0)
{
std::cout<<"Winsock error code: "<
// Shutdown our socket
shutdown(Socket,SD_SEND);
closesocket(Socket);
}
Sleep(1000);
}
system("PAUSE");
return 0;
}
#include
#include
#pragma comment(lib,”ws2_32.lib”)
{
WSADATA WsaDat;
if(WSAStartup(MAKEWORD(2,2),&WsaDat)!=0)
{
std::cout<<"WSA Initialization failed!\r\n";
WSACleanup();
system("PAUSE");
return 0;
}
if(Socket==INVALID_SOCKET)
{
std::cout<<"Socket creation failed.\r\n";
WSACleanup();
system("PAUSE");
return 0;
}
serverInf.sin_family=AF_INET;
serverInf.sin_addr.s_addr=INADDR_ANY;
serverInf.sin_port=htons(8888);
{
std::cout<<"Unable to bind socket!\r\n";
WSACleanup();
system("PAUSE");
return 0;
}
while(TempSock==SOCKET_ERROR)
{
std::cout<<"Waiting for incoming connections...\r\n";
TempSock=accept(Socket,NULL,NULL);
}
u_long iMode=1;
ioctlsocket(Socket,FIONBIO,&iMode);
std::cout<<"Client connected!\r\n\r\n";
for(;;)
{
char *szMessage="Welcome to the server!\r\n";
send(Socket,szMessage,strlen(szMessage),0);
if(nError!=WSAEWOULDBLOCK&&nError!=0)
{
std::cout<<"Winsock error code: "<
shutdown(Socket,SD_SEND);
closesocket(Socket);
}
}
system("PAUSE");
return 0;
}
Reference from
http://www.win32developer.com/tutorial/winsock/winsock_tutorial_3.shtm
Problem:
Recently computer can’t browse microsoft.com web site, but google and others work well.
Solution:
Disable the DNS client service, form control panel.
sudo nano /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth1
iface eth1 inet dhcp
auto eth0
iface eth0 inet static
address x.y.z.a
network x.y.z.a
netmask 255.255.255.255
cat /etc/lsb-release
Wireshark is a network “sniffer” tool,
install it:
Applications –> Ubuntu Software Center –> Wireshark
Running:
ALt-F2 –> gksu - u root wireshark
http://website.com/?q=user/login
nano -c