0

I'm a complete noob in c++, wasn't going to learn it any time soon, but somehow i've been delegated a small c++ task. I need to write a programm, that'll show a list of users of the windows After searching for a while on forums i found the script as follows:

#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "netapi32.lib")
 
#include <stdio.h>
#include <windows.h>
#include <lm.h>
#include <locale.h>
 
int main()
{
    setlocale(LC_ALL, "Rus");
    DWORD dwlevel = 0;
    DWORD dwfilter = 0;
    USER_INFO_0 * theEntries = new USER_INFO_0[20];
    DWORD dwprefmaxlen = 512;
    DWORD dwentriesread;
    DWORD dwtotalentries;
    NET_API_STATUS result;
 
    result = NetUserEnum(NULL, dwlevel, dwfilter, (LPBYTE*)&theEntries, dwprefmaxlen, &dwentriesread, &dwtotalentries, NULL);
    for (int i = 0; i < dwentriesread; i++)
    {
        printf("%i: ", i+1);
        wprintf(L"%s \n", theEntries[i].usri0_name);
    }
    NetApiBufferFree(theEntries);
}

When compiling, i get the following errors:

main.cpp:25: undefined reference to `NetUserEnum'
main.cpp:62: undefined reference to `NetApiBufferFree'

What am i doing wrong? Aren't the methods included in one of the include directive?

  • 2
    You seem to be compiling with GCC, which does not support this pragma. You need to link with netapi32.lib explicitly. See this question: [#pragma comment(lib, "xxx.lib") equivalent under Linux?](https://stackoverflow.com/questions/1685206/pragma-commentlib-xxx-lib-equivalent-under-linux) – Botje Aug 14 '20 at 10:23
  • @Botje Thank you! It does clear up a lot of things – white_tuuth Aug 14 '20 at 12:36

0 Answers0