Home   Index   About
Ultimate Pack


Custom Search
HELLO.H (HELLO OLE Sample)

#ifdef WIN32

#ifdef UNICODE

#define FROM_OLE_STRING(str) str

#define TO_OLE_STRING(str) str

#else

#define FROM_OLE_STRING(str) ConvertToAnsi(str)

char* ConvertToAnsi(OLECHAR FAR* szW);

#define TO_OLE_STRING(str) ConvertToUnicode(str)

OLECHAR* ConvertToUnicode(char FAR* szA);

// Maximum length of string that can be converted between Ansi & Unicode

#define STRCONVERT_MAXLEN 300

#endif

#else // WIN16

#define APIENTRY far pascal

#define TCHAR char

#define TEXT(sz) sz

#define FROM_OLE_STRING(str) str

#define TO_OLE_STRING(str) str

#define LPTSTR LPSTR

// Windows NT defines the following in windowsx.h

#define GET_WM_COMMAND_ID(w,l) (w)

#define GET_WM_COMMAND_CMD(w,l) HIWORD(l)

#define GET_WM_COMMAND_HWND(w,l) LOWORD(l)

#endif

#define STRICT

// Resource IDs

#define IDD_MAINWINDOW 101

#define IDI_ICON 102

// Child window IDs

#define IDC_HELLODISPLAY 101

#define IDC_SAYHELLO 102

// MAX len of string table entries

#define STR_LEN 100

// String table constants

#define IDS_Name 1

#define IDS_HelloMessage 2

#define IDS_ErrorLoadingTypeLib 3

#define IDS_SayHello 4

#define IDS_ProgID 5

#define IDS_Unexpected 1001

// SCODEs for the Hello Application. This is required for vtable-binding

// Automation objects want to return custom HRESULTs. All the OLE-defined

// FACILITY_ITF codes have a code value which lies in the region 0x0000-0x01FFF.

// While it is legal for the definer to use any code, it is highly recommended

// that only code values in the range 0x0200-0xFFFF be used, as this will reduce the

// possiblity of accidental confusion with any OLE-defined errors.

#define HELLO_E_FIRST MAKE_SCODE(SEVERITY_ERROR, FACILITY_ITF, 0x0200)

#define HELLO_E_UNEXPECTED (HELLO_E_FIRST + 0x0)

// Unexpected error

// Number of SCODEs

#define SCODE_COUNT 1

// Function prototypes

int APIENTRY WinMain (HINSTANCE, HINSTANCE, LPSTR, int);

BOOL InitApplication (HINSTANCE);

BOOL InitInstance (HINSTANCE);

BOOL ProcessCmdLine(LPSTR lpCmdLine, LPDWORD pdwRegisterCF, LPDWORD pdwRegisterActiveObject, int nCmdShow);

  • oid Uninitialize(DWORD dwRegisterCF, DWORD dwRegisterActiveObject);

HRESULT LoadTypeInfo(ITypeInfo FAR* FAR* pptinfo, REFCLSID clsid);

#ifdef WIN16

extern "C" LRESULT __export CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);

#else

extern "C" LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);

#endif

#include "tlb.h"

// ISupportErrorInfo interface implementation

interface CSupportErrorInfo : public ISupportErrorInfo

{

public:

// IUnknown methods

STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR* ppvObj);

STDMETHOD_(ULONG, AddRef)(void);

STDMETHOD_(ULONG, Release)(void);

// ISupportErrorInfo method

STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);

CSupportErrorInfo(IUnknown FAR* punkObject, REFIID riid);

private:

LPUNKNOWN m_punkObject; // IUnknown of Object that implements this interface

GUID m_iid;

};

class FAR CHello : public IHello

{

public:

// IUnknown methods

STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR* ppvObj);

STDMETHOD_(ULONG, AddRef)(void);

STDMETHOD_(ULONG, Release)(void);

// IDispatch methods

STDMETHOD(GetTypeInfoCount)(UINT FAR* pctinfo);

