DeskBand实现之——四个函数

    对于一个DeskBand来说,它应该是一个DLL,也是一个COM对象,它是由explorer来调用的。对于DLL来说,它有几个函数,相当重要,本文对这几个函数作一个简单说明。

    1,DllMain

    2,DllGetClassObject

    3,DllCanUnloadNow

    4,DllRegisterServer

    5,DllUnregisterServer

    其中函数2—5是需要导出的,作为该DLL与客户端通信的接口。

    下面对这5个函数作个说明。

 

    1,DllMain

    这是一个DLL的入口点函数。系统在不同的时间调用这个进入点函数,这些调用可以用来提供一些信息(如保存DLL的Instance),通常用于代DLL进行每个进程或线程的初始化和清除操作。如果你的DLL不需要这些通知信息,就不必在DLL源代码中实现这个函数,例如,如果你创建一个只包含资源的DLL,就不必实现该函数。注意,这个函数通常中做进程或线程的初始化和清除操作,当你的DllMain函数执行时,同一个地址空间中的其他DLL可能尚未执行它们的DllMain函数,这意味着它们尚未初始,因此你应该避免调用从其他DLL中输出的函数。此外,你应该避免从DllMain内部调用LoadLibrary和FreeLibrary函数,因为这些函数会形成一个依赖性循环。

 

    2,DllGetClassObject

    这个函数相当重要,它必须是一个输出函数。它用于创建类工厂,在类工厂里面创建自定义的COM对象。不要直接调用这个函数。请看它的实现:

STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
{
    // CLSID_SdkDeskBand这个就是自定义COM的CLSID
    HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
    if ( TRUE == IsEqualCLSID(rclsid, CLSID_SdkDeskBand) )
    {
        hr = E_OUTOFMEMORY;
        // 这就是我们自己实现类工厂,它可创建出我们自大定义的COM对象
        SdkClassFactory *pClassFactory = new SdkClassFactory();
        if ( NULL != pClassFactory )
        {
            hr = pClassFactory->QueryInterface(riid, ppv);
        }
        SAFE_RELEASE(pClassFactory);
    }
    return hr;
}


    3,DllCanUnloadNow

    这个函数告诉OS是否可以卸载该DLL,它一般实现比较简单,也可以作一些清除操作,如果关闭一些全局句柄,写一个LOG等。

