Thursday, January 17, 2008

Using the Delphi Type Library Importer to Import Microsoft XML

Over the years I've gotten many questions about importing Microsoft XML with the type library importer and why the resulting *_TLB.pas file doesn't match that of Microsoft's documentation. There are a lot of interfaces with the same problem but lets take a closer look at one of them as an example. You can find the documentation for ISAXDXMLReader.getProperty here. The documentation provides the following C++ code for the getProperty function:

HRESULT getProperty(
const wchar_t* pwchName,
VARIANT* pvarValue

Notice the type of pwchName. It's type is const wchar_t* which should be const WideString but as you can see after importing the type library you get:

function getProperty(var pwchName: Word;
out pvarValue: OleVariant): HResult; stdcall;

Obviously the codegen is wrong but why is that. If you take a look at the .tlb in Ole View or the Type Library Editor you'll notice the following IDL:

HRESULT _stdcall getProperty(
[in] unsigned short* pwchName,
[out, retval] VARIANT* pvarValue);

Notice the unsigned short*. The type library importer generated it as a var Word. This means the type library is doing exactly what it should be doing.

So either the documentation is incorrect or the .tlb is incorrect.

No comments:

Post a Comment