File: libusb_version.c

package info (click to toggle)
ponyprog 3.1.4%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,920 kB
  • sloc: cpp: 35,932; python: 981; sh: 565; xml: 67; makefile: 45; ansic: 38
file content (51 lines) | stat: -rw-r--r-- 1,131 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// #include <stdlib.h>
#include <stdio.h>
// #include <string.h>
#include <libusb.h>

#if WIN32
#include <winbase.h>
typedef const struct libusb_version * (__stdcall * version_fn)(void);
#endif

int main(int argc, char *argv[])
{
    int status = 0;
    const struct libusb_version *ver;

#if WIN32

    if (argc > 1) {
        HINSTANCE dll;
        version_fn get_version;

        dll = LoadLibraryA(argv[1]);

        if (!dll) {
            fprintf(stderr, "Failed to load %s\n", argv[1]);
            return -1;
        }

        get_version = (version_fn) GetProcAddress(dll, "libusb_get_version");

        if (get_version) {
            ver = get_version();
            printf("%u.%u.%u", ver->major, ver->minor, ver->micro);
        } else {
            fprintf(stderr, "Failed to get address of libusb_get_version()\n");
            status = -1;
        }

        FreeLibrary(dll);
    } else {
        fprintf(stderr, "Windows usage: %s <libusb.dll>\n", argv[0]);
        return -1;
    }

#else
    ver = libusb_get_version();
    printf("%u.%u.%u", ver->major, ver->minor, ver->micro);
#endif

    return status;
}