
// testmyServ.cpp : 
// TestClient for COM server: by Shoaib Ali
// you can submit your comments at alleey@usa.net.
//
// Test Application for the COM server all we need is the file containing the CLSID with by the way is
// not that neccessary however we still need the interface definition file as it gives us the prototype
// of all the methods and its uuid...
//


#include "stdafx.h"
#include <ComDef.h>
#include "myInterface.h"
#include "myServ_supp.h"

void main()
{
/*	CoInitialize(0);
	HRESULT hr;
	ImyInterface *pmine=(0);
	hr = CoCreateInstance(CLSID_Mine,				// CLSID of COM server
						  NULL,						//
						  CLSCTX_INPROC_SERVER,		// it is a DLL 
						  __uuidof(ImyInterface),	// the interface IID
						  (void**)&pmine			// 
						  );
	if(FAILED(hr))
	{
		printf("failed to initialize COM server");
		return ;
	}

	long value = 10;
	printf("Enter a number : ") , scanf("%ld",&value);

	hr = pmine->Cube(&value);  // Call interface method 
	if(FAILED(hr))
		printf("failed square of ImyInterface.\n");
	else
		printf("Cube of the number is %ld. \n",value);

	pmine->Release();	// dont forget to do this ....	*/

	// Initialize the library
	MYSERV_DllMain(GetModuleHandle(NULL), DLL_PROCESS_ATTACH, NULL);

	IClassFactory *pIClassFactory = NULL;
	ImyInterface *pmine = NULL;
	HRESULT hr;

	// Get class object for CLSID_Mine
	hr = MYSERV_DllGetClassObject(CLSID_Mine, IID_IClassFactory, (LPVOID *)&pIClassFactory);

	if(FAILED(hr))
	{
		printf("failed to get class object");
		return ;
	}

	// Create an instance with class object
	hr = pIClassFactory->CreateInstance(NULL, __uuidof(ImyInterface), (LPVOID *)&pmine);

	pIClassFactory->Release();

	if(FAILED(hr))
	{
		printf("failed to initialize COM server");
		return ;
	}

	long value = 10;
	printf("Enter a number : ") , scanf("%ld",&value);

	hr = pmine->Cube(&value);  // Call interface method 
	if(FAILED(hr))
		printf("failed square of ImyInterface.\n");
	else
		printf("Cube of the number is %ld. \n",value);

	pmine->Release();	// dont forget to do this ....

	// Finalize the library
	MYSERV_DllMain(GetModuleHandle(NULL), DLL_PROCESS_DETACH, NULL);
}

