C++语言中，int __cdecl main(int argc, char* argv[]) {
    int status = -1;
    char device_base_path[MAX_PATH + 1] = "";
    DWORD num_devices = get_devices(GUID_DEVINTERFACE_XDMA, device_base_path, sizeof(device_base_path));
    verbose_msg("Devices found: %d\n", num_devices);
    if (num_devices < 1) {
        goto Exit;
    }
    if (!parse(argc, argv)) {
        goto Exit;
    }
    verbose_msg("Device base path: %s\n", device_base_path);
    char device_path[MAX_PATH + 1] = "";
    strcpy_s(device_path, sizeof device_path, device_base_path);
    strcat_s(device_path, sizeof device_path, "\\");
    strcat_s(device_path, sizeof device_path, options.device);
    verbose_msg("Device node: %s\n", options.device);
    HANDLE device = CreateFile(device_path, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (device == INVALID_HANDLE_VALUE) {
        fprintf(stderr, "Error opening device, win32 error code: %ld\n", GetLastError());
        goto Exit;
    }
    if (INVALID_SET_FILE_POINTER == SetFilePointerEx(device, options.address, NULL, FILE_BEGIN)) {
        fprintf(stderr, "Error setting file pointer, win32 error code: %ld\n", GetLastError());
        goto CleanupDevice;
    }

    LARGE_INTEGER start;
    LARGE_INTEGER stop;
    LARGE_INTEGER freq;
    QueryPerformanceFrequency(&freq);

    if (options.direction == C2H) {
        verbose_msg("reading from device...\n");

        // allocate and zero-initialize memory to hold read bytes
        options.data = allocate_buffer(options.size, options.alignment);
        if (!options.data) {
            fprintf(stderr, "Error allocating %ld bytes of memory, error code: %ld\n", options.size, GetLastError());
            goto CleanupDevice;}
 memset(options.data, 0, options.size);
        QueryPerformanceCounter(&start);
        if (!ReadFile(device, options.data, options.size, &options.size, NULL)) {
            fprintf(stderr, "ReadFile from device %s failed with Win32 error code: %ld\n",
                    device_path, GetLastError());
            goto CleanupDevice;
        }
        QueryPerformanceCounter(&stop);
        if (options.binary == TRUE) {
            print_bytes_binary(options.data, options.size);
        }
        else {
            print_bytes(options.address.QuadPart, options.data, options.size);
        }

        double time_sec = (unsigned long long)(stop.QuadPart - start.QuadPart) / (double)freq.QuadPart;
        printf("%ld bytes received in %fs\n", options.size, time_sec);
    }
    else {
        verbose_msg("writing to device...\n");

        if (options.file) {
            FILE* inputFile;
            if (fopen_s(&inputFile, options.file, "rb") != 0) {
                fprintf(stderr, "Could not open file <%s>\n", options.file);
                goto CleanupDevice;
            }
            if (options.size == 0) {
                fseek(inputFile, 0, SEEK_END);
                fpos_t fpos;
                fgetpos(inputFile, &fpos);
                fseek(inputFile, 0, SEEK_SET);
                options.size = (DWORD)fpos;
            }

            options.data = allocate_buffer(options.size, options.alignment);
            if (!options.data) {
                fprintf(stderr, "Error allocating %ld bytes of memory, error code: %ld\n", options.size, GetLastError());
                goto CleanupDevice;
            }
            options.size = (DWORD)fread(options.data, 1, options.size, inputFile);

            fclose(inputFile);
            printf("%ld bytes read from file %s\n", options.size, options.file);
        }

        if (options.data == NULL) {
            printf("Error! No valid data given!\n");
            usage(argv[0]);
            goto CleanupDevice;
        }

        QueryPerformanceCounter(&start);
        if (!WriteFile(device, options.data, options.size, &options.size, NULL)) {
            fprintf(stderr, "WriteFile to device %s failed with Win32 error code: %d\n",
                    device_path, GetLastError());
            goto CleanupDevice;
        }
        QueryPerformanceCounter(&stop);
        if (options.verbose) {
            print_bytes(options.address.QuadPart, options.data, options.size);
        }

        double time_sec = (unsigned long long)(stop.QuadPart - start.QuadPart) / (double)freq.QuadPart;
        printf("%ld bytes written in %fs\n", options.size, time_sec);
    }

    status = 0; 
CleanupDevice:
    CloseHandle(device);
Exit:
    if (options.device)	free(options.device);
    if (options.file)	free(options.file);
    if (options.data)	_aligned_free(options.data);
    return status;
}  的意思