Raised This Month: $ Target: $400
 0% 

Winsock


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ajaxx
Senior Member
Join Date: Oct 2009
Old 11-02-2010 , 17:13   Winsock
Reply With Quote #1

I’m trying to get the hostname of the computer running my plugin with gethostname(char * name, int namelen) from winsock.h. I execute it in code like so:
Code:
#include "Player.h"
#include "winsock.h"
   
  Player::Player(_bstr_t connectionString)
  {
        _connectionString = connectionString;
   
        ::CoInitialize(NULL);
   
        _connectionPtr.CreateInstance(__uuidof(ADODB::Connection));
        
        if(_connectionPtr)
        {
              _connectionPtr->Open(_connectionString, "", "", 0);
        }
   
        GetServerSettings(GetHostname());
  }
   
  char* Player::GetHostname()
  {
        char* name = "";
        int nameLen = 50;
        ::gethostname(name, nameLen);
   
        return name;
  }
   
  void Player::GetServerSettings(char * hostname)
  {
        ADODB::_RecordsetPtr recordsetPtr = Provider::GetServerSettings(_connectionPtr, hostname);
   
        if(recordsetPtr && !recordsetPtr->EndOfFile)
        {
              _gameServerType = GameServerType(int(recordsetPtr->Fields->Item["GameServerType_ID"]->Value));
              recordsetPtr->Close();
        }
   
        recordsetPtr->Release();
  }
   
  Player::~Player()
  {
  }
I’m getting:
Code:
Error      1              error LNK2019: unresolved external symbol _gethostname@8 referenced in function "private: char * __thiscall Player::GetHostname(void)" (?GetHostname@Player@@AAEPADXZ)               Player.obj
How do I properly link to winsock.h?
Ajaxx is offline
API
Veteran Member
Join Date: May 2006
Old 11-03-2010 , 13:21   Re: Winsock
Reply With Quote #2

You need to link the lib file. winsock32.lib maybe?
But please remember that you are completely removing linux compatibility, unless you can find a nix' equivalent and use #ifdef's
__________________
API is offline
Send a message via AIM to API
Mani
Veteran Member
Join Date: Dec 2004
Location: UK
Old 11-03-2010 , 13:31   Re: Winsock
Reply With Quote #3

For winsock2

http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
__________________
Installation files, documentation and help can be found at: -

www.mani-admin-plugin.com
Mani is offline
API
Veteran Member
Join Date: May 2006
Old 11-03-2010 , 19:48   Re: Winsock
Reply With Quote #4

Aha!
Quote:
Ws2_32.lib
Good luck. Remember, you are going to need that Linux equivalent if you don't want to break nix support.
__________________
API is offline
Send a message via AIM to API
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 11-05-2010 , 19:53   Re: Winsock
Reply With Quote #5

Quote:
Originally Posted by pimpinjuice View Post
You need to link the lib file. winsock32.lib maybe?
But please remember that you are completely removing linux compatibility, unless you can find a nix' equivalent and use #ifdef's
Linux is overrated, real server ops run Windows so they can be TCAdmin Guinea Pigs!

http://linux.die.net/man/2/gethostname

Looks like a possible linux equivalent, not sure it is returning the same thing that the windows version is though.
CrimsonGT is offline
Ajaxx
Senior Member
Join Date: Oct 2009
Old 11-11-2010 , 03:17   Re: Winsock
Reply With Quote #6

Thanks Mani,
I found that page, that’s where I got my sample code from.

Thanks PimpinJuice,
That’s the piece I was missing.
Ajaxx is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:06.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode