Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

This is from the Evolution of a Programmer "joke", at the "Master Programmer" level. It seems to be C++, but I don't know what all this bloated extra stuff is, nor did any Google searches turn up anything except the joke I took it from. Can anyone tell me more about what I'm reading here?

  [
  uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)
  ]
  library LHello
  {
      // bring in the master library
      importlib("actimp.tlb");
      importlib("actexp.tlb");
      // bring in my interfaces
      #include "pshlo.idl"
      [
      uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)
      ]
      cotype THello
   {
   interface IHello;
   interface IPersistFile;
   };
  };
  [
  exe,
  uuid(2573F890-CFEE-101A-9A9F-00AA00342820)
  ]
  module CHelloLib
  {
      // some code related header files
      importheader(<windows.h>);
      importheader(<ole2.h>);
      importheader(<except.hxx>);
      importheader("pshlo.h");
      importheader("shlo.hxx");
      importheader("mycls.hxx");
      // needed typelibs
      importlib("actimp.tlb");
      importlib("actexp.tlb");
      importlib("thlo.tlb");
      [
      uuid(2573F891-CFEE-101A-9A9F-00AA00342820),
      aggregatable
      ]
      coclass CHello
   {
   cotype THello;
   };
  };
  #include "ipfix.hxx"
  extern HANDLE hEvent;
  class CHello : public CHelloBase
  {
  public:
      IPFIX(CLSID_CHello);
      CHello(IUnknown *pUnk);
      ~CHello();
      HRESULT  __stdcall PrintSz(LPWSTR pwszString);
  private:
      static int cObjRef;
  };
  #include <windows.h>
  #include <ole2.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include "thlo.h"
  #include "pshlo.h"
  #include "shlo.hxx"
  #include "mycls.hxx"
  int CHello:cObjRef = 0;
  CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)
  {
      cObjRef++;
      return;
  }
  HRESULT  __stdcall  CHello::PrintSz(LPWSTR pwszString)
  {
      printf("%ws\n", pwszString);
      return(ResultFromScode(S_OK));
  }

  CHello::~CHello(void)
  {
  // when the object count goes to zero, stop the server
  cObjRef--;
  if( cObjRef == 0 )
      PulseEvent(hEvent);
  return;
  }
  #include <windows.h>
  #include <ole2.h>
  #include "pshlo.h"
  #include "shlo.hxx"
  #include "mycls.hxx"
  HANDLE hEvent;
   int _cdecl main(
  int argc,
  char * argv[]
  ) {
  ULONG ulRef;
  DWORD dwRegistration;
  CHelloCF *pCF = new CHelloCF();
  hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  // Initialize the OLE libraries
  CoInitiali, NULL);
  // Initialize the OLE libraries
  CoInitializeEx(NULL, COINIT_MULTITHREADED);
  CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER,
      REGCLS_MULTIPLEUSE, &dwRegistration);
  // wait on an event to stop
  WaitForSingleObject(hEvent, INFINITE);
  // revoke and release the class object
  CoRevokeClassObject(dwRegistration);
  ulRef = pCF->Release();
  // Tell OLE we are going away.
  CoUninitialize();
  return(0); }
  extern CLSID CLSID_CHello;
  extern UUID LIBID_CHelloLib;
  CLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-00AA00342820 */
      0x2573F891,
      0xCFEE,
      0x101A,
      { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
  };
  UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-00AA00342820 */
      0x2573F890,
      0xCFEE,
      0x101A,
      { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
  };
  #include <windows.h>
  #include <ole2.h>
  #include <stdlib.h>
  #include <string.h>
  #include <stdio.h>
  #include "pshlo.h"
  #include "shlo.hxx"
  #include "clsid.h"
  int _cdecl main(
  int argc,
  char * argv[]
  ) {
  HRESULT  hRslt;
  IHello        *pHello;
  ULONG  ulCnt;
  IMoniker * pmk;
  WCHAR  wcsT[_MAX_PATH];
  WCHAR  wcsPath[2 * _MAX_PATH];
  // get object path
  wcsPath[0] = '\0';
  wcsT[0] = '\0';
  if( argc > 1) {
      mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);
      wcsupr(wcsPath);
      }
  else {
      fprintf(stderr, "Object path must be specified\n");
      return(1);
      }
  // get print string
  if(argc > 2)
      mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1);
  else
      wcscpy(wcsT, L"Hello World");
  printf("Linking to object %ws\n", wcsPath);
  printf("Text String %ws\n", wcsT);
  // Initialize the OLE libraries
  hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  if(SUCCEEDED(hRslt)) {
      hRslt = CreateFileMoniker(wcsPath, &pmk);
      if(SUCCEEDED(hRslt))
   hRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello);
      if(SUCCEEDED(hRslt)) {
   // print a string out
   pHello->PrintSz(wcsT);
   Sleep(2000);
   ulCnt = pHello->Release();
   }
      else
   printf("Failure to connect, status: %lx", hRslt);
      // Tell OLE we are going away.
      CoUninitialize();
      }
  return(0);
  }
