'C++ Problem with CPR GET request in dll at exxecution time in

I have a custom CSP dll that has to make a GET request to an API. I am making the request with CPR library, but when I make this call the program hangs.

auto r = cpr::Get(cpr::Url{ URL });

I am testing with a console application loading the library and calling to the exported method.

I´m developing with Visual Studio dll project and I collect the dependencies from vcpkg.

If I make this call from the console application it works, but when I make the request from the DLL it hangs and connection is never done.

I have been trying other libraries for making the request and all of them hang when I try to make the call to the endpoint.

Thanks in advance!

EDIT:

If I make the request in a console application like this it works

BOOL Authenticate() {

    auto r = cpr::Get(cpr::Url{ URL });

    long sc = r.status_code;
    if (sc != 200) {
        return FALSE;
    }

    return TRUE;

}


int main()
{
    if (Authenticate()) {
        return 0;
    }
    else {
        return -1;
    }

}

The problem is that if I make the request to the same method exported from a dll it hangs when the GET request is done. The dll is compiled with Visual Studio -> dll project. Sample here, where method authenticate is a is in previous example.

int main()
{
    HINSTANCE hinstDLL;
    hinstDLL = LoadLibrary(PATH_TO_DLL);
    if (!hinstDLL)
        printf("LoadLibrary error %x\n", GetLastError()); 
    else {
        Authenticate_DLL lpproc;
        lpproc = (CPAcquireContext_DLL)GetProcAddress(hinstDLL, "Authenticate");
        if (!lpproc())
        {
            printf("LoadMethod error %x\n", GetLastError());
        }

    }

}

URL is a REST API and in remote server no request is done, so CPR is not making the call

EDIT2:

After a lot of testing requests only hang when I make use of HTTPS URLs. If the URL is just HTTP the request is done



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source