1

Background:

I have an existing code that uses functionality provided by Microsoft, to post XML data over HTTP. Specifically, IServerXMLHTTPRequest (included in MSXML3 and up) from msxml4.dll (COM).

The Problem:

In the possible eventuality, were MSXML4.DLL is missing on the client workstation, the described POST operation will simply fail. More information about MSXML versions.

The current code:

#import "msxml4.dll"
using namespace MSXML2;
…
IServerXMLHTTPRequestPtr spIXMLHTTPRequest = NULL;
hr = spIXMLHTTPRequest.CreateInstance(__uuidof(ServerXMLHTTP40));

Alternatives:

  1. Hard code to MSXML6 (instead of MSXML4). Not a good solution as we do not know what MSXML version is installed on the workstation. Also, the code will break again if Microsoft will release the next DLL version.
  2. Dynamically load the latest from the registry: Find MSXML version from registry and Dynamically load a function from a DLL
  3. Use the type library instead?
  4. I would be happy to hear additional alternatives

The question:

What is the simplest and most robust way to change my code to be MSXML version agnostic? That is, use IServerXMLHTTPRequest regardless of the MSXML version actually installed on the client machine. If no version of MSXML is installed, prompt the user and exit gracefully.

Need additional information? Just let me know

Thank you!

Community
  • 1
  • 1
Rotem Varon
  • 1,597
  • 1
  • 15
  • 32
  • The point of msxml4 was that you could install it yourself. So if it is missing then you did it wrong :) – Hans Passant Nov 10 '14 at 19:53
  • No, MSXML4 is no longer supported: http://msdn.microsoft.com/en-us/data/bb291077.aspx. I would like to use the version that exists on the machine. Thanks for your comment. – Rotem Varon Nov 10 '14 at 20:23
  • You are creating an instance of `ServerXMLHTTP40`, that is version 4 object. If it fails, you can try another version: `if(FAILED(hr)) { // hr = ...CoCreateInstance(... 60); }` – Roman R. Nov 12 '14 at 06:55
  • This is exactly what this guy did: http://stackoverflow.com/a/951879/895667. This not exactly what I am looking for as I would like to have no indication of version in my code (if possible...). Thanks for your comment @RomanR. – Rotem Varon Nov 12 '14 at 07:02

1 Answers1

1

From MSDN:

MSXML version 3.0 was the last version of MSXML to support version-independent GUIDs and ProgIDs. Starting with version 4.0, MSXML is installed on your computer in side-by-side mode. This means that, for example, installing MSXML 5.0 for Microsoft Office Applications does not replace any previously installed version of the MSXML parser on your computer. This is done to protect the quality of applications that are currently using earlier versions of MSXML. Side-by-side mode also allows you to decide which version of the parser to use in your code.

This means that there is no COM class installed which you can instantiate expecting that most recent installed version will be picked up, or otherwise someone else will decide for you whether to load MSXML 4 or 6 depending on availability or another criteria.

You are expected to use specific version and depend on respective runtime to be available or installed. Or you can switch between MSXML versions in your code as you already discovered.

Community
  • 1
  • 1
Roman R.
  • 68,205
  • 6
  • 94
  • 158