/* Collection of code snippets by Arne Vajhøj */
/* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) */
#ifndef TEST_H
#define TEST_H

#include <windows.h>

// { 2f2d7587-78e8-46ee-ba65-fc7094b37a13 }
DEFINE_GUID(IID_ITest, 0x2f2d7587, 0x78e8, 0x46ee, 0xba, 0x65, 0xfc, 0x70, 0x94, 0xb3, 0x7a, 0x13);

// { 2c7de05d-a083-40d7-b7af-90af8d432489 }
DEFINE_GUID(CLSID_CoTest, 0x2c7de05d, 0xa083, 0x40d7, 0xb7, 0xaf, 0x90, 0xaf, 0x8d, 0x43, 0x24, 0x89);

interface ITest : public IUnknown
{
    virtual HRESULT __stdcall Add(long int a, long int b, long int *c) = 0;
    virtual HRESULT __stdcall Concat(BSTR a, BSTR b, BSTR *c) = 0;
};

class CoTest : public ITest
{
private:
    LONG volatile m_refcnt;
public:
    CoTest();
    virtual ~CoTest();
    // IUnknown
    HRESULT __stdcall QueryInterface(REFIID riid, void **ppv);
    ULONG __stdcall AddRef();
    ULONG __stdcall Release();
    // ITest
    HRESULT __stdcall Add(long int a, long int b, long int *c);
    HRESULT __stdcall Concat(BSTR a, BSTR b, BSTR *c);
};

class CoTestFactory : IClassFactory
{
private:
    LONG volatile m_refcnt;
public:
    CoTestFactory();
    // IUnknown
    HRESULT __stdcall QueryInterface(REFIID riid, void **ppv);
    ULONG __stdcall AddRef();
    ULONG __stdcall Release();
    // IClassFactory
    HRESULT __stdcall CreateInstance(LPUNKNOWN pUnk, REFIID riid, void **ppv);
    HRESULT __stdcall LockServer(BOOL fLock);
};

#endif // TEST_H
