//
// Copyright 1997, Don Box/Addison Wesley
//
// This code accompanies the book 'The Component
// Object Model' from Addison Wesley. Blah blah blah
//
//
interface IChatSessionEvents;
[
uuid(5223A050-2441-11d1-AF4F-0060976AA886),
object
]
interface IChatSession : IUnknown
{
import «objidl.idl»;
[propget] HRESULT SessionName([out, string] OLECHAR **ppwsz);
HRESULT Say([in, string] const OLECHAR *pwszStatement);
HRESULT GetStatements([out] IEnumString **ppes);
HRESULT Advise([in] IChatSessionEvents *pEventSink,
[out] DWORD *pdwReg);
HRESULT Unadvise([in] DWORD dwReg);
}
[
uuid(5223A051-2441-11d1-AF4F-0060976AA886),
object
]
interface IChatSessionEvents : IUnknown
{
import «objidl.idl»;
HRESULT OnNewUser([in, string] const OLECHAR *pwszUser);
HRESULT OnUserLeft([in, string] const OLECHAR *pwszUser);
HRESULT OnNewStatement([in, string] const OLECHAR *pwszUser,
[in, string] const OLECHAR *pwszStmnt);
}
[
uuid(5223A052-2441-11d1-AF4F-0060976AA886),
object
]
interface IChatSessionManager : IUnknown
{
import «objidl.idl»;
HRESULT GetSessionNames([out] IEnumString **ppes);
HRESULT FindSession([in, string] const OLECHAR *pwszName,
[in] BOOL bDontCreate,
[in] BOOL bAllowAnonymousAccess,
[out] IChatSession **ppcs);
HRESULT DeleteSession([in, string] const OLECHAR *pwszName);
}
cpp_quote(«DEFINE_GUID(CLSID_ChatSession,0x5223a053,0x2441,»)
cpp_quote(«0x11d1,0xaf,0x4f,0x0,0x60,0x97,0x6a,0xa8,0x86);»)
/////////////////////////////////////////////////////
//
// client.cpp
//
// Copyright 1997, Don Box/Addison Wesley
//
// This code accompanies the book 'The Component
// Object Model' from Addison Wesley. Blah blah blah
//
//
#define _WIN32_WINNT 0x403
#include <windows.h>
#include <stdio.h>
#include <initguid.h>
#include <wchar.h>
#include «../include/COMChat.h»
#include «../include/COMChat_i.c»
void Error(HRESULT hr, const char *psz)
{
printf(«%s failed and returned 0x%x », psz, hr);
}
// utility function to print command line syntax
int Usage(void)
{
const char *psz =
«usage: client.exe <action> <user> <host> »
« where: »
« action = /sessions|/chat:session|/delete:session »
« user = /user:domain\user /password:pw |»
«/anonymous | <nothing> »
« host = /host:hostname | <nothing> »;
printf(psz);
return -1;
}
// utility function for printing a list of strings
void PrintAllStrings(IEnumString *pes)
{
enum { CHUNKSIZE = 64 };
OLECHAR *rgpwsz[CHUNKSIZE];
ULONG cFetched;
HRESULT hr;
do
{
hr = pes->Next(CHUNKSIZE, rgpwsz, &cFetched);
if (SUCCEEDED(hr))
{
for (ULONG i = 0; i < cFetched; i++)