From: Rui L. <rg...@ru...> - 2011-01-23 23:50:28
|
Hello, I'm trying to use the NetUserAdd function from netapi32 library, but its failing on me: gcc -shared -oservice-setup-helper.dll -lnetapi32 service-setup-helper.c C:\Users\RUILOP~1\AppData\Local\Temp\ccHqnS1l.o:service-setup-helper.c:(.text+0x5f): undefined reference to `NetUserAdd@16' collect2: ld returned 1 exit status Note that objdump only reports _NetUserAdd@16 (with leading underscore): objdump -t /c/Dev/MinGW/lib/libnetapi32.a | grep UserAdd [ 7](sec 1)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 _NetUserAdd@16 [ 8](sec 5)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 __imp__NetUserAdd@16 What is going on? How do I use NetUserAdd? TIA! Best Regards, Rui Lopes PS here's the source: #define _WIN32_WINNT 0x0501 #ifndef UNICODE #define UNICODE #endif #include <windows.h> #include <lm.h> #include <wchar.h> __declspec(dllexport) int __stdcall CreateServiceUser(LPWSTR userName, LPWSTR password, LPWSTR comment) { USER_INFO_1 userInfo; ZeroMemory(&userInfo, sizeof(userInfo)); userInfo.usri1_name = userName; userInfo.usri1_password = password; userInfo.usri1_priv = USER_PRIV_USER; userInfo.usri1_comment = comment; userInfo.usri1_flags = UF_DONT_EXPIRE_PASSWD | UF_SCRIPT; DWORD paramError; NET_API_STATUS status = NetUserAdd(NULL, 1, (PBYTE)&userInfo, ¶mError); return status; } |