refactored logging for synwinxt, and added version number.

This commit is contained in:
Nick Bolton 2014-03-07 19:37:52 +00:00
parent b3a28139ad
commit 64248beb4e
3 changed files with 81 additions and 68 deletions

View File

@ -21,27 +21,27 @@
#include <Shlwapi.h>
extern LONG g_refCount;
extern void outputDebugStringF(const char *str, ...);
extern void log(const char *str, ...);
CClassFactory::CClassFactory() :
m_refCount(1)
{
outputDebugStringF("synwinxt: > CClassFactory::ctor, g_refCount=%d\n", g_refCount);
log("> CClassFactory::ctor, g_refCount=%d", g_refCount);
InterlockedIncrement(&g_refCount);
outputDebugStringF("synwinxt: < CClassFactory::ctor, g_refCount=%d\n", g_refCount);
log("< CClassFactory::ctor, g_refCount=%d", g_refCount);
}
CClassFactory::~CClassFactory()
{
outputDebugStringF("synwinxt: > CClassFactory::dtor, g_refCount=%d\n", g_refCount);
log("> CClassFactory::dtor, g_refCount=%d", g_refCount);
InterlockedDecrement(&g_refCount);
outputDebugStringF("synwinxt: < CClassFactory::dtor, g_refCount=%d\n", g_refCount);
log("< CClassFactory::dtor, g_refCount=%d", g_refCount);
}
HRESULT STDMETHODCALLTYPE
CClassFactory::QueryInterface(REFIID riid, void **ppvObject)
{
outputDebugStringF("synwinxt: > CClassFactory::QueryInterface\n");
log("> CClassFactory::QueryInterface");
static const QITAB qit[] =
{
QITABENT(CClassFactory, IClassFactory),
@ -49,36 +49,36 @@ CClassFactory::QueryInterface(REFIID riid, void **ppvObject)
};
HRESULT hr = QISearch(this, qit, riid, ppvObject);
outputDebugStringF("synwinxt: < CClassFactory::QueryInterface, hr=%d\n", hr);
log("< CClassFactory::QueryInterface, hr=%d", hr);
return hr;
}
ULONG STDMETHODCALLTYPE
CClassFactory::AddRef()
{
outputDebugStringF("synwinxt: > CClassFactory::AddRef, m_refCount=%d\n", m_refCount);
log("> CClassFactory::AddRef, m_refCount=%d", m_refCount);
LONG r = InterlockedIncrement(&m_refCount);
outputDebugStringF("synwinxt: < CClassFactory::AddRef, r=%d, m_refCount=%d\n", r, m_refCount);
log("< CClassFactory::AddRef, r=%d, m_refCount=%d", r, m_refCount);
return r;
}
ULONG STDMETHODCALLTYPE
CClassFactory::Release()
{
outputDebugStringF("synwinxt: > CClassFactory::Release, m_refCount=%d\n", m_refCount);
log("> CClassFactory::Release, m_refCount=%d", m_refCount);
LONG r = InterlockedDecrement(&m_refCount);
if (r == 0) {
delete this;
}
outputDebugStringF("synwinxt: < CClassFactory::Release, r=%d\n", r);
log("< CClassFactory::Release, r=%d", r);
return r;
}
HRESULT STDMETHODCALLTYPE
CClassFactory::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObject)
{
outputDebugStringF("synwinxt: > CClassFactory::CreateInstance\n");
log("> CClassFactory::CreateInstance");
if (pUnkOuter != NULL) {
return CLASS_E_NOAGGREGATION;
}
@ -89,20 +89,20 @@ CClassFactory::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObject
delete pExtension;
}
outputDebugStringF("synwinxt: < CClassFactory::CreateInstance, hr=%d\n", hr);
log("< CClassFactory::CreateInstance, hr=%d", hr);
return hr;
}
HRESULT STDMETHODCALLTYPE
CClassFactory::LockServer(BOOL fLock)
{
outputDebugStringF("synwinxt: > CClassFactory::LockServer, g_refCount=%d\n", g_refCount);
log("> CClassFactory::LockServer, g_refCount=%d", g_refCount);
if (fLock) {
InterlockedIncrement(&g_refCount);
}
else {
InterlockedDecrement(&g_refCount);
}
outputDebugStringF("synwinxt: < CClassFactory::LockServer, g_refCount=%d\n", g_refCount);
log("< CClassFactory::LockServer, g_refCount=%d", g_refCount);
return S_OK;
}

View File

