Студопедия  
Главная страница | Контакты | Случайная страница

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатика
ИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханика
ОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторика
СоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансы
ХимияЧерчениеЭкологияЭкономикаЭлектроника

Link /DLL /SUBSYSTEM:WINDOWS /DEF:%1.def

 

Note that now the name decoration is done for us by the macro.

 

The only 'gotcha' (well, the most obvious) is that no parameters to a COM call should be passed in edx as this register is used to handle 'this' the object reference. Using edx as a parameter will generate a compile error.

 

 

Using IShellFile and IPersistFile from shell32.dll
--------------------------------------------------------------------------------------------------------------------
The shell32.dll provides a simple. easy way to make shell links (shortcuts). However, it uses a COM interface to provide this service. The sample below is based on the MSDN "Shell Links" section for "Internet Tools and Technologies."


This may be a strange place to find documentation, but there it is.

 

The "Shell Links" article may be found at: http://msdn.microsoft.com/library/psdk/shellcc/shell/Shortcut.htm

 

For this tutorial we will access the following members of the IShellLink and the IPersistFile interfaces. Note every interface includes a "ppi" interface parameter, this is the interface that we calling to (it is the THIS parameter). (The following interface information is a copy of information published by Microsoft)

 

IShellLink::QueryInterface, ppi, ADDR riid, ADDR ppv
* riid: The identifier of the interface requested. To get access to the
* ppv: The pointer to the variable that receives the interface.


Description: Checks if the object also supports the requested interface. If so,
signs the ppv pointer with the interface's pointer.

 

IShellLink::Release, ppi

 

Description: Decrements the reference count on the IShellLink interface.

 

IShellLink:: SetPath, ppi, ADDR szFile
* pszFile: A pointer to a text buffer containing the new path for the shell
link object.

 

Description: Defines where the file the shell link points to.

 

IShellLink::SetIconLocation, ppi, ADDR szIconPath, iIcon
* pszIconPath: A pointer to a text buffer containing the new icon path.
* iIcon: An index to the icon. This index is zero based.


Description: Sets which icon the shelllink will use.

 

IPersistFile::Save, ppi, ADDR szFileName, fRemember
* pszFileName: Points to a zero-terminated string containing the absolute path
of the file to which the object should be saved.
* fRemember: Indicates whether the pszFileName parameter is to be used as the
current working file. If TRUE, pszFileName becomes the current file and the
object should clear its dirty flag after the save. If FALSE, this save
operation is a "Save A Copy As..." operation. In this case, the current file
is unchanged and the object should not clear its dirty flag. If pszFileName is
NULL, the implementation should ignore the fRemember flag.

 

Description: Perform a save operation for the ShellLink object, or saves the shell link are creating.

 

IPersistFile::Release, ppi
Description: Decrements the reference count on the IPersistFile interface.

These interfaces contain many many more methods (see the full interface
definitions in the code below), but we only need concentrate on those we will
actually be using.

 

 

A shell link is the MS-speak name for a shortcut icon. The information contained in a link (.lnk) file is:

1 - The file path and name of the program to shell.

2 - Where to obtain the icon to display for the shortcut (usually from the
executable itself), and which icon in that file to use. We will use
the first icon in the file

3 - A file path and name where the shortcut should be stored.

The use of these interfaces is simple and straightforward. It goes like this:

Call CoCreateInstance CLSID_ShellLink for a IID_IShellLink interface

Queryinterface IShellLink for an IID_IPersistFile interface.

Call IShellLink.SetPath to specify where the shortcut target is

Call IShellLink.SetIconLocation to specify which icon to use

Call IPersistFile.Save to save our new shortcut.lnk file.

finally,

Call IPersistFile.Release

Call IShellLink.Release

This releases our hold on these interfaces, which will automatically lead to the dll that supplied them being unloaded. Again, the hard part in this application was finding documentation. What finally found broke the search open was using Visual Studio "Search in Files" to find "IShellLink" and " IPersistFile" in the /include area of MSVC. This lead me to various.h files, from which I hand translated the interfaces from C
to MASM.

 

