Click here to Skip to main content
15,884,298 members
Articles / Desktop Programming / ATL

Passing C++ Object in ATL DLL Server

Rate me:
Please Sign up or sign in to vote.
1.00/5 (3 votes)
16 Jun 20022 min read 104K   838   35  
This article explains how to pass a C++ object across a COM server.
// BolbData.cpp : Implementation of CBolbData
// Copyright (c) 2000, Uttam Kumar

#include "stdafx.h"
#include "Server.h"
#include "BolbData.h"
// Class provides Load and Expand functions to serialize and deserialize objects.
#include "Blob.h"
// A Simple class derived form CObject to be serialized and deserialized
#include "SimpleObj.h"

/////////////////////////////////////////////////////////////////////////////
// CBolbData


STDMETHODIMP CBolbData::SetArray(SAFEARRAY *pData)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())

  // create a dummy pointer of CSimpleObj
	CSimpleObj *dummy=NULL; 
	// create blob obect to expand/deserialize 
  CBlob blob;             
  // Init dummy object using safe array through this function
	blob.Expand( (CObject*&)dummy, pData );
  dummy->Show(); // Call show function to test the object.
  delete dummy;  // Delete the pointer.

	return S_OK;
}

STDMETHODIMP CBolbData::GetArray(SAFEARRAY **pData)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())
	// create object to send to server
	CSimpleObj *pMyOb = new CSimpleObj();

	// set the string data
	pMyOb->SetString( "A SAFEARRAY from the server!" );
	
	// create blob to serialize object
	CBlob blob;

	// load the object into the blob
	*pData = blob.Load( pMyOb );
	// delete the pMyOb pointer 
  delete pMyOb;

  return S_OK;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) Barclays Wealth
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions