There is such code:

#include <ras.h> #include <raserror.h> #include <stdio.h> #include <windows.h> int main(int argc, char** argv) { DWORD dwEntryInfoSize = 0; DWORD dwDeviceInfoSize = 0; DWORD dwRet = 0; LPRASENTRY lpRasEntry = NULL; LPBYTE lpDeviceInfo = NULL; /** * Create RAS connection * * Get buffer sizing information for a default phonebook entry */ if ((dwRet = RasGetEntryProperties(NULL, "", NULL, &dwEntryInfoSize, NULL, &dwDeviceInfoSize)) != ERROR_SUCCESS) { if (dwRet != ERROR_BUFFER_TOO_SMALL) { printf("RasGetEntryProperties error: %s\n", GetLastError()); return EXIT_FAILURE; } } if (dwEntryInfoSize == 0) { printf("Entry info size error: %s\n", GetLastError()); return EXIT_FAILURE; } lpRasEntry = (LPRASENTRY) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwEntryInfoSize); if (lpRasEntry == NULL) { printf("HeapAlloc RasEntry error: %s\n", GetLastError()); return EXIT_FAILURE; } if (dwDeviceInfoSize) { lpDeviceInfo = (LPBYTE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwDeviceInfoSize); } lpRasEntry->dwSize = sizeof(RASENTRY); // Вот здесь возникает ошибка: Overlapped I/O operation is in progress. // Кстати, ошибка возникает в Windows XP а в Windows 10 все работает // прекрасно. Мне нужно чтобы этот код работал именно в XP if ((dwRet = RasGetEntryProperties(NULL, "", lpRasEntry, &dwEntryInfoSize, lpDeviceInfo, &dwDeviceInfoSize)) != ERROR_SUCCESS) { printf("RasGetEntryProperties error: %s\n", GetLastError()); return EXIT_FAILURE; } // Validate new phonebook name "TestEntry" if ((dwRet = RasValidateEntryName(NULL, "TestEntry")) != ERROR_SUCCESS) { printf("RasValidateEntryName error: %s\n", GetLastError()); return EXIT_FAILURE; } // Install a new phonebook entry, "TestEntry", using default properties if ((dwRet = RasSetEntryProperties(NULL, "TestEntry", lpRasEntry, dwEntryInfoSize, lpDeviceInfo, dwDeviceInfoSize)) != ERROR_SUCCESS) { printf("RasSetEntryProperties error: %s\n", GetLastError()); return EXIT_FAILURE; } // Deallocate memory for the connection buffer HeapFree(GetProcessHeap(), 0, lpRasEntry); lpRasEntry = NULL; return EXIT_SUCCESS; } 

This code creates a normal dial-up connection. And I'm stuck on this bug.

enter image description here

    1 answer 1

    There were errors in the code ...

    Error # 1: Ras * functions do not set error codes for GetLastError (). Those. GetLastError () does not make sense. They return error codes as a DWORD. Read the Routing and Remote Access Error Codes on MSDN.

    Error # 2: Beginning with NT, in the RasGetEntryProperties () function 5 and 6, the parameters are not used and must be NULL.

    Mistake # 3: The most insidious. The fact is that the dimensions of the RASENTRY structure for some Windows operating systems differ. For example, between XP and 10. Therefore, somewhere in the header files we have to specify something like this:

     #define WINVER 0x0501 #define _WIN32_WINNT 0x0501 

    More details can be read in MSDN. Modifying WINVER and _WIN32_WINNT. In this case, we specified the version of Windows XP. That is what I needed. And Overlapped I / O operation is in progress in general has nothing to do with us in this case. We simply deduced the result of GetLastError () which probably appeared somewhere in the depths of Windows during the execution of the previous functions.