@ -24,27 +24,27 @@
extern LONG g_refCount;
extern GUID g_CLSID;
extern void setDraggingFilename(const char* str);
extern void outputDebugStringF(const char* str, ...);
extern void log(const char* str, ...);
CDataHandlerExtension::CDataHandlerExtension() :
m_refCount(1)
{
outputDebugStringF("synwinxt: > CDataHandlerExtension::ctor, g_refCount=%d\n", g_refCount);
log("> CDataHandlerExtension::ctor, g_refCount=%d", g_refCount);
InterlockedIncrement(&g_refCount);
outputDebugStringF("synwinxt: < CDataHandlerExtension::ctor, g_refCount=%d\n", g_refCount);
log("< CDataHandlerExtension::ctor, g_refCount=%d", g_refCount);
}
CDataHandlerExtension::~CDataHandlerExtension()
{
outputDebugStringF("synwinxt: > CDataHandlerExtension::dtor, g_refCount=%d\n", g_refCount);
log("> CDataHandlerExtension::dtor, g_refCount=%d", g_refCount);
InterlockedDecrement(&g_refCount);
outputDebugStringF("synwinxt: < CDataHandlerExtension::dtor, g_refCount=%d\n", g_refCount);
log("< CDataHandlerExtension::dtor, g_refCount=%d", g_refCount);
}
HRESULT STDMETHODCALLTYPE
CDataHandlerExtension::QueryInterface(REFIID riid, void **ppvObject)
{
outputDebugStringF("synwinxt: > CDataHandlerExtension::QueryInterface\n");
log("> CDataHandlerExtension::QueryInterface");
static const QITAB qit[] =
{
QITABENT(CDataHandlerExtension, IPersistFile),
@ -54,10 +54,10 @@ CDataHandlerExtension::QueryInterface(REFIID riid, void **ppvObject)
HRESULT hr = QISearch(this, qit, riid, ppvObject);
if (FAILED(hr)) {
outputDebugStringF("synwinxt: < CDataHandlerExtension::QueryInterface, hr=FAILED\n");
log("< CDataHandlerExtension::QueryInterface, hr=FAILED");
}
else {
outputDebugStringF("synwinxt: < CDataHandlerExtension::QueryInterface, hr=%d\n", hr);
log("< CDataHandlerExtension::QueryInterface, hr=%d", hr);
}
return hr;
}
@ -65,39 +65,39 @@ CDataHandlerExtension::QueryInterface(REFIID riid, void **ppvObject)
ULONG STDMETHODCALLTYPE
CDataHandlerExtension::AddRef()
{
outputDebugStringF("synwinxt: > CDataHandlerExtension::AddRef, m_refCount=%d\n", m_refCount);
log("> CDataHandlerExtension::AddRef, m_refCount=%d", m_refCount);
LONG r = InterlockedIncrement(&m_refCount);
outputDebugStringF("synwinxt: < CDataHandlerExtension::AddRef, r=%d, m_refCount=%d\n", r, m_refCount);
log("< CDataHandlerExtension::AddRef, r=%d, m_refCount=%d", r, m_refCount);
return r;
}
ULONG STDMETHODCALLTYPE
CDataHandlerExtension::Release()
{
outputDebugStringF("synwinxt: > CDataHandlerExtension::Release, m_refCount=%d\n", m_refCount);
log("> CDataHandlerExtension::Release, m_refCount=%d", m_refCount);
LONG r = InterlockedDecrement(&m_refCount);
if (r == 0) {
delete this;
}
outputDebugStringF("synwinxt: < CDataHandlerExtension::Release, r=%d\n", r);
log("< CDataHandlerExtension::Release, r=%d", r);
return r;
}
HRESULT STDMETHODCALLTYPE
CDataHandlerExtension::Load(__RPC__in LPCOLESTR pszFileName, DWORD dwMode)
{
outputDebugStringF("synwinxt: > CDataHandlerExtension::Load\n");
log("> CDataHandlerExtension::Load");
std::string fileName = _bstr_t(pszFileName);
setDraggingFilename(fileName.c_str());
outputDebugStringF("synwinxt: < CDataHandlerExtension::Load\n");
log("< CDataHandlerExtension::Load");
return S_OK;
}
HRESULT STDMETHODCALLTYPE
CDataHandlerExtension::GetClassID(__RPC__out CLSID *pClassID)
{
outputDebugStringF("synwinxt: > CDataHandlerExtension::GetClassID\n");
log("> CDataHandlerExtension::GetClassID");
*pClassID = g_CLSID;
outputDebugStringF("synwinxt: < CDataHandlerExtension::GetClassID\n");
log("< CDataHandlerExtension::GetClassID");
return S_OK;
}

View File

@ -21,6 +21,7 @@
#include <Windows.h>
#include <strsafe.h>
#include <sstream>
#pragma comment(lib, "Shlwapi.lib")
@ -46,7 +47,7 @@ HRESULT unregisterShellExtDataHandler(CHAR* fileType, const CLSID& clsid);
HRESULT unregisterInprocServer(const CLSID& clsid);
void
outputDebugStringF(const char* str, ...)
log(const char* str, ...)
{
char buf[2048];
@ -54,13 +55,15 @@ outputDebugStringF(const char* str, ...)
va_start(ptr, str);
vsprintf_s(buf, str, ptr);
OutputDebugStringA(buf);
std::stringstream ss;
ss << "synwinxt-" << VERSION << ": " << buf << std::endl;
OutputDebugStringA(ss.str().c_str());
}
BOOL APIENTRY
DllMain(HMODULE module, DWORD reason, LPVOID reserved)
{
outputDebugStringF("synwinxt: > DllMain, reason=%d\n", reason);
log("> DllMain, reason=%d", reason);
switch (reason) {
case DLL_PROCESS_ATTACH:
@ -76,14 +79,15 @@ DllMain(HMODULE module, DWORD reason, LPVOID reserved)
break;
}
outputDebugStringF("synwinxt: < DllMain\n");
log("< DllMain");
return TRUE;
}
//#pragma comment(linker, "/export:DllGetClassObject,PRIVATE")
STDAPI
DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppvObj)
{
outputDebugStringF("synwinxt: > DllGetClassObject\n");
log("> DllGetClassObject");
HRESULT hr = E_OUTOFMEMORY;
*ppvObj = NULL;
@ -94,29 +98,32 @@ DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppvObj)
classFactory->Release();
}
outputDebugStringF("synwinxt: < DllGetClassObject, hr=%d\n", hr);
log("< DllGetClassObject, hr=%d", hr);
return hr;
}
//#pragma comment(linker, "/export:DllCanUnloadNow,PRIVATE")
STDAPI
DllCanUnloadNow()
{
outputDebugStringF("synwinxt: > DllCanUnloadNow, g_refCount=%d\n", g_refCount);
log("> DllCanUnloadNow, g_refCount=%d", g_refCount);
int r = g_refCount > 0 ? S_FALSE : S_OK;
outputDebugStringF("synwinxt: < DllCanUnloadNow, g_refCount=%d, r=%d\n", g_refCount, r);
log("< DllCanUnloadNow, g_refCount=%d, r=%d", g_refCount, r);
return r;
}
//#pragma comment(linker, "/export:DllRegisterServer,PRIVATE")
STDAPI
DllRegisterServer()
{
outputDebugStringF("synwinxt: > DllRegisterServer\n");
log("> DllRegisterServer");
HRESULT hr;
/*HRESULT hr;
CHAR module[MAX_PATH];
if (GetModuleFileName(g_instance, module, ARRAYSIZE(module)) == 0) {
hr = HRESULT_FROM_WIN32(GetLastError());
outputDebugStringF("synwinxt: < DllRegisterServer, hr=%d\n", hr);
log("< DllRegisterServer, hr=%d", hr);
return hr;
}
@ -131,21 +138,25 @@ DllRegisterServer()
g_CLSID);
}
outputDebugStringF("synwinxt: < DllRegisterServer, hr=%d\n", hr);
return hr;
log("< DllRegisterServer, hr=%d", hr);
*/
log("< DllRegisterServer");
return S_OK;
}
//#pragma comment(linker, "/export:DllUnregisterServer,PRIVATE")
STDAPI
DllUnregisterServer()
{
outputDebugStringF("synwinxt: > DllUnregisterServer\n");
log("> DllUnregisterServer");
/*
HRESULT hr = S_OK;
CHAR module[MAX_PATH];
if (GetModuleFileName(g_instance, module, ARRAYSIZE(module)) == 0) {
hr = HRESULT_FROM_WIN32(GetLastError());
outputDebugStringF("synwinxt: < DllRegisterServer, hr=%d\n", hr);
log("< DllRegisterServer, hr=%d", hr);
return hr;
}
@ -154,14 +165,16 @@ DllUnregisterServer()
hr = unregisterShellExtDataHandler("*", g_CLSID);
}
outputDebugStringF("synwinxt: < DllUnregisterServer, hr=%d\n", hr);
return hr;
}
log("< DllUnregisterServer, hr=%d", hr);*/
log("< DllUnregisterServer");
return S_OK;
}
/*
HRESULT
registerInprocServer(CHAR* module, const CLSID& clsid, CHAR* threadModel)
{
outputDebugStringF("synwinxt: > registerInprocServer\n");
log("> registerInprocServer");
if (module == NULL || threadModel == NULL) {
return E_INVALIDARG;
@ -191,14 +204,14 @@ registerInprocServer(CHAR* module, const CLSID& clsid, CHAR* threadModel)
}
}
outputDebugStringF("synwinxt: < registerInprocServer, hr=%d\n", hr);
log("< registerInprocServer, hr=%d", hr);
return hr;
}
HRESULT
unregisterInprocServer(const CLSID& clsid)
{
outputDebugStringF("synwinxt: > unregisterInprocServer\n");
log("> unregisterInprocServer");
HRESULT hr = S_OK;
@ -216,10 +229,10 @@ unregisterInprocServer(const CLSID& clsid)
}
if (FAILED(hr)) {
outputDebugStringF("synwinxt: < unregisterInprocServer, hr=FAILED\n");
log("< unregisterInprocServer, hr=FAILED");
}
else {
outputDebugStringF("synwinxt: < unregisterInprocServer, hr=%d\n", hr);
log("< unregisterInprocServer, hr=%d", hr);
}
return hr;
}
@ -227,7 +240,7 @@ unregisterInprocServer(const CLSID& clsid)
HRESULT
registerShellExtDataHandler(CHAR* fileType, const CLSID& clsid)
{
outputDebugStringF("synwinxt: > registerShellExtDataHandler\n");
log("> registerShellExtDataHandler");
if (fileType == NULL) {
return E_INVALIDARG;
@ -250,14 +263,14 @@ registerShellExtDataHandler(CHAR* fileType, const CLSID& clsid)
CArchMiscWindows::setValue(key, NULL, CLASSID);
}
outputDebugStringF("synwinxt: < registerShellExtDataHandler, hr=%d\n", hr);
log("< registerShellExtDataHandler, hr=%d", hr);
return hr;
}
HRESULT
unregisterShellExtDataHandler(CHAR* fileType, const CLSID& clsid)
{
outputDebugStringF("synwinxt: > unregisterShellExtDataHandler\n");
log("> unregisterShellExtDataHandler");
if (fileType == NULL) {
return E_INVALIDARG;
@ -278,10 +291,10 @@ unregisterShellExtDataHandler(CHAR* fileType, const CLSID& clsid)
hr = HRESULT_FROM_WIN32(RegDeleteTree(HKEY_CLASSES_ROOT, subkey));
}
outputDebugStringF("synwinxt: < unregisterShellExtDataHandler, hr=%d\n", hr);
log("< unregisterShellExtDataHandler, hr=%d", hr);
return hr;
}
*/
std::string
getFileExt(const char* filenameCStr)
{
@ -296,7 +309,7 @@ getFileExt(const char* filenameCStr)
void
setDraggingFilename(const char* filename)
{
outputDebugStringF("synwinxt: > setDraggingFilename, filename=%s\n", filename);
log("> setDraggingFilename, filename=%s", filename);
// HACK: only handle files that are not .exe or .lnk
// dragging anything, including a selection marquee, from a program
@ -308,23 +321,23 @@ setDraggingFilename(const char* filename)
memcpy(g_draggingFilename, filename, MAX_PATH);
}
else {
outputDebugStringF(
"synwinxt: ignoring filename=%s, ext=%s\n",
log(
"ignoring filename=%s, ext=%s",
filename, ext.c_str());
}
outputDebugStringF("synwinxt: < setDraggingFilename, g_draggingFilename=%s\n", g_draggingFilename);
log("< setDraggingFilename, g_draggingFilename=%s", g_draggingFilename);
}
void
getDraggingFilename(char* filename)
{
outputDebugStringF("synwinxt: > getDraggingFilename\n");
log("> getDraggingFilename");
memcpy(filename, g_draggingFilename, MAX_PATH);
// mark string as empty once used, so we can't accidentally copy
// the same file more than once unless the user does this on purpose.
g_draggingFilename[0] = NULL;
outputDebugStringF("synwinxt: < getDraggingFilename, filename=%s\n", filename);
log("< getDraggingFilename, filename=%s", filename);
}