65.9K
CodeProject 正在变化。 阅读更多。
Home

十六进制转换器

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0投票)

2000年11月13日

viewsIcon

103512

downloadIcon

1008

将二进制/文本数据转换为十六进制格式。

引言

这是一个简单的 COM 组件,可以将二进制/文本数据转换为十六进制格式。我只是为了一个项目查看二进制数据而编写的。该组件仅支持两个接口;IHexConverterISupportErrorInfo,以及四个方法。它是在 Win98 上使用 VC++ 6.0 开发的。它使用起来非常简单,我想它可能对其他人有用。

方法

SetFile([in] BSTR bstrFilePath);
SetString([in] BSTR bstrInput);
GetLineCount([out] long* pLineCount)
GetNextLine([out] BSTR* pbstrOutput)

典型用法 (在 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); 

    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();

在使用前需要注册该组件。如果您发现任何问题或可能的改进,请通过 Mukesh Gupta 与我联系。

参考文献

  • Windows 编程与 MFC 作者:Jeff Prosise
© . All rights reserved.