Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is comsupp(w).lib?

I'm trying to compile some COM code, the example here. I get the compilation fine, but linking complaints about ConvertStringtoBSTR missing. After doing some research, I found out that said symbol should be in comsupp.lib. The problem is that I can not find this library in the Windows SDK... where is the library or the function?

like image 309
dsign Avatar asked Feb 25 '12 14:02

dsign


2 Answers

Just copy the comment from @HansPassant so as to make the comment to become an answer. Not trying to steal his answer, but just want to let people know there is an answer to this question.

It is not an SDK file, it is a Visual Studio file. Stored in the vc/lib directory. VS license required. – Hans Passant Feb 25 '12 at 19:09

like image 118
user3454439 Avatar answered Sep 25 '22 19:09

user3454439


Seven years later in case of googling ... If you don't have VS, you may just copy and use the code of the WineHQ source for this function, something like that :

char* WINAPI ConvertBSTRToString(BSTR pSrc)
{
    DWORD cb, cwch;
    char *szOut = NULL;

    if (!pSrc) return NULL;

    /* Retrieve the size of the BSTR with the NULL terminator */
    cwch = ::SysStringLen(pSrc) + 1;

    /* Compute the needed size with the NULL terminator */
    cb = ::WideCharToMultiByte(CP_ACP, 0, pSrc, cwch, NULL, 0, NULL, NULL);
    if (cb == 0)
    {
        cwch = ::GetLastError();
        ::_com_issue_error(!IS_ERROR(cwch) ? HRESULT_FROM_WIN32(cwch) : cwch);
        return NULL;
    }

    /* Allocate the string */
    szOut = (char*)::operator new(cb * sizeof(char));
    if (!szOut)
    {
        ::_com_issue_error(HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY));
        return NULL;
    }

    /* Convert the string and NULL-terminate */
    szOut[cb - 1] = '\0';
    if (::WideCharToMultiByte(CP_ACP, 0, pSrc, cwch, szOut, cb, NULL, NULL) == 0)
    {
        /* We failed, clean everything up */
        cwch = ::GetLastError();

        ::operator delete(szOut);
        szOut = NULL;

        ::_com_issue_error(!IS_ERROR(cwch) ? HRESULT_FROM_WIN32(cwch) : cwch);
    }

    return szOut;
}
like image 28
Denis LALANNE Avatar answered Sep 22 '22 19:09

Denis LALANNE