|
See the following from which u can get the IP address of the local machine
gethostname(szHostName, strlen( szHostName ) ); //returns machine name
strFullName="\\\\"+szHostName;
host = gethostbyname(strFullName); //returns hostent*
if(host!=NULL)
{
ptr = (struct in_addr *) host->h_addr_list[0];
int a = ptr->S_un.S_un_b.s_b1; // Eg. 211.40.35.76 split up like this.
int b = ptr->S_un.S_un_b.s_b2; // 40
int c = ptr->S_un.S_un_b.s_b3; // 35
int d = ptr->S_un.S_un_b.s_b4; // 76
strTemp.Format("%d.%d.%d.%d",a,b,c,d);
AfxMessageBox("IP:="+strTemp);
}
Thanks and Regards
Laxman
FAILURE is the first step towards SUCCESS
-- modified at 23:45 Friday 20th January, 2006
|
|
|
|
|
|
Yes, MFC. I'm not using .NET. just pure visual c++.
waxie
|
|
|
|
|
|
Yeah. It's in .NET. I just want to retrieve IP address and then store it in a string.
waxie
|
|
|
|
|
waxie wrote: It's in .NET
It's not in .Net. It's in SDK.
Anyway it will work smoothly so don't worry.
Anyway why are you reposting the same question again. I guess Laxman already answered you.
Jesus Loves <marquee direction="up" height="40" scrolldelay="1" step="1" scrollamount="1" style="background:#aabbcc;border-bottom:thin solid 1px #6699cc">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
I've tried using the code but it still does not work.
I'm making some tweaks. Hopefully this will work.
waxie
|
|
|
|
|
I'm getting these errors when linking:
error LNK2001: unresolved external symbol __imp__gethostbyname@4
error LNK2001: unresolved external symbol __imp__gethostname@8
you have any idea what causes these errors? I guess the linker is looking for a lib file or something..
waxie
|
|
|
|
|
|
Yes I have included winsock.h in my project - else it would produce symbol not found errors. I'm using VC6.
|
|
|
|
|
|
Yes, I have. I don't have errors now but it really doesn't output anything. If it's alright with you, can you check if this code works fine in your pc and outputs your IP ad?
Thanks so much.
waxie
|
|
|
|
|
Try this one....
You may have to modify it a bit to suit your needs....
void CHostNameAndIpDlg::OnBnClickedFind()
{
WSADATA WSAData;
::ZeroMemory(&WSAData, sizeof(WSAData));
::WSAStartup(MAKEWORD(1,0), &WSAData);
char szHostName[MAX_PATH];
::gethostname(szHostName, MAX_PATH);
AfxMessageBox(szHostName);
char szIps[128];
struct sockaddr_in sckAddr;
struct hostent *pHost;
pHost = ::gethostbyname(szHostName);
for(int index=0; pHost->h_addr_list[index] != NULL;index++)
{
memcpy(&sckAddr.sin_addr, pHost->h_addr_list[index], pHost->h_length);
strcpy(szIps, inet_ntoa(sckAddr.sin_addr));
strcat(szIps, ", ");
AfxMessageBox(szIps);
szIps[0] = 0;
}
::WSACleanup();
}
AfxMessageBox denotes output. You can replace it with your own output procedure. I have commented my output procedure.
First it will display a message box containing host name, second it will display message boxes for each IP found(If there are more that one).
Jesus Loves <marquee direction="up" height="40" scrolldelay="1" step="1" scrollamount="1" style="background:#aabbcc;border-bottom:thin solid 1px #6699cc">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
Thank you very much. I think you deserve a 10.
|
|
|
|
|
|
Okiems. Thank you very much Owner drawn! I really appreciate your help.
waxie
|
|
|
|
|
Hi!
Can anyone point me to the solution of the following problem :
i want to retrieve information about the gfx card installed in the system (driver, driverversion, physical ram, chip type, etc) as well as information about other hardware-components and drivers.
For the display i currently use
INT cnt = 0;
FLAG ret = TRUE;
while (ret)
{
DISPLAY_DEVICE ddev;
ddev.cb = sizeof(DISPLAY_DEVICE);
ret = EnumDisplayDevices(NULL, cnt,&ddev,0);
if ((ret) && (!(ddev.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER)))
{ // no need for mirroring drivers (ex. netmeeting driver)
DEVMODE devMode;
devMode.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(ddev.DeviceName,ENUM_CURRENT_SETTINGS,&devMode);
/*
Process device Info
*/
} // if (ret)
cnt++;
} // while (ret)
but the gathered information here is insufficient...
My application is a non-MFC application, so i am looking for plain SDK mechanisms
Thanks in advance
-- modified at 6:07 Friday 20th January, 2006
|
|
|
|
|
|
thanks a lot. that was the information i was missing
AmorphisOne
|
|
|
|
|
Hi everybody... I know there was an API function that called from a process will return you the path to where the EXE that launched the process is located. If called from a DLL it would return the path to where the EXE that loaded the DLL is located and if called from an EXE it would return the path to the EXE. But I forgot how it was named and couldn't find it on quick Google / MSDN searches. Can you please refresh my memory?
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
GetModuleFileName(...);
this is this.
|
|
|
|
|
Thank you! :- D. I remember now.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
I have a problem with visual c++ V.6
Without the inline statement it works fine, with inline the compiler refuses creating code. Problem appears to be linked with "inline int CArray::getFw()"
Here´s a sniplet:
from CArray.h:
typedef int T;
class CArray
{
public:
CArray( int, T = 0);
int getFw();
void SetFeld( int, T );
T GetFeld( int);
T& operator[ ](int );
virtual ~CArray();
private:
int fw;
T* p;
};
from CArray.cpp:
....
inline int CArray::getFw()
{
return fw;
}
|
|
|
|
|
What's the exact error message ?
|
|
|
|
|
Since it´s a German installation it´s:
Generieren von Code...
Linker-Vorgang läuft...
Testprogramm.obj : error LNK2001: Nichtaufgeloestes externes Symbol "public: int __thiscall CArray::getFw(void)" (?getFw@CArray@@QAEHXZ)
Debug/Testprogramm.exe : fatal error LNK1120: 1 unaufgeloeste externe Verweise
Fehler beim Ausführen von link.exe.
Browse-Informationsdatei wird erstellt...
Testprogramm.exe - 2 Fehler, 0 Warnung(en)
|
|
|
|