STDMETHOD(GetTypeInfo)(

UINT itinfo,

LCID lcid,

ITypeInfo FAR* FAR* pptinfo);

STDMETHOD(GetIDsOfNames)(

REFIID riid,

OLECHAR FAR* FAR* rgszNames,

UINT cNames,

LCID lcid,

DISPID FAR* rgdispid);

STDMETHOD(Invoke)(

DISPID dispidMember,

REFIID riid,

LCID lcid,

WORD wFlags,

DISPPARAMS FAR* pdispparams,

VARIANT FAR* pvarResult,

EXCEPINFO FAR* pexcepinfo,

UINT FAR* puArgErr);

// IHello methods

STDMETHOD(get_Application)(IHello FAR* FAR* ppHello);

STDMETHOD(get_FullName)(BSTR FAR* pbstr);

STDMETHOD(get_Name)(BSTR FAR* pbstr);

STDMETHOD(get_Parent)(IHello FAR* FAR* ppHello);

STDMETHOD(put_Visible)(VARIANT_BOOL bVisible);

STDMETHOD(get_Visible)(VARIANT_BOOL FAR* pbool);

STDMETHOD(Quit)();

STDMETHOD(put_HelloMessage)(BSTR bstrMessage);

STDMETHOD(get_HelloMessage)(BSTR FAR* pbstrMessage);

STDMETHOD(SayHello)();

// CHello methods

STDMETHOD(RaiseException)(int nID);

STDMETHOD_(void, ShowWindow)(int nCmdShow);

static HRESULT Create(HINSTANCE hinst, LPTSTR lpszHelloMessage, CHello FAR* FAR* pphello); // Creates and intializes Hello object

CHello();

~CHello();

public:

HWND m_hwnd; // Application window.

HINSTANCE m_hinst; // Hinstance of application.

BSTR m_bstrName; // Name of application.

BSTR m_bstrProgID; // ProgID of application.

private:

LPTYPEINFO m_ptinfo; // Type information of Hello application interface.

BSTR m_bstrHelloMsg; // Hello message

BSTR m_bstrFullName; // Full name of application.

BOOL m_bVisible; // Is window visible?

EXCEPINFO m_excepinfo; // Information to raise an exception on error.

BOOL m_bRaiseException; // Properties and methods use this to signal that an exception is to be raised.

ULONG m_cRef; // Reference count

CSupportErrorInfo m_SupportErrorInfo; // ISupportErrorInfo interface implementation

};

class FAR CHelloCF : public IClassFactory

{

public:

// IUnknown methods

STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR* ppvObj);

STDMETHOD_(ULONG, AddRef)(void);

STDMETHOD_(ULONG, Release)(void);

// IClassFactory methods

STDMETHOD(CreateInstance)(IUnknown FAR* punkOuter, REFIID riid,

void FAR* FAR* ppv);

STDMETHOD(LockServer)(BOOL fLock);

CHelloCF();

private:

ULONG m_cRef; // Reference count

};

extern CHello FAR* g_phello;


Last news from Greatis Software

Nostalgia .Net     Nostalgia .Net     .Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes.  More »

Recommended software for developers

Ultimate Pack for Delphi and C++ Builder     Ultimate Pack     Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price.  More »

Form Designer .Net     Form Designer .Net     Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro!  More »

Print Suite .Net     Print Suite .Net     Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available  More »

Gradient Controls .Net     Gradient Controls .Net     Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available  More »

iGrid     Greatis iGrid     iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors.  More »


All the contacts and projects

Dmitry Vasiliev (just.dmitry)

Related Links

Software for Visual Studio .NET developers
Software for Delphi and C++ Builder developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET

More Online Helps

Win32 Programmer's Reference
Win32 Multimedia Programmer's Reference
OLE Programmer's Reference
Microsoft Windows Pen API Programmer's Reference
Microsoft Windows Sockets 2 Reference
Microsoft Windows Telephony API (TAPI) Programmer's Reference
Unix Manual Pages

Free Tech Secrets ;) Copyright © 2008-2012 Free Tech Secrets ;) greatis just4fun network just4fun