Create a shortcut with masm32-use a com demo

Source: Internet
Author: User
Document directory
  • Makelink. ASM, a demonstration of COM
  • A demo of makelink. ASM and COM
  • Bibliography:
  • Bibliography:
  • Code

Http://www.chinaitpower.com/A/2001-12-10/7354.html

A demo of makelink. ASM, a demonstration of COM makelink. ASM, com

This program does very little, as a good tutorial program shocould. when run, it creates a shortcut cut 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.

ThisProgramNothing is done, just like in a good tutorialProgramIt should be done. After running, it creates a shortcut pointing to itself in the same directory. InFileIt may be interesting to run and observe the creation of shortcuts in the Manager. Then you can try the shortcut and see that its creation time has changed.

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 "cannot cut to shelllink. lnk "these strings are passed to the shell Link interface, and it is saved (or persisted in com-speak ).

The sample code of the shortcut is located in.../COM/examples/shortcut cut. It consists of someFileOfFileStart with "hack code" in the complete path of the name, and createCharacterString. It setsFileChanged to "export cut to shelllink. lnk ". TheseCharacterThe string is passed to the shell Link Interface and saved (in the com language, it is persistent ).

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.

Cocreatelink functions used to actually execute COM functions and implement shortcuts are designed to be as common as possible. ThereforeProgramThere is a possibility of reuse.

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... /COM/bin/blddll. BAT file supplied.

ThisProgramIt is very similar to the previous tutorials, but it was edited again to make it clearer. To avoid confusionFile. It can use the provided ../COM/bin/bldll. batFile.

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.

Additional note: iczelion has a very useful resource. h In its tutorial.File. Use rc.exe to compile ResourcesFileThis is quite useful. I used it so frequently that I moved it to my/masm32/includeFileFolder. You need to either copy your copy or change rsrc. RCFileTo create a path.

Bibliography:

"Inside COM, Microsoft's Component Object Model" Dell 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 compile strate 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 economy mopoulos

Copyright limit l 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 author er. "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 Taylor

Http://thunder.prohosting.com /~ ASM1/

Assembly Language Journal, APR-June 99

Code

* Purpleendurer note:

To make the connection successful

Includelib shell32.lib

Changed:

Includelib/masm32/lib/shell32.lib

Makelink. ASM


