Cannot compile the sample from MSDN IADsWinNTSystemInfo

Dear Sir,

I have copied the code from MSDN in order to use IADsWinNTSystemInfo to get the machine name and PDC. The code is listed as follows.

#include <activeds.h>
#include <stdio.h>


int main()
{
HRESULT hr;

hr = CoInitialize(NULL);

IADsWinNTSystemInfo *pNtSys;
hr = CoCreateInstance(CLSID_WinNTSystemInfo,
NULL,
CLSCTX_INPROC_SERVER,
IID_IADsWinNTSystemInfo,
(void**) &pNtSys);

BSTR bstr;
hr = pNtSys->get_UserName(&bstr);
if (SUCCEEDED(hr)) {
printf("User: %S\n", bstr);
SysFreeString(bstr);
}

hr = pNtSys->get_ComputerName(&bstr);
if (SUCCEEDED(hr)) {
printf("Computer: %S\n", bstr);
SysFreeString(bstr);
}

hr = pNtSys->get_DomainName(&bstr);
if (SUCCEEDED(hr)) {
printf("Domain: %S\n", bstr);
SysFreeString(bstr);
}

hr = pNtSys->get_PDC(&bstr);
if (SUCCEEDED(hr)) {
printf("PDC: %S\n", bstr);
SysFreeString(bstr);
}

if(pNtSys) {
pNtSys->Release();
}

CoUninitialize();
return 0;
}

However, VC reported the following error when compiling

Linking...
adscode.obj : error LNK2019: unresolved external symbol __imp__CoUninitialize@0 referenced in function _main
adscode.obj : error LNK2019: unresolved external symbol __imp__SysFreeString@4 referenced in function _main
adscode.obj : error LNK2019: unresolved external symbol __imp__CoCreateInstance@20 referenced in function _main
adscode.obj : error LNK2001: unresolved external symbol _CLSID_WinNTSystemInfo
adscode.obj : error LNK2001: unresolved external symbol _IID_IADsWinNTSystemInfo
adscode.obj : error LNK2019: unresolved external symbol __imp__CoInitialize@4 referenced in function _main
D:\VCExpress\ads\Debug\ads.exe : fatal error LNK1120: 6 unresolved externals

Thanks



Answer this question

Cannot compile the sample from MSDN IADsWinNTSystemInfo

  • AFM

    You need to add the libraries for the Win32 APIs you're calling to the linker settings.  To find out the names of libraries, search up the corresponding API in MSDN.

    krv5, you should open a new thread if you need assistance.  Unfortunately, changing to a static library does not solve the problem of compiling and linking an executable.

     


  • Luis S&amp;#225;

    Sir,

    Yes. I have installed Platform SDK.


  • Scott Fisher

  • MatthewH

    I am having a similar problem, but strangely, it goes away when I change the configuration type from Application to Static Library.

    1>------ Build started: Project: CImg_demo, Configuration: Debug Win32 ------

    1>Linking...

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__SetDIBitsToDevice@48 referenced in function "public: __thiscall cimg_library::CImgDisplay::CImgDisplay(unsigned int,unsigned int,char const *,unsigned int,unsigned int,bool,bool)" ( 0CImgDisplay@cimg_library@@QAE@IIPBDII_N1@Z)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__SetWindowPos@28 referenced in function "public: struct cimg_library::CImgDisplay & __thiscall cimg_library::CImgDisplay::resize(int,int,bool,bool)" ( resize@CImgDisplay@cimg_library@@QAEAAU12@HH_N0@Z)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__AdjustWindowRect@12 referenced in function "public: struct cimg_library::CImgDisplay & __thiscall cimg_library::CImgDisplay::resize(int,int,bool,bool)" ( resize@CImgDisplay@cimg_library@@QAEAAU12@HH_N0@Z)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__ChangeDisplaySettingsA@8 referenced in function "public: __thiscall cimg_library::CImgDisplay::~CImgDisplay(void)" ( 1CImgDisplay@cimg_library@@QAE@XZ)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__DestroyWindow@4 referenced in function "public: __thiscall cimg_library::CImgDisplay::~CImgDisplay(void)" ( 1CImgDisplay@cimg_library@@QAE@XZ)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__EnumDisplaySettingsA@12 referenced in function "public: void __thiscall cimg_library::CImgDisplay::new_lowlevel(char const *)" ( new_lowlevel@CImgDisplay@cimg_library@@QAEXPBD@Z)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__DispatchMessageA@4 referenced in function "public: static unsigned long __stdcall cimg_library::CImgDisplay::thread_lowlevel(void *)" ( thread_lowlevel@CImgDisplay@cimg_library@@SGKPAX@Z)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__GetMessageA@16 referenced in function "public: static unsigned long __stdcall cimg_library::CImgDisplay::thread_lowlevel(void *)" ( thread_lowlevel@CImgDisplay@cimg_library@@SGKPAX@Z)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__SetWindowLongA@12 referenced in function "public: static unsigned long __stdcall cimg_library::CImgDisplay::thread_lowlevel(void *)" ( thread_lowlevel@CImgDisplay@cimg_library@@SGKPAX@Z)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__GetDC@4 referenced in function "public: static unsigned long __stdcall cimg_library::CImgDisplay::thread_lowlevel(void *)" ( thread_lowlevel@CImgDisplay@cimg_library@@SGKPAX@Z)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__SetForegroundWindow@4 referenced in function "public: static unsigned long __stdcall cimg_library::CImgDisplay::thread_lowlevel(void *)" ( thread_lowlevel@CImgDisplay@cimg_library@@SGKPAX@Z)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__GetWindowRect@8 referenced in function "public: static unsigned long __stdcall cimg_library::CImgDisplay::thread_lowlevel(void *)" ( thread_lowlevel@CImgDisplay@cimg_library@@SGKPAX@Z)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__CreateWindowExA@48 referenced in function "public: static unsigned long __stdcall cimg_library::CImgDisplay::thread_lowlevel(void *)" ( thread_lowlevel@CImgDisplay@cimg_library@@SGKPAX@Z)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__DefWindowProcA@16 referenced in function "public: static long __stdcall cimg_library::CImgDisplay::proc_lowlevel(struct HWND__ *,unsigned int,unsigned int,long)" ( proc_lowlevel@CImgDisplay@cimg_library@@SGJPAUHWND__@@IIJ@Z)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__PeekMessageA@20 referenced in function "public: static long __stdcall cimg_library::CImgDisplay::proc_lowlevel(struct HWND__ *,unsigned int,unsigned int,long)" ( proc_lowlevel@CImgDisplay@cimg_library@@SGJPAUHWND__@@IIJ@Z)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__ShowWindow@8 referenced in function "public: static long __stdcall cimg_library::CImgDisplay::proc_lowlevel(struct HWND__ *,unsigned int,unsigned int,long)" ( proc_lowlevel@CImgDisplay@cimg_library@@SGJPAUHWND__@@IIJ@Z)

    1>CImg_demo.obj : error LNK2019: unresolved external symbol __imp__GetWindowLongA@8 referenced in function "public: static long __stdcall cimg_library::CImgDisplay::proc_lowlevel(struct HWND__ *,unsigned int,unsigned int,long)" ( proc_lowlevel@CImgDisplay@cimg_library@@SGJPAUHWND__@@IIJ@Z)

    1>.\Debug/CImg_demo.exe : fatal error LNK1120: 17 unresolved externals


  • Cannot compile the sample from MSDN IADsWinNTSystemInfo