Master Programmer <BR> ================= <BR> [ <BR> uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820) <BR> ] <BR> library LHello <BR> { <BR> // bring in the master library <BR> importlib("actimp.tlb"); <BR> importlib("actexp.tlb"); <BR> <BR> // bring in my interfaces <BR> #include "pshlo.idl" <BR> <BR> [ <BR> uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820) <BR> ] <BR> cotype THello <BR> { <BR> interface IHello; <BR> interface IPersistFile; <BR> }; <BR> }; <BR> <BR> [ <BR> exe, <BR> uuid(2573F890-CFEE-101A-9A9F-00AA00342820) <BR> ] <BR> module CHelloLib <BR> { <BR> <BR> // some code related header files <BR> importheader(<windows.h>); <BR> importheader(<ole2.h>); <BR> importheader(<except.hxx>); <BR> importheader("pshlo.h"); <BR> importheader("shlo.hxx"); <BR> importheader("mycls.hxx"); <BR> <BR> // needed typelibs <BR> importlib("actimp.tlb"); <BR> importlib("actexp.tlb"); <BR> importlib("thlo.tlb"); <BR> <BR> [ <BR> uuid(2573F891-CFEE-101A-9A9F-00AA00342820), <BR> aggregatable <BR> ] <BR> coclass CHello <BR> { <BR> cotype THello; <BR> }; <BR> }; <BR> <BR> <BR> #include "ipfix.hxx" <BR> <BR> extern HANDLE hEvent; <BR> <BR> class CHello : public CHelloBase <BR> { <BR> public: <BR> IPFIX(CLSID_CHello); <BR> <BR> CHello(IUnknown *pUnk); <BR> ~CHello(); <BR> <BR> HRESULT __stdcall PrintSz(LPWSTR pwszString); <BR> <BR> private: <BR> static int cObjRef; <BR> }; <BR> <BR> <BR> #include <windows.h> <BR> #include <ole2.h> <BR> #include <stdio.h> <BR> #include <stdlib.h> <BR> #include "thlo.h" <BR> #include "pshlo.h" <BR> #include "shlo.hxx" <BR> #include "mycls.hxx" <BR> <BR> int CHello::cObjRef = 0; <BR> <BR> CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk) <BR> { <BR> cObjRef++; <BR> return; <BR> } <BR> <BR> HRESULT __stdcall CHello::PrintSz(LPWSTR pwszString) <BR> { <BR> printf("%ws\n", pwszString); <BR> return(ResultFromScode(S_OK)); <BR> } <BR> <BR> <BR> CHello::~CHello(void) <BR> { <BR> <BR> // when the object count goes to zero, stop the server <BR> cObjRef--; <BR> if( cObjRef == 0 ) <BR> PulseEvent(hEvent); <BR> <BR> return; <BR> } <BR> <BR> #include <windows.h> <BR> #include <ole2.h> <BR> #include "pshlo.h" <BR> #include "shlo.hxx" <BR> #include "mycls.hxx" <BR> <BR> HANDLE hEvent; <BR> <BR> int _cdecl main( <BR> int argc, <BR> char * argv[] <BR> ) { <BR> ULONG ulRef; <BR> DWORD dwRegistration; <BR> CHelloCF *pCF = new CHelloCF(); <BR> <BR> hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); <BR> <BR> // Initialize the OLE libraries <BR> CoInitializeEx(NULL, COINIT_MULTITHREADED); <BR> <BR> CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER, <BR> REGCLS_MULTIPLEUSE, &dwRegistration); <BR> <BR> // wait on an event to stop <BR> WaitForSingleObject(hEvent, INFINITE); <BR> <BR> // revoke and release the class object <BR> CoRevokeClassObject(dwRegistration); <BR> ulRef = pCF->Release(); <BR> <BR> // Tell OLE we are going away. <BR> CoUninitialize(); <BR> <BR> return(0); <BR> } <BR> <BR> extern CLSID CLSID_CHello; <BR> extern UUID LIBID_CHelloLib; <BR> <BR> CLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-00AA00342820 */ <BR> 0x2573F891, <BR> 0xCFEE, <BR> 0x101A, <BR> { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 } <BR> }; <BR> <BR> UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-00AA00342820 */ <BR> 0x2573F890, <BR> 0xCFEE, <BR> 0x101A, <BR> { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 } <BR> }; <BR> <BR> #include <windows.h> <BR> #include <ole2.h> <BR> #include <stdlib.h> <BR> #include <string.h> <BR> #include <stdio.h> <BR> #include "pshlo.h" <BR> #include "shlo.hxx" <BR> #include "clsid.h" <BR> <BR> int _cdecl main( <BR> int argc, <BR> char * argv[] <BR> ) { <BR> HRESULT hRslt; <BR> IHello *pHello; <BR> ULONG ulCnt; <BR> IMoniker * pmk; <BR> WCHAR wcsT[_MAX_PATH]; <BR> WCHAR wcsPath[2 * _MAX_PATH]; <BR> <BR> // get object path <BR> wcsPath[0] = ´\0´; <BR> wcsT[0] = ´\0´; <BR> if( argc > 1) { <BR> mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1); <BR> wcsupr(wcsPath); <BR> } <BR> else { <BR> fprintf(stderr, "Object path must be specified\n"); <BR> return(1); <BR> } <BR> <BR> // get print string <BR> if(argc > 2) <BR> mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1); <BR> else <BR> wcscpy(wcsT, L"Hello World"); <BR> <BR> printf("Linking to object %ws\n", wcsPath); <BR> printf("Text String %ws\n", wcsT); <BR> <BR> // Initialize the OLE libraries <BR> hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED); <BR> <BR> if(SUCCEEDED(hRslt)) { <BR> <BR> <BR> hRslt = CreateFileMoniker(wcsPath, &pmk); <BR> if(SUCCEEDED(hRslt)) <BR> hRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello); <BR> <BR> if(SUCCEEDED(hRslt)) { <BR> <BR> // print a string out <BR> pHello->PrintSz(wcsT); <BR> <BR> Sleep(2000); <BR> ulCnt = pHello->Release(); <BR> } <BR> else <BR> printf("Failure to connect, status: %lx", hRslt); <BR> <BR> // Tell OLE we are going away. <BR> CoUninitialize(); <BR> } <BR> <BR> return(0); <BR> } <BR> <BR># END: return programmer to real world <BR>