HexConvertor : A COM Component

This is a simple COM component that converts a lump of binary/text data to the hex format. I just wrote it for one of my projects to have a look at the binary data. The component supports only two interfaces IHexConverter and ISupportErrorInfo with four methods. It's been developed on Win98, VC++ 6.0. It's very simple in use. Thought might be useful for others.

Methods:

SetFile([in] BSTR bstrFilePath);

SetString([in] BSTR bstrInput);

GetLineCount([out] long* pLineCount)

GetNextLine([out] BSTR* pbstrOutput)

 

Typical Usage (in C++):

    ::CoInitialize(NULL);

    IHexConvertor* pHC = NULL;

    HRESULT hr = CoCreateInstance(CLSID_HexConverter,

                                    CLSTX_INPROC_SERVER,

                                    IID_IHexConverter,

                                    (void**)&pHC);

   

    //Set the input file / string

    CComBSTR bstrFile(_T("C:\MyFile.dat"))

    hr = pHC->SetFile(bstrFile);

or

    CComBSTR bstrInput(_T("blah........blah............"));

    hr = pHC->SetString(bstrString);

    //get the total no. of lines in the output string(containing 16 bytes each)

    long lLines;

    hr = pHC->GetLineCount(&iLines);

   

    //get each line

    for(int i = 0; i < iLines; i++)

    {

        CComBSTR bstrOutput;

        hr = pHC->GetNextLine(&bstrOutput);

    }

    pHC->Release();

    pHC = NULL;

    ::CoUnInitialize();