Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
620 B
8
Indexable
Never
int comExists(unsigned int port)
{
#if defined WIN32 || defined WIN64
    TCHAR * buffer;
    COMMCONFIG CommConfig;
    DWORD size;

    if (! (1 <= port && port <= 255)) return -1;
    buffer =  malloc (10 * sizeof(TCHAR) );

#ifdef UNICODE
    swprintf_s( (wchar_t *) buffer, 10 * sizeof(TCHAR), L"COM%d", port);
#else
    sprintf_s( buffer, 10 * sizeof(TCHAR), L"COM%d", port);
#endif
    size = sizeof CommConfig;

    if(GetDefaultCommConfig( buffer, &CommConfig, &size) == 0)
        return -1;

    return 0;
#else
    ;lk;lk;lk // here we should broke, if we not under Windows
#endif
}