Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi. I am trying to use this function[^] in my program but I don't know how to link application with the Netapi32.lib and Netapi32.dll.

For this project I am using Bloodshed Dev C++, but I have Code Blocks and Visual Studio 2010 too. Can you please explain me what I need to do to link Netapi32.lib and Netapi32.dll. Where do I need to put them, and where to download them.

This is my code:
C++
NET_API_STATUS ret  = 0 ;
LPCWSTR groupname   = L"Administrators";
LPBYTE buffer    = NULL;
DWORD entriesRead;
DWORD totalEntries;
DWORD resumeHandle = 0;

ret=NetGroupGetUsers (NULL, groupname, 0, &buffer, 32767,                    &entriesRead,&totalEntries, &resumeHandle);


And I am getting this error:
[Linker error] undefined reference to `NetGroupGetUsers@32'
Posted

1 solution

The netapi32.dll is part of Windows and is located in the Windows system directory like all other system DLLs.

To use functions from this DLL, you must link your application against the netapi32.lib library file. This library is provided by the Windows SDK which should be already installed on your system when using Visual Studio.

How to add the library to your project depends on the used development environment. At first you should ensure that the path to the Lib folder of your SDK installation is part of the library search pathes of your linker project settings. Then just add the library name to your project settings.

When using Visual studio, you may specify the library name also in the source file:
#pragma comment(lib, "netapi32.lib")
 
Share this answer
 
Comments
Member 8738025 26-Jul-12 11:27am    
Thank you very much. I did everything what you said and I succeeded.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900