-1

I'm writing an app that still needs to run on Windows XP. I want to use SHCreateMemStream(). MSDN says this:

Prior to Windows Vista, this function was not included in the public Shlwapi.h file, nor was it exported by name from Shlwapi.dll. To use it on earlier systems, you must call it directly from the Shlwapi.dll file as ordinal 12 (source)

But how do I do that? Since MSDN says that SHCreateMemStream() is not exported by name in Shlwapi.dll I guess I can't just use LoadLibrary() and GetProcAddress() to get a function pointer to it on XP. So how am I supposed to call this function on XP?

Note that I'm looking for a solution in plain C, not C++.

Andreas
  • 9,245
  • 9
  • 49
  • 97
  • 3
    Does [this](https://stackoverflow.com/q/3598108/10871073) help? – Adrian Mole Nov 02 '20 at 18:41
  • 2
    simply link with *Shlwapi.lib* - here anyway *SHCreateMemStream* imported by ordinal 12 – RbMm Nov 02 '20 at 18:52
  • 1
    "*I guess I can't just use `LoadLibrary()` and `GetProcAddress()` to get a function pointer to it on XP*" - yes, you can. `GetProcAddress()` can lookup a function by name **or ordinal**. – Remy Lebeau Nov 02 '20 at 19:55
  • @RemyLebeau: Thanks, I didn't know that. But it turns out that the link lib that comes with the Windows 7 SDK also imports the ordinal (as pointed out by RbMm in his answer). So the note in MSDN quoted in my OP is probably a relic from very old SDKs because in the Windows 7 SDK there's really nothing special to be done for `SHCreateMemStream()`. – Andreas Nov 02 '20 at 19:59

1 Answers1

2

not need something special for xp. as usual link with Shlwapi.lib and call SHCreateMemStream as any imported api. all Shlwapi.lib from ms sdk import SHCreateMemStream by ordinal 12 but not by name (this can be checked by run

link.exe /dump /exports <path>shlwapi.lib > shlwapi.txt

if all ok, you must view inside shlwapi.txt (of course you can select any name for output file)

Dump of file <path>shlwapi.lib

File Type: LIBRARY

     Exports

       ordinal    name

       ...

            12    _SHCreateMemStream@8
       ...

in output will be list of functions imported by this lib. before some names printed ordinal - this mean that this function imported by ordinal. in no ordinal - function imported by name. SHCreateMemStream imported by ordinal 12. so if you link with such lib - your PE will be import SHCreateMemStream by ordinal 12, but not by name. this you and need.

RbMm
  • 31,280
  • 3
  • 35
  • 56
  • You're right, it works. Compiled on Windows 7 with the Windows 7 SDK and it works just fine on XP. Thanks! – Andreas Nov 02 '20 at 19:57