;---------------------------------------------------------------------; MakeLink.asm ActiveX simple client to demonstrate basic concepts;               written & (c) copyright April 5, 2000 by Ernest Murphy;;               contact the author at ernie@surfree.com;;               may be reused for any educational or;               non-commercial application without further license;---------------------------------------------------------------------.386.model flat, stdcalloption casemap:noneinclude /masm32/include/windows.incinclude /masm32/include/user32.incinclude /masm32/include/kernel32.incinclude /masm32/include/ole32.incinclude /masm32/com/include/oaidl.incinclude /masm32/com/include/shlobj.incincludelib /masm32/lib/user32.libincludelib /masm32/lib/kernel32.libincludelib /masm32/lib/ole32.lib;---------------------------------------------------------------------CoCreateLink      PROTO :DWORD, :DWORDMakeMessage MACRO Text:REQ    ; macro to display a message box    ; the text to display is kept local to    ; this routine for ease of use    LOCAL lbl    LOCAL sztext    jmp lblsztext:      db Text,0lbl:    invoke MessageBox,NULL,sztext,ADDR szAppName,MB_OK    ENDM  ; IPersistFile Interface   IPersistFile            STRUCT DWORD       IPersistFile_QueryInterface       comethod3       ?       IPersistFile_AddRef               comethod1       ?       IPersistFile_Release              comethod1       ?       IPersistFile_GetClassID           comethod2       ?       IPersistFile_IsDirty              comethod1       ?       IPersistFile_Load                 comethod3       ?       IPersistFile_Save                 comethod3       ?       IPersistFile_SaveCompleted        comethod2       ?       IPersistFile_GetCurFile           comethod2       ? IPersistFile            ENDS;---------------------------------------------------------------------.dataszAppName         BYTE     "Shell Link Maker", 0szLinkName        BYTE     "Shortcut to MakeLink.lnk", 0szBKSlash   BYTE   "/", 0hInstance         HINSTANCE   ?Pos               DWORD       ?szBuffer1   BYTE   MAX_PATH DUP(?)szBuffer2   BYTE   MAX_PATH DUP(?);---------------------------------------------------------------------.codestart:;---------------------------------------------------------------------;  this bracketed code is just a 'quick hack';  to replace the filename from the filepathname;  with the 'Shortcut to' title;    invoke GetModuleHandle, NULL    mov hInstance, eax    invoke GetModuleFileName, NULL, ADDR szBuffer1, MAX_PATH    invoke lstrcpy, ADDR szBuffer2, ADDR szBuffer1    ; Find the last backslash '/' and change it to zero    mov edx, OFFSET szBuffer2    mov ecx, edx    .REPEAT        mov al, BYTE PTR [edx]        .IF al == 92 ; "/"            mov ecx, edx        .ENDIF        inc edx    .UNTIL  al == 0    mov BYTE PTR [ecx+1], 0       invoke lstrcpy, ADDR szBuffer2, ADDR szLinkName;---------------------------------------------------------------------; here is where we call the proc with the COM methods    invoke CoInitialize, NULL    MakeMessage "Let's try our Createlink."    invoke CoCreateLink, ADDR szBuffer1, ADDR szBuffer2    MakeMessage "That's all folks !!!"    invoke CoUninitializeinvoke ExitProcess, NULL;---------------------------------------------------------------------CoCreateLink PROC pszPathObj:DWORD, pszPathLink:DWORD ; CreateLink - uses the shell's IShellLink and IPersistFile interfaces  ;   to create and store a shortcut to the specified object.  ; Returns the hresult of calling the member functions of the interfaces.  ; pszPathObj - address of a buffer containing the path of the object.  ; pszPathLink - address of a buffer containing the path where the  ;   shell link is to be stored.  ; addapted from MSDN article "Shell Links" ;  deleted useless "description" method ;  added set icon location method    LOCAL   pwsz    :DWORD             LOCAL   psl     :DWORD             LOCAL   ppf     :DWORD           LOCAL   hResult :DWORD           LOCAL   hHeap   :DWORD       .dataCLSID_ShellLink     GUID       sCLSID_ShellLinkIID_IShellLink      GUID       sIID_IShellLinkIID_IPersistFile    GUID       {00000010bH, 00000H, 00000H, /                                {0C0H, 000H, 000H, 000H, 000H, 000H, 000H, 046H}}.code    ; first, get some heap for a wide buffer    invoke GetProcessHeap    mov hHeap, eax    invoke HeapAlloc, hHeap, NULL, MAX_PATH * 2    mov pwsz, eax    ; Get a pointer to the IShellLink interface.     invoke CoCreateInstance, ADDR CLSID_ShellLink, NULL,                              CLSCTX_INPROC_SERVER,                              ADDR IID_IShellLink, ADDR psl    mov hResult, eax    test eax, eax    .IF SUCCEEDED         ; Query IShellLink for the IPersistFile         ; interface for saving the shortcut        coinvoke psl, IShellLink, QueryInterface, ADDR IID_IPersistFile, ADDR ppf        mov hResult, eax        test eax, eax        .IF SUCCEEDED             ; Set the path to the shortcut target             coinvoke psl, IShellLink, SetPath, pszPathObj            mov hResult, eax            ; add the  description, use first icon found            coinvoke psl, IShellLink, SetIconLocation, pszPathObj, 0             mov hResult, eax            ; change string to Unicode.             ; (COM typically expects Unicode strings)            invoke MultiByteToWideChar, CP_ACP, 0, pszPathLink,                                         -1, pwsz, MAX_PATH            ; Save the link by calling IPersistFile::Save  coinvoke ppf, IPersistFile, Save, pwsz, TRUE            mov eax, hResult            ; release the IPersistFile ppf pointer            coinvoke ppf, IPersistFile, Release            mov hResult, eax        .ENDIF        ; release the IShellLink psl pointer        coinvoke psl, IShellLink, Release        mov hResult, eax    .ENDIF    ; free our heap space    invoke HeapFree, hHeap, NULL, pwsz    mov eax, hResult    ; since we reuse this variable over and over,                        ;  it contains the last operations result    retCoCreateLink ENDP;---------------------------------------------------------------------end start 

Rsrc. RC

// resource.h may be found in Iczelion's tut #10-1// it is well worth moving to your /masm32/include/ folder#include "/masm32/include/resource.h"#define IDC_ICON1              1001#define IDC_ICON2              1002IDI_ICON1     ICON   MOVEABLE PURE LOADONCALL DISCARDABLE "PLANE.ICO"IDI_ICON2     ICON   MOVEABLE PURE LOADONCALL DISCARDABLE "TRFFC14.ICO"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.