STDAPI DllCanUnloadNow()
{
    // g_lDllRefCount是当前DLL的引用计数,
    // 如果这个变量值为0的话,说明可以卸载该DLL,否则不可以。
    return (g_lDllRefCount > 0) ? S_FALSE : S_OK;
}

    4,DllRegisterServer

    当该DLL注册时,就会调用这个函数,典型的就是用regsvr32命令注册DLL时,它就会调用该函数,一般在这个函数里央就可以来注册了,比如写一些注册表,注册当前DLL的类型等。

 

    5,DllUnregisterServer

    当用regsvr32 /u来卸载该DLL时会调用这个方法,在这个方法里面,要做的就是在注册表中删除写入的值。当这个函数调用后,一般DLL还不能立马被删除,OS会有一个轮循机制,大概要等一段时间,这个DLL就可以删除掉了。为了能够马上删除它,可以在这个函数里加入如下代码:

    // Find handle to the task bar.
    // hTaskbarWnd是Desk Band对象的容器
    HWND hTaskbarWnd = FindWindow(L"Shell_TrayWnd", NULL);
    // If task bar receives this message, it will call CoFreeUnusedLibraries function
    // immediately to free unused libraries.
    PostMessage(hTaskbarWnd, WM_TIMER, 24, 0);



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1,ATLAux.zipA set of VC++ helpers and patterns to help automate some routine coding tasks.(35KB)2,CltnWizard.zipATL object wizard that creates a collection of other COM objects(37KB)3,gridctrlatl.zipA grid control for displaying tabular data, based on Chris Maunder's grid control(101KB)4,TempMonitor.zipA step by step tutorial on using ATL controls in MFC(47KB)5,SAWzip.zipAn ATL based control for reading and writing zip files(187KB)6,Property12.zipDescribes an ActiveX Control to use OLE Automation to set an object's properties.(222KB)7,AlxGrd.zipDescribes an ActiveX Control to use OLE Automation to set an object's properties.(215KB)8,ATLLog_demo.zipA simple logging utility to help debug your ATL applications(48KB)9,ATL_pp_wizard.zipA wizard that allows you to create an ATL Object Wizard Property Page(74KB)10,AtlSplitter.zipATL Splitter ActiveX control(94KB)11,Com_Atl.zipBeginner's Tutorial: COM/ATL Simple Project(19KB)12,ienum.zipA simplified method to enumerate a collection of objects.(137KB)13,ConExe_demo.zipAn article on ATL COM event connection point threading issues(72KB)14,RBDeskBand.zipAn ATL Object Wizard that creates an DeskBand COM Object implementation(149KB)15,instmsi.zipThis is an ATL Object Wizard that eases window development using CWindowImpl. It removes the redundant copy-n-paste of code between class implementations(1437KB)16,DrawingD.zipDrawing complex ATL/ActiveX controls at designtime(38KB)17,ATLDateLib.zipNon-MFC Date Routines in an ATL Component.(10KB)18,shellext.zipA wizard that allows you to create an ATL Property Page or Context Menu extensions(77KB)19,StructStg.zipA wrapper class for most common IStorage methods and API calls.(20KB)20,PropBrowser.zipAllows you to easily create property pages for ActiveX controls(59KB)21,Redirect.zipAn ATL-control for redirecting stdout/stdin(55KB)22,kPad.zipAn example of using the WTL library and RichEdit control(131KB)23,rsPrevFontcmb.zipA font combo box that previews the fonts in the dropdown view(30KB)24,ButtonMenu.zipUse WTL to create simple button that implements drop-down menu(19KB)25,DocViewWTL.zipA library that provides the easiest way to get loosely coupled components.(163KB)26,update_wtl.zipNotes on updating your WTL installation(2KB)27,sidebarmenu.zipAn article about changing the look of WTL icon menu(85KB)28,customdraw.zipHow to use WTL to create custom controls(20KB)29,WTLDocs1.zipBeginning Documentation on WTL(71KB)30,Toolbar.zipAn article on extending the tool bar control using the Window Template Library(64KB)31,propsheetddx.zipDemonstrates how to use DDX/DDV and tabbed property sheets with WTL(35KB)32,donut_demo.zipMDI and Tab WebBrowser(168KB)33,JCB.zipA Java Class Browser written in C++ using WTL(139KB)34,MenuBtn.zipUse of a Push button with a drop down menu(21KB)35,AutoATL.zipUsing ATL to Automate a MFC Application Or, Creating Hybrid MFC ATL COM Objects(41KB)36,atlcontain.zipUsing Containment In ATL - A Complete Application(202KB)37,atnt_src.zipSplitter window control(454KB)38,msform.exeActiveX script hosting - 2(123KB)39,axhost.exeActiveX script hosting(109KB)40,ATL_Script.zipImplementing Active Script Site with ATL(52KB)41,actvdbg.zipAdding Debug facilities to an Active Scripting Host(86KB)42,Gif89a.zipA Control for Displaying Animated GIF Images(221KB)43,proppagec.zipActiveX Control Property Page Container(40KB)44,qlistctrl.zipQListCtrl - a popup list box like that in Visual C++ 6.0(36KB)45,ncombo.zipAn Enhanced Combo Box Control.(194KB)46,XFloorWnd.zipFloor Window Control(341KB)47,propgrid.zipProperties Grid Control(239KB)48,dscdao.zipData Source ActiveX control for DAO(201KB)49,rnso.zipRNSO - A Remote Notifiers,Subjects and Observers Server over DCOM(197KB)50,multiarray.zipUsing a Multidimensional SAFEARRAY to pass data across from COM objects (50KB)51,safearray.zipPassing DYNAMIC Data QUICKLY using SafeArrays - 2(71KB)52,comcollec.zipCOM Collection Template Class(30KB)53,AXDocc.zipProgramming Active Document Containers(114KB)54,MBV_Demo.zipMBV Wizard and the COM Container Library(105KB55,WaveEdAt.zipA COM-based Automation Wave File Editor(124KB)56,bankaccount1.zipHandling Interdependent Objects in Automation An Example of a Bank Server Object(53KB)57,aspfile.zipAn ASP Component to Send Arbitary Large File from Server to Client(62KB)58,tlbrowser.zipWriting a simple Typelibrary browser(45KB)59,tiatut.zipBuilding a World Class Application with MFC and COM Automation(197KB)60,asyncpp.zipAsynchronous Pluggable Protocol(11KB)61,comarray.zipPassing arrays of structures in COM.(24KB)62,olefile.zipCOleFileManager - encapsulates the ugly details of implementing compound file support(4KB)63,VBCollecs.zipSimple STL Collections in ATL(14KB)64,hyperlinks.zipActiveX hyper linking(389KB)65,activex.zipActiveX Control Tutorial(89KB)66,atlexamp.zipLeveraging C++ Applications Using COM An Example Using ATL COM(52KB)67,docviewcom.zipLeveraging C++ Applications Using COM An Extension of the Document View Architecture(86KB)68,atlclienttut.zipATL Client Application Tutorial(51KB)69,wordauto.zipAutomation And Eventing With Microsoft Word(32KB)

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值