Home   Index   About
Ultimate Pack


Custom Search
POINT.CPP (LINES OLE Sample)

/*************************************************************************

  • OLE Automation Points Object.

  • point.cpp

  • CPoint implementation

  • Written by Microsoft Product Support Services, Windows Developer Support

  • (c) Copyright Microsoft Corp. 1994 All Rights Reserved

  • ***********************************************************************/

#include <windows.h>

#include <windowsx.h>

#ifdef WIN16

#include <ole2.h>

#include <compobj.h>

#include <dispatch.h>

#include <variant.h>

#include <olenls.h>

#endif

#include "lines.h"

/*

* CPoint::Create

*

* Purpose:

* Creates an instance of the Point automation object and initializes it.

*

* Parameters:

* ppPoint Returns Point automation object.

*

* Return Value:

* HRESULT

*

*/

HRESULT

CPoint::Create(CPoint FAR* FAR* ppPoint )

{

HRESULT hr;

CPoint FAR* pPoint = NULL;

*ppPoint = NULL;

pPoint = new CPoint();

if (pPoint == NULL)

goto error;

// Load type information for the point from type library.

hr = LoadTypeInfo(&pPoint->m_ptinfo, IID_IPoint);

if (FAILED(hr))

goto error;

*ppPoint = pPoint;

return NOERROR;

error:

if (pPoint == NULL)

return ResultFromScode(E_OUTOFMEMORY);

if (pPoint->m_ptinfo)

pPoint->m_ptinfo->Release();

// Set to NULL to prevent destructor from attempting to free again

pPoint->m_ptinfo = NULL;

delete pPoint;

return hr;

}

/*

* CPoint::CPoint

*

* Purpose:

* Constructor for CPoint object. Initializes members to NULL.

*

*/

#pragma warning (disable : 4355)

CPoint::CPoint() : m_SupportErrorInfo(this, IID_IPoint)

#pragma warning (default : 4355)

{

m_cRef = 0;

m_cInternalRef = 0;

m_ptinfo = NULL;

m_nX = -1;

m_nY = -1;

}

/*

* CPoint::~CPoint

*

* Purpose:

* Destructor for CPoint object. Frees Point message BSTR and default

* IDispatch implementation. Closes the aplication.

*

*/

CPoint::~CPoint()

{

if (m_ptinfo) m_ptinfo->Release();

}

/*

* CPoint::QueryInterface, AddRef, Release

*

* Purpose:

* Implements IUnknown::QueryInterface, AddRef, Release

*

*/

STDMETHODIMP

CPoint::QueryInterface(REFIID iid, void FAR* FAR* ppv)

{

*ppv = NULL;

if (iid == IID_IUnknown || iid == IID_IDispatch || iid == IID_IPoint)

*ppv = this;

else if (iid == IID_ISupportErrorInfo)

*ppv = &m_SupportErrorInfo;

else return ResultFromScode(E_NOINTERFACE);

AddRef();

return NOERROR;

}

STDMETHODIMP_(ULONG)

CPoint::AddRef(void)

{

#ifdef _DEBUG

TCHAR ach[50];

wsprintf(ach, TEXT("Ref = %ld, Point\r\n"), m_cRef+1);

OutputDebugString(ach);

#endif

return ++m_cRef;

}

STDMETHODIMP_(ULONG)

CPoint::Release(void)

{

#ifdef _DEBUG

TCHAR ach[50];

wsprintf(ach, TEXT("Ref = %ld, Point\r\n"), m_cRef-1);

OutputDebugString(ach);

#endif

if(--m_cRef == 0)

{

delete this;

return 0;

}

return m_cRef;

}

/*

* CPoint::GetTypeInfoCount

*

* Purpose:

* Implements IDispatch::GetTypeInfoCount.

*

*/

STDMETHODIMP

CPoint::GetTypeInfoCount(UINT FAR* pctinfo)

{

*pctinfo = 1;

return NOERROR;

}

/*

* CPoint::GetTypeInfo

*

* Purpose:

* Implements IDispatch::GetTypeInfo.

*

*/

STDMETHODIMP

CPoint::GetTypeInfo(

UINT itinfo,

LCID lcid,

ITypeInfo FAR* FAR* pptinfo)

{

*pptinfo = NULL;

if(itinfo != 0)

return ResultFromScode(DISP_E_BADINDEX);

m_ptinfo->AddRef();

*pptinfo = m_ptinfo;

return NOERROR;

}

/*

* CPoint::GetIDsOfNames

*

* Purpose:

* Implements IDispatch::GetIDsOfNames. The standard implementation, DispGetIDsOfNames,

* is used.

*

*/

STDMETHODIMP

CPoint::GetIDsOfNames(

REFIID riid,

OLECHAR FAR* FAR* rgszNames,

UINT cNames,

LCID lcid,

DISPID FAR* rgdispid)

{

return DispGetIDsOfNames(m_ptinfo, rgszNames, cNames, rgdispid);

}

/*

* CPoint::Invoke

*

* Purpose:

* Implements IDispatch::Invoke. The standard implementation, DispInvoke,

* is used.

*

*/

STDMETHODIMP

CPoint::Invoke(

DISPID dispidMember,

REFIID riid,

LCID lcid,

WORD wFlags,

DISPPARAMS FAR* pdispparams,

VARIANT FAR* pvarResult,

EXCEPINFO FAR* pexcepinfo,

UINT FAR* puArgErr)

{

return DispInvoke(

this, m_ptinfo,

dispidMember, wFlags, pdispparams,

pvarResult, pexcepinfo, puArgErr);

}

STDMETHODIMP

CPoint::get_x(int FAR* pnX)

{

*pnX = m_nX;

return NOERROR;

}

STDMETHODIMP

CPoint::put_x(int nX)

{

m_nX = nX;

return NOERROR;

}

STDMETHODIMP

CPoint::get_y(int FAR* pnY)

{

*pnY = m_nY;

return NOERROR;

}

STDMETHODIMP

CPoint::put_y(int nY)

{

m_nY = nY;

return NOERROR;

}

/*

*

* The following methods are not exposed through Automation

*

*/

/*

* CPoint::InternalAddRef, InternalRelease

*

* Purpose:

* Implements an internal ref count for the use of the points collection.

* The points collection does not have duplicates, instead a reference count is incremented.

* A point is removed from the collection when the reference count drops to 0.

*

*/

STDMETHODIMP_(ULONG)

CPoint::InternalAddRef(void)

{

#ifdef _DEBUG

TCHAR ach[50];

wsprintf(ach, TEXT("Internal Ref = %ld, Point\r\n"), m_cInternalRef+1);

OutputDebugString(ach);

#endif

return ++m_cInternalRef;

}

STDMETHODIMP_(ULONG)

CPoint::InternalRelease(void)

{

#ifdef _DEBUG

TCHAR ach[50];

wsprintf(ach, TEXT("Internal Ref = %ld, Point\r\n"), m_cInternalRef-1);

OutputDebugString(ach);

#endif

return --m_cInternalRef;

}

STDMETHODIMP_(int)

CPoint::get_x(void)

{

return m_nX;

}

STDMETHODIMP_(int)

CPoint::get_y(void)

{

return m_nY;

}


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