Search code examples
c++windows-phone-8static-linking

GetModuleHandle on Windows Phone 8.0


I am trying to load the winsock dll on Windows Phone 8.0 native C++ library.

 HMODULE ws2mod = GetModuleHandle("ws2_32.dll");
    win_getaddrinfo = GetProcAddress(ws2mod, "getaddrinfo");
    if (win_getaddrinfo)
        return win_getaddrinfo(node, service, hints, res); 

I am getting a linker error:

Error   178 error LNK2019: unresolved external symbol GetModuleHandle referenced in

When I double click and do Goto Definition on Visual Studio, I see the definition in libloaderapi.h file within Windows Phone Kits.

What is the library that I should link with? Here are the current libraries:

WindowsPhoneCore.lib
RuntimeObject.lib
PhoneAppModelHost.lib

Solution

  • GetModuleHandle is not on the list of approved APIs for WP8.

    However getaddrinfo is. I think you can just link to ws2_32.lib and call getaddrinfo directly, rather than via GetProcAddress.