share|improve this question

closed as off topic by Telastyn, Martin Beckett, Walter, Eric King, MainMa Nov 19 '12 at 22:01

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

4 Answers

it prints "hello world" - the traditional first program in any beginner class.

It's a joke about the complexity of some Microsoft frameworks, especially OLE

share|improve this answer
1  
I know it prints hello world, naturally that's the point...I just didn't know for what framework/system it was necessary to write like this. this is what you have to do for windows? – Aerovistae Nov 18 '12 at 19:21
14  
No - it's how you could do it if you wanted to really follow all the possible details of using OLE. It's like describign how to build a house by including the details of mining the clay and describing how to build a brick factory – Martin Beckett Nov 18 '12 at 19:23
2  
@MartinBeckett Isn't a brick factory usually itself an instance of House? – Michael Kjörling Nov 19 '12 at 15:12
4  
@MichaelKjörling - except in Java you would have a BrickFactoryFactory to generate each BrickFactory and then the BrickFactory would generate each Brick – Martin Beckett Nov 19 '12 at 16:36
1  
@MartinBeckett your BrickFactoryFactory is a tight-coupling point, implementation must be segregated by the BrickFactoryFactoryManager which will be injected using the interface in case you want a different BrickFactoryFactory for different BrickFactories for different Bricks. The IBrickFactoryFactoryManager is highly dependent on the IClayMiningWorkerManagerFactory, this coupling should probably be fixed in iteration two... – Jimmy Hoffa Feb 4 at 16:33

Looks like it may be Microsoft's flavor of IDL (Interface Definition Language) followed by C++ source.

ref for MIDL: http://msdn.microsoft.com/en-us/library/aa367088.aspx

share|improve this answer

It is old Microsoft OLE (Object Linking and Embedding) code.

Microsoft has done several frameworks over the years, all of them mutually incompatible.

share|improve this answer

I believe it's C++/CLI, a Microsoft-specific language derived from C++.

UPDATE: From comments, it looks like I was probably mistaken. I'm going to leave this answer here, at least for now, because I think it was a reasonable guess and it's probably instructive to see why it was incorrect.

share|improve this answer
It is not. C++/CLI is a lot less plumbing-heavy, and can be easily identified by references to managed objects using the Object^ notation. This is just COM classes with all the autogenerated stuff implictly mentioned. – Avner Shahar-Kashtan Nov 18 '12 at 20:50
Ok, but what language is it? Parts of it are valid C++, but the "plumbing" would be treated as a syntax error by any conforming C++ compiler. – Keith Thompson Nov 18 '12 at 21:16
It doesn't have to be syntactically correct to be funny. – Michael Shaw Nov 18 '12 at 21:36
@MichaelShaw: I wasn't questioning the humor. I believe it's syntactically valid in some version of some C++-like language; I'm curious what language (or dialect) it is. – Keith Thompson Nov 18 '12 at 21:46
3  
It's three different source files concatenated. The first is IDL (en.wikipedia.org/wiki/Interface_description_language), the next two C++. (One C++ header and one C++ source file.) – Steven Burnap Nov 19 '12 at 4:11
show 2 more comments

Not the answer you're looking for? Browse other questions tagged or ask your own question.