Another handy tool I could have used is the command line app "FindGUID.exe," which looks through the registry for a specific interface name or coclass, or will output a list of every class and interface with their associated GUIDs.


Finally, the OLEView.exe application will let you browse the registry type libraries and mine them for information. However, these tools come with MSVC and are proprietary.

 

Take care when defining an interface. Missing vtable methods lead to strange results. Essentially COM calls, on one level, amount to "perform function (number)" calls. Leave a method out of the vtable definition and you call the wrong interface. The original IShellLink interface definition I used from a inc
file I downloaded had a missing function. The calls I made generated a "SUCCEEDED" hResult, but in some cases would not properly clean the stack (since my push count did not match the invoked function's pop count), thus lead to a GPF as I exited a procedure. Keep this in mind if you ever get similar
"weird" results.


MakeLink.asm, a demonstration of COM
--------------------------------------------------------------------------------------------------------------------
This program does very little, as a good tutorial program should. When run, it creates a shortcut to itself, in the same directory. It can be amusing to run from file explorer and watch the shortcut appear. Then you can try the shortcut and watch it's creation time change.

 

The shell link tutorial code is in...\COM\examples\shortcut. It begins with some "hack code" to get the full file name path of the executable, and also makes a string with the same path that changes the file to "Shortcut To ShellLink.lnk" These strings are passed to the shell link interface, and it is saved (or persisted in COM-speak).

 

The CoCreateLink procedure used to actually perform the COM methods and perform this link creation has been kept as general as possible, and may have reuse possibilities in other applications.

 

This program is similar to earlier published tutorial, but has been edited for some additional clarity. The interfaces are defined in a separate include file to reduce clutter. It may be built in MASM32 by using the...\COM\bin\BLDDLL.BAT file supplied.

 

Additional note: Iczelion has quite a useful file in his tutorials named resource.h. It is quite useful when using rc.exe to compile resource files. I use it so much I have moved it to my /masm32/include/ folder. You need to either move your copy there, or change the path in the rsrc.rc file to build it properly.

 

 

Bibliography:
--------------------------------------------------------------------------------------------------------------------
"Inside COM, Microsoft's Component Object Model" Dale Rogerson
Copyright 1997,

Paperback - 376 pages CD-ROM edition
Microsoft Press; ISBN: 1572313498
(THE book for understanding how COM works on a fundamental level.
Uses C++ code to illustrate basic concepts as it builds simple fully
functional COM object)

 

"Automation Programmer's Reference: Using ActiveX Technology to Create
Programmable Applications" (no author listed)
Copyright 1997,

Paperback - 450 pages
Microsoft Press; ISBN: 1572315849
(This book has been available online on MSDN in the past, but it is cheap
enough for those of you who prefer real books you can hold in your hand.
Defines the practical interfaces and functions that the automation libraries
provide you, but is more of a reference book then a "user's guide")

 

Microsoft Developers Network

http://msdn.microsoft.com/

 

"Professional Visual C++ 5 ActiveX/Com Control Programming" Sing Li
and Panos Economopoulos
Copyright April 1997,

Paperback - 500 pages (no CD Rom, files available online)
Wrox Press Inc; ISBN: 1861000375
(Excellent description of activeX control and control site interfaces.
A recent review of this book on Amazon.com stated "These guys are the
type that want to rewrite the world's entire software base in
assembler." Need I say more?)

 

"sean's inconsequential homepage" http://ript.net/~spec/
Various hardcore articles on low-level COM and ATL techniques. Coded in C++

 

"Using COM in Assembly Language" Bill Tyler

http://thunder.prohosting.com/~asm1/
Assembly Language Journal, Apr-June 99

 

Link /DLL /SUBSYSTEM:WINDOWS /DEF:%1.def




Дата добавления: 2014-12-18; просмотров: 55 | Поможем написать вашу работу | Нарушение авторских прав




lektsii.net - Лекции.Нет - 2014-2024 год. (0.011 сек.) Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав