Linker Error bei WNetAddConnection2



  • Hallo!
    gestern hatte ich schonmal ein Problem beim einrichten des netzlaufwerk
    Hoffe ich bin dieses mal im richtigen bereich 😉

    Also Folgendes, ich hab den Code um das netzlaufwerkt zu verbinden fertig.
    Beim Compilieren bekomme ich aber 3 Errors (Linker fehler)

    1>wnet.obj : error LNK2028: unresolved token (0A000023) "extern "C" unsigned long __stdcall WNetAddConnection2W(struct _NETRESOURCEW *,wchar_t const *,wchar_t const *,unsigned long)" (?WNetAddConnection2W@@$$J216YGKPAU_NETRESOURCEW@@PB_W1K@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
    1>wnet.obj : error LNK2019: unresolved external symbol "extern "C" unsigned long __stdcall WNetAddConnection2W(struct _NETRESOURCEW *,wchar_t const *,wchar_t const *,unsigned long)" (?WNetAddConnection2W@@$$J216YGKPAU_NETRESOURCEW@@PB_W1K@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
    1>D:\Projects\wnet\Debug\wnet.exe : fatal error LNK1120: 2 unresolved externals
    

    Irgendwie verstehe ich da nur bahnhof 🙄
    Was ist da denn falsch?

    Hier noch mein code:

    #include <Windows.h>
    #include <Winnetwk.h>
    #include <tchar.h>
    
    int main() {
    	NETRESOURCE nr;
    	ZeroMemory(&nr, sizeof(nr));
    	LPWSTR remotePath = _T("\\\\share\\folder");
    	LPWSTR localPath = _T("Z:");
    	LPWSTR pw = _T("xxxxx");
    	LPWSTR user = _T("yyyyy");
    
    	nr.dwDisplayType = RESOURCEDISPLAYTYPE_GENERIC;
    	nr.dwScope = RESOURCE_GLOBALNET;
    	nr.dwType = RESOURCETYPE_DISK;
    	nr.dwUsage = RESOURCEUSAGE_CONNECTABLE;
    	nr.lpComment = NULL;
    	nr.lpLocalName = localPath;
    	nr.lpProvider = NULL;
    	nr.lpRemoteName = remotePath;
    	DWORD iResult = WNetAddConnection2(&nr, pw, user, 0);
    	return 0;
    }
    

  • Mod

    Du musst auch die Library Mpr.lib in die Linker Optionen setzen, oder einfacher in Deinen Code folgendes einbauen:

    #pragma comment(lib, "mpr.lib")
    


  • Vielen dank, das hatte ich vergessen..
    steht sogar in der hilfe 🙄


Anmelden zum Antworten