Showing posts with label C++. Show all posts
Showing posts with label C++. Show all posts

Oct 8, 2013

[Unity3d] How to use C++ dll in Unity3d

1. Make CLI  Class library project in Visual Studio. 


2.  Delete all files except main cpp  file. You don`t need other auto created files. 


3. Write down the codes you need like this. 

4.  Drag and drop the dll file to Unity Assets/Plugins. It is recommended that you use release mode rather than debug mode while building the project. 
(Make sure you drag and drop to Plugins folder. Other folders  may not work or cause errors.) 
5.  Create a C# script and attach it to a game object. Write code as below.  
 Then you will have value of '1102' in integer variable "nRet". 

[C++] How to check client`s IP address.

When you call  accept(),  you will have client`s  information in  SOCKADDR_IN structure. 
 SOCKADDR_IN clntAddr; 
int addrLen = sizeof(clntAddr);  
SOCKET hSocket = ::accept(mListenSocket, (SOCKADDR*)&clntAddr, &addrLen); 
printf("Server IP = %s\n"inet_ntoa(clntAddr.sin_addr)); 

Result will be like this:     "Server IP = 211.22.32.15"