Advertisement
Guest User

Untitled

a guest
Aug 26th, 2015
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. [uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)]
  2. library LHello
  3. {
  4. // bring in the master library
  5. importlib("actimp.tlb");
  6. importlib("actexp.tlb");
  7.  
  8. // bring in my interfaces
  9. #include "pshlo.idl"
  10.  
  11. [
  12. uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)
  13. ]
  14. cotype THello
  15. {
  16. interface IHello;
  17. interface IPersistFile;
  18. };
  19. };
  20.  
  21. [
  22. exe,
  23. uuid(2573F890-CFEE-101A-9A9F-00AA00342820)
  24. ]
  25. module CHelloLib
  26. {
  27.  
  28. // some code related header files
  29. importheader();
  30. importheader();
  31. importheader();
  32. importheader("pshlo.h");
  33. importheader("shlo.hxx");
  34. importheader("mycls.hxx ");
  35.  
  36. // needed typelibs
  37. importlib("actimp.tlb");
  38. importlib("actexp.tlb");
  39. importlib("thlo.tlb");
  40.  
  41. [
  42. uuid(2573F891-CFEE-101A-9A9F-00AA00342820),
  43. aggregatable
  44. ]
  45. coclass CHello
  46. {
  47. cotype THello;
  48. };
  49. };
  50.  
  51. #include "ipfix.hxx"
  52.  
  53. extern HANDLE hEvent;
  54.  
  55. class CHello : public CHelloBase
  56. {
  57. public:
  58. IPFIX(CLSID_CHello);
  59.  
  60. CHello(IUnknown *pUnk);
  61. ~CHello();
  62.  
  63. HRESULT __stdcall PrintSz(LPWSTR pwszString);
  64.  
  65. private:
  66. static int cObjRef;
  67. };
  68.  
  69. #include
  70. #include
  71. #include
  72. #include
  73. #include "thlo.h"
  74. #include "pshlo.h"
  75. #include "shlo.hxx"
  76. #include "mycls.hxx"
  77.  
  78. int CHello::cObjRef = 0;
  79.  
  80. CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)
  81. {
  82. cObjRef++;
  83. return;
  84. }
  85.  
  86. HRESULT __stdcall CHello::PrintSz(LPWSTR pwszString)
  87. {
  88. printf("%ws\n", pwszString);
  89. return(ResultFromScode(S_OK));
  90. }
  91.  
  92. CHello::~CHello(void)
  93. {
  94.  
  95. // when the object count goes to zero, stop the server
  96. cObjRef--;
  97. if( cObjRef == 0 )
  98. PulseEvent(hEvent);
  99.  
  100. return;
  101. }
  102.  
  103. #include < windows.h>
  104. #include
  105. #include " pshlo.h"
  106. #include "shlo.hxx"
  107. #include "mycls.hxx"
  108.  
  109. HANDLE hEvent;
  110.  
  111. int _cdecl main(
  112. int argc,
  113. char * argv[]
  114. ) {
  115. ULONG ulRef;
  116. DWORD dwRegistration;
  117. CHelloCF *pCF = new CHelloCF();
  118.  
  119. hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  120.  
  121. // Initialize the OLE libraries
  122. CoInitializeEx(NULL, COINIT_MULTITHREADED);
  123.  
  124. CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER,
  125. REGCLS_MULTIPLEUSE, &dwRegistration);
  126.  
  127. // wait on an event to stop
  128. WaitForSingleObject(hEvent, INFINITE);
  129.  
  130. // revoke and release the class object
  131. CoRevokeClassObject(dwRegistration);
  132. ulRef = pCF->Release();
  133.  
  134. // Tell OLE we are going away.
  135. CoUninitialize();
  136.  
  137. return(0);
  138. }
  139.  
  140. extern CLSID CLSID_CHello;
  141. extern UUID LIBID_CHelloLib;
  142.  
  143. CLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-00AA00342820 */
  144. 0x2573F891,
  145. 0xCFEE,
  146. 0x101A,
  147. { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
  148. };
  149.  
  150. UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-00AA00342820 */
  151. 0x2573F890,
  152. 0xCFEE,
  153. 0x101A,
  154. { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
  155. };
  156.  
  157. #include
  158. #include
  159. #include < stdlib.h>
  160. #include
  161. #include
  162. #include "pshlo.h"
  163. #include "shlo.hxx"
  164. #include "clsid.h"
  165.  
  166. int _cdecl main(
  167. int argc,
  168. char * argv[]
  169. ) {
  170. HRESULT hRslt;
  171. IHello *pHello;
  172. ULONG ulCnt;
  173. IMoniker * pmk;
  174. WCHAR wcsT[_MAX_PATH];
  175. WCHAR wcsPath[2 * _MAX_PATH];
  176.  
  177. // get object path
  178. wcsPath[0] = '\0';
  179. wcsT[0] = '\0';
  180. if( argc > 1) {
  181. mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);
  182. wcsupr(wcsPath);
  183. }
  184. else {
  185. fprintf(stderr, "Object path must be specified\n");
  186. return(1);
  187. }
  188.  
  189. // get print string
  190. if(argc > 2)
  191. mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1);
  192. else
  193. wcscpy(wcsT, L"Hello World");
  194.  
  195. printf("Linking to object %ws\n", wcsPath);
  196. printf("Text String %ws\n", wcsT);
  197.  
  198. // Initialize the OLE libraries
  199. hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  200.  
  201. if(SUCCEEDED(hRslt)) {
  202.  
  203. hRslt = CreateFileMoniker(wcsPath, &pmk);
  204. if(SUCCEEDED(hRslt))
  205. hRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello);
  206.  
  207. if(SUCCEEDED(hRslt)) {
  208.  
  209. // print a string out
  210. pHello->PrintSz(wcsT);
  211.  
  212. Sleep(2000);
  213. ulCnt = pHello->Release();
  214. }
  215. else
  216. printf("Failure to connect, status: %lx", hRslt);
  217.  
  218. // Tell OLE we are going away.
  219. CoUninitialize();
  220. }
  221.  
  222. return(0);
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement