Untitled

 avatar
unknown
plain_text
4 years ago
620 B
10
Indexable
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
}
Editor is loading...