File: CLIENT.CPP

package info (click to toggle)
camlidl 1.05-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 872 kB
  • ctags: 1,131
  • sloc: ml: 4,894; ansic: 940; cpp: 897; makefile: 294; sh: 182
file content (72 lines) | stat: -rw-r--r-- 1,621 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// Client.cpp - Client implementation
//   This client connects to the IX dual interface
//   through the vtbl.
//
#include <objbase.h>
#include <iostream.h>

#include "Util.h"
#include "Iface.h"

static inline void trace(char* msg)
	{ Util::Trace("Client", msg, S_OK) ;} 
static inline void trace(char* msg, HRESULT hr)
	{ Util::Trace("Client", msg, hr) ;}

void test(const CLSID & clsid)
{
	DWORD clsctx ;
	clsctx = CLSCTX_INPROC_SERVER ;		
	trace("Attempt to create in-proc component.") ;

	IX* pIX = NULL ; 
	HRESULT hr = CoCreateInstance(clsid,
	                              NULL,
	                              clsctx, 
	                              IID_IX,
	                              (void**)&pIX) ;
	if (SUCCEEDED(hr))
	{
		trace("Successfully created component.") ;
		trace("Use interface IX.") ;
		wchar_t* wszIn = L"This is the test." ;
		BSTR bstrIn ;
		bstrIn = ::SysAllocString(wszIn) ; 
		pIX->FxStringIn(bstrIn) ; 
		::SysFreeString(bstrIn) ;

		BSTR bstrOut ; //@dual
		pIX->FxStringOut(&bstrOut ) ;

		// Display returned string.
		ostrstream sout ;
		sout << "FxStringOut returned a string:  "
		     << bstrOut 
		     << ends;
		trace(sout.str()) ;
		::SysFreeString(bstrOut ) ;

		trace("Release IX.") ;
		pIX->Release() ;
	}
	else
	{
		trace("Could not create component.", hr);
	}

}

const CLSID CLSID_Caml_Component = 
  {0x6a3d0750, 0xdad9, 0x11d2, {0x8e, 0x2c, 0x00, 0x60, 0x97, 0x4f, 0xbf, 0x19} };

int main()
{
  // Initialize COM Library
  CoInitialize(NULL) ;
  test(CLSID_Component);
  test(CLSID_Caml_Component);
  // Uninitialize COM Library
  CoUninitialize() ;
  return 0;
}