让vc6和最新的msdn集成

http://www.codeproject.com/macro/VSNetHelp.asp

Integrate latest MSDN with VC6 and Hook functions of COM

By Chunhua Liu

Introduction

After Oct. 2001, you cannot get help by pressing F1 in VC6 with latest MSDN.
Microsoft has changed the help format from CHM to document explorer.
?   Is it possible to use latest MSDN in VC6?
?   The answer is YES!

Details

First, we must know how VC6 brings up the help after you press F1. This is
easy if you have a debugger such as Soft-ICE.

If you don't install MSDN, after you press F1, VC6 will popup a message box
says you haven't installed MSDN. Set a breakpoint at MessageBox. Press F1
and debugger will popup. Look at the stack. You will see this function was
called from "C:/Program Files/Common Files/Microsoft
Shared/VS98/vshelp.dll".

Then we use Dependency Walker ("depends" in Visual Studio Tools) to see
what functions are exported. We will see DllRegisterServer and
DllUnregisterServer. It's obviously a COM.

Use VC6 to create a simple console project. Add the following line to your
.cpp file.

#import "C:/Program Files/Common Files/Microsoft Shared/VS98/vshelp.dll"
And build your project.

Open the Debug directory, you will find "vshelp.tlh" and "vshelp.tli"
Open "vshelp.tlh", you will see:

struct __declspec(uuid("854d7ac0-bc3d-11d0-b421-00a0c90f9dc4"))
    IVsHelpSystem : IUnknown
{
    //
    // Wrapper methods for error-handling
    //

    HRESULT KeywordSearch (
        LPWSTR pszKeyword,
        long dwFlags,
        long dwReserved );
    HRESULT ALinkSearch (
        LPWSTR pszALink,
        long dwFlags,
        long dwReserved );
    ...

The function KeywordSearch was called when you press F1. So if we replace
this function and call latest MSDN's help function, it should work.
Then how to do this? Since it's a COM interface, it's easy to hook it.
Basically a COM interface is a C++ class with virtual table. It has a
pointer to a table contains all virtual functions address. And this table
is shared by all instances. So we only need change the function address in
the table. And this interface will look like:

struct _IVsHelpSystemVtbl{
    HRESULT (STDMETHODCALLTYPE *QueryInterface)(IUnknown * This,
      REFIID riid, void **ppvObject);
    ULONG (STDMETHODCALLTYPE *AddRef)(IUnknown * This);
    ULONG (STDMETHODCALLTYPE *Release)(IUnknown * This);
    HRESULT (STDMETHODCALLTYPE *KeywordSearch)(IUnknown * This,
      LPWSTR pszKeyword, long dwFlags, long dwReserved);
};

struct _IVsHelpSystem
{
    struct _IVsHelpSystemVtbl *lpVtbl;
};

What we need to do now is create an instance of this COM. And we will get
the address of the table. Now we need to know how to bring up the help of
latest MSDN. It seems it's not documented. It's also a COM.

Add the following line to your .cpp file. You will get the COM definition.
#import "C:/Program Files/Common Files/Microsoft Shared/MSEnv/vshelp.tlb"
In "vshelp.tlh", you can find function:

HRESULT DisplayTopicFromF1Keyword ( _bstr_t pszKeyword );

Obviously, this is what we need. So in the function KeywordSearch, call
DisplayTopicFromF1Keyword will launch the latest MSDN.

Here is the code:

HRESULT hr = theHelp.CreateInstance(__uuidof(VsHelp::DExploreAppObj));
if (SUCCEEDED(hr))
{
    HRESULT hr = vc6Help.CreateInstance(
      __uuidof(VsHelpServices::VsHelpServices));
    if (SUCCEEDED(hr))
    {
        iHelp = (_IVsHelpSystem *)vc6Help.GetInterfacePtr();

        TRACE1("iHelp = %x/n", iHelp);
        TRACE1("lpVtbl = %x/n", iHelp->lpVtbl);
        TRACE1("KeywordSearch = %x/n", iHelp->lpVtbl->KeywordSearch);

        OldKeywordSearch = iHelp->lpVtbl->KeywordSearch;

        DWORD dwOldProtect;
        if (VirtualProtect(iHelp->lpVtbl, sizeof(
          _IVsHelpSystemVtbl), PAGE_READWRITE, &dwOldProtect))
            iHelp->lpVtbl->KeywordSearch = MyKeywordSearch;
    }
}

Easy, right? There are two things you must keep in mind. First we must
declare the vc6Help in global space and release it when program quit.
This is because the vshelp.dll will be freed if there is no more instance.
If so, then what we modified will be gone with it. The second, we must call
VirtualProtect to make the virtual table become writable, otherwise you
cannot modify the virtual table because it's read only.

How to use it?

Click VC6's menu "Tools"->"Customize"->"Add-ins and Macro Files"->"Browse".
Then choose "VSNetHelp.dll", click "Close".

Move the caret to a keyword, press F1. You got it!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
关于 VC 帮助 简介 当我提供了MSDN精简版的下载后,有人就说精简版的VC不支持搜索。的确,这是由于微软的这些相关文件制作问题造成的。我觉得这不算是什么大的问题,但最近在想:我大学的时候不也一直很迷茫吗?不懂的时候,到处碰壁。许多 时间浪费在寻找正确的道理。所以今天我花了很长的时间重新dump微软的chm文件制作了这个版本。也希望大家能够不断的提建议,不断的完善它。目的是希望我们80后一代,不仅是网络游戏的一代,还是编程高手的一代。 使用这个帮助的用户,估计多半都在使用Visual C++。没办法,VC实在是太好用了。开发工具这东西,大家萝卜白菜各有所爱,作为ed的编写者,大家可以尝试的用一用:ed - 支持60种编程语言的编辑器。 特别是支持的语言种类比较多,比如写汇编文件,ed就是非常不错的编辑器。 文件 vc.chm 主帮助文件 help1.chm Microsoft Macro Assembler Reference help2.chm Visual C++ Programmer's Guide help3.chm Languages and Libraries for Visual C++ help4.chm Microsoft Foundation Classes and Templates 适合用户 学习MASM、C或C++、MFC的用户。(注意:不包含Windows SDK) 感谢 Suofanker - 江湖人称“送饭的”,精通seo、服务器加固、自称是中国第八代黑客。 NE.Tiger: 为ed和MSDN精简版提供了更新建议,MSDN 1.2.2就是我按照他的详细回信制作的。 吴霖: 提供的高速网络硬盘,非常感谢,上传速度特别快。 artcpp: 为ed提出了这么多出色的更新建议。 于涵: 促使了MSDN 精简版的诞生 :) 。 祖春山: 非常感谢在本站还有建立起来的时候提供的宝贵的建议,以及后来的许多更新意见和无偿的测试 :) -------------------------------------------------------------------------------- 徐艺波 2007-07-19 北京 绿盟科技

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值