خرید بک لینک

Vote count: 0

I'm trying to simply display some overlay icons in the Windows Explorer. Since I'm relatively new to programming for Windows (I just have some experience in Mac programming), I used this article to start.

So this is my code:

Icon.h

#pragma once
#include "resource.h"
#include "ExplorerSync_i.h"

using namespace ATL;

class ATL_NO_VTABLE CIcon :
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CIcon, &CLSID_Icon>,
    public IShellIconOverlayIdentifier,
    public IDispatchImpl<IIcon, &IID_IIcon, &LIBID_ExplorerSyncLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
    CIcon();
    STDMETHOD(GetOverlayInfo)(LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD* pdwFlags);
    STDMETHOD(GetPriority)(int* pPriority);
    STDMETHOD(IsMemberOf)(LPCWSTR pwszPath, DWORD dwAttrib);

DECLARE_REGISTRY_RESOURCEID(IDR_ICON)

BEGIN_COM_MAP(CIcon)
    COM_INTERFACE_ENTRY(IIcon)
    COM_INTERFACE_ENTRY(IDispatch)
    COM_INTERFACE_ENTRY(IShellIconOverlayIdentifier)
END_COM_MAP()

    HRESULT FinalConstruct()
    {
        retu S_OK;
    }

    void FinalRelease()
    {
    }

protected:

};

Icon.cpp

#include "stdafx.h"
#include "Icon.h"
#using <system.dll>

using namespace System;
using namespace System::Diagnostics;

STDMETHODIMP CIcon::GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, int * pIndex, DWORD * pdwFlags)
{
    GetModuleFileNameW(_AtlBaseModule.GetModuleInstance(), pwszIconFile, cchMax);
    *pIndex = 0;
    *pdwFlags = ISIOI_ICONFILE | ISIOI_ICONINDEX;
    retu S_OK;
}

STDMETHODIMP CIcon::GetPriority(int * pPriority)
{    
    *pPriority = 0;
    retu S_OK;
}

STDMETHODIMP CIcon::IsMemberOf(LPCWSTR pwszPath, DWORD dwAttrib)
{       
    wchar_t *s = _wcsdup(pwszPath);
    HRESULT r = S_FALSE;
    _wcslwr_s(s, 1);
    r = S_OK;
    free(s);
    retu r;
}

CIcon::CIcon() {
}

ExplorerSync.cpp

#include "stdafx.h"
#include "resource.h"
#include "ExplorerSync_i.h"
#include "dllmain.h"
#include "Icon.h"
#using <system.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace ATL;

STDAPI DllCanUnloadNow(void)
{
            retu _AtlModule.DllCanUnloadNow();
    }

_Check_retu_
STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID* ppv)
{
        retu _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}

STDAPI DllRegisterServer(void)
{   
    HRESULT hr = _AtlModule.DllRegisterServer();

    // not possible to instantiate, because it is abstract according to error message
    //CIcon *cIcon = new (std::nothrow) CIcon();

        retu hr;
}

STDAPI DllUnregisterServer(void)
{
    HRESULT hr = _AtlModule.DllUnregisterServer();
        retu hr;
}

STDAPI DllInstall(BOOL bInstall, _In_opt_  LPCWSTR pszCmdLine)
{   
    HRESULT hr = E_FAIL;
    static const wchar_t szUserSwitch[] = L"user";

    if (pszCmdLine != NULL)
    {
        if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0)
        {
            ATL::AtlSetPerUserRegistration(true);
        }
    }

    if (bInstall)
    {   
        hr = DllRegisterServer();
        if (FAILED(hr))
        {
            DllUnregisterServer();
        }
    }
    else
    {
        hr = DllUnregisterServer();
    }

    retu hr;
}

So I used primarily the code from the example mentioned above and because it did not work, I changed the code a bit according to my thoughts.

The problem is not the compiling. This works and registration via regsvr32 as well without any errors. But with some event log entries I found out, that DllRegisterServer is the only method which is called. All the other functions (especially the interface implementations for the icons) are not called at all. Although it's not done in the example, I tried to instantiate the Icon class in the DllRegisterServer method in the hope it helps, but I caot do that (error message: Icon is abstract and caot be instantiated).

So can anybody tell me, what's going wrong, please? Thank you so much in advance!

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 12 خرداد 1395 ساعت: 5:54

صفحه بندی