|
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)
|
|
|
|
|
Did you include the .cpp file of your CArray in the project ?
If yes, do you have the same error if you remove the inline keyword ?
|
|
|
|
|
Hi Cedric
the .cpp file is included and no, if I remove the inline keyword it works fine.
my main application is called "testprogram" and it´s .cpp file contains
#include <stdafx.h>
#include <conio.h>
#include <string.h>
#include <malloc.h>
#include <windows.h>
#include <wincon.h>
#include <assert.h>
#ifndef _ARRAY
#include "Array.h"
#endif
where array.h is the header file from CArray.cpp
|
|
|
|
|
I found the Problem:
MS Visual C needs inline methods to be defined in the .h file rather than in the .cpp file. I moved the inline method from .cpp to .h and now it works fine.
Odd
This tells the MSDN
Function Inlining
Mixing inline and non-inline compile options on different modules can cause problems. Consider the following example that has:
A library Test.lib with inline functions.
A header file containing the function prototypes for the library (Test.h).
An application App.exe, which is linking with Test.lib using the Test.h header file.
If Test.lib is created with function inlining turned on (/Ob1 or /Ob2), you will get an unresolved external error on any inline functions from Test.lib that are used in App.exe. The function's address is not in the PST for Test.lib because the functions were inlined inside the library. You need to either disable inlining (/Ob0) when building the library or place the inline function code in the header file (Test.h).
Similarly, a project that uses function inlining yet defines the functions in a source file rather than in the header file will also get this error. The header file is included everywhere deemed appropriate, but the functions are only inlined in the source file where they are defined. Therefore, the linker sees the functions as unresolved externals when used in other modules. For example:
-- modified at 7:06 Friday 20th January, 2006
|
|
|
|
|
Kamann wrote: Since it´s a German installation
since everyone here speak english, couldn't you traduce it ?
(ok, it is a LNK2001, so MSDN tells it is an Unresolved external symbol , but please be compliant too...)
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
|
|
Hi Michael,
is this just Microsoft specific or in general ? Do other Compilers require the same ?
-- modified at 16:29 Saturday 21st January, 2006
|
|
|
|