Let VC6 and the latest MSDN integration

xiaoxiao2021-03-06  19

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 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 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 folowing 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 dwnderved;

HRESULT AlinkSearch

LPWSTR PSZALINK,

Long dwflags,

Long dwnderved;

...

The Function KeywordSearch Was Called WHEN You Press F1. SO if We Replace

THIS FUNCTION AND CALL LATEST MSDN's HELP FUNCTION, ITHHOULD 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 TABLE

Is Shared by all all instances. sowe online the function address IN

The table. and this interface will look odick:

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

The address of the table. Now we need to know how to bring up the help of

Latest MSDN. It's it's not docunted. it's also a com.

Add The Following Line to Your .cpp File. You will get the com definition.

#import "c: / program files / compon 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 :: deforeappobj));

En (ac))

{

HRESULT HR = VC6HELP.CREATEINSTANCE

__UUIDOF (vshelpservices :: vshelpservices));

En (ac))

{

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 is aful two things you must keep in mind. Flight. First WE MUST

Declare The VC6HELP in Global Space and release it will.

This is because the vshelp.dll will be freed if there is no more instance.

If SO, THAT 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-insid" -> "browse".

Then Choose "vsnetHelp.dll", Click "Close".

Move The Caret To a Keyword, Press F1. You Got IT!

转载请注明原文地址:https://www.9cbs.com/read-41357.html

New Post(0)