Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Hex Converter

0.00/5 (No votes)
13 Nov 2000 1  
Converts a lump of binary/text data to hex format.

Introduction

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, with VC++ 6.0. It's very simple in use, and I thought it 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();

You need to register the component before use. If you spot any problems or possible enhancements please let me know at [Mukesh Gupta].

References:

  • Windows Programming With MFC By: Jeff Prosise

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here