What does the fCreate parameter to SHCreateStreamOnFileEx mean?

Date:January 19, 2007 / year-entry #21
Tags:code
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20070119-01/?p=28343
Comments:    9
Summary:The documentation for the fCreate parameter for the SHCreateStreamOnFileEx function covers the issue, but since people seem to really like charts and tables, I'll present the same information in tabular form. grfMode fCreate File exists? Behavior STGM_CREATE (ignored) Yes File is opened (old contents lost) STGM_CREATE (ignored) No File is created STGM_FAILIFTHERE FALSE Yes File...

The documentation for the fCreate parameter for the SHCreateStreamOnFileEx function covers the issue, but since people seem to really like charts and tables, I'll present the same information in tabular form.

grfMode fCreate File exists? Behavior
STGM_CREATE (ignored) Yes File is opened (old contents lost)
STGM_CREATE (ignored) No File is created
STGM_FAILIFTHERE FALSE Yes File is opened (old contents preserved)
STGM_FAILIFTHERE FALSE No Fails
STGM_FAILIFTHERE TRUE Yes Fails
STGM_FAILIFTHERE TRUE No File is created

Comments (9)
  1. ac says:

    It seems somebody already put your work in the msdn library?

    http://msdn2.microsoft.com/en-us/library/ms538417.aspx

  2. Henrik says:

    Perhaps it was Raymond himself.

  3. Dan says:

    That table’s logic makes my head hurt. :(  Especially the dual meaning of STGM_FAILIFTHERE, since it can FAILIFNOTTHERE and SUCCEEDIFTHERE if fCreate is FALSE.

  4. jj says:

    The version on MSDN doesn’t say when the contents of the file are lost – seems potentially dangerous.

    [It is already documented that STGM_CREATE deletes the old storage if it existed. -Raymond]
  5. John Elliott says:

    This reminded me of the DOS OPEN function on the Spectrum +3, where you passed a ‘create action’ saying what to do if the file didn’t exist, and an ‘open action’ saying what to do if it did. These were 0-based integers, but my copy of the manual used a 1-based list to describe them, so you had to subtract 1 from all the values it gave.

    I see there’s a (corrected) online copy at http://www.worldofspectrum.org/ZXSpectrum128+3Manual/chapter8pt27.html

  6. Miral says:

    I’m with Dan.  FAILIFTHERE fails if the file is *not* there when fCreate is FALSE, which is rather counterintuitive.

  7. Jim Kane says:

    Yes, tables that cover every possibility are great!  While your at it a table for VariantChangeType and/or variantchangetypeex would be great.

  8. Tyler Beam says:

    (Disclaimer: I added the fCreate param to SHCreateStreamOnFileEx.)  The reason for the weirdness is because STGM_FAILIFTHERE is a zero flag, and we had to work within the constraints of the existing STGM enumeration.

    Zero flags sometimes make sense when you’re giving a name for default behavior but this one obviously didn’t work out that well.

  9. Claimer says:

    (Disclaimer: I added the fCreate param to

    SHCreateStreamOnFileEx.)

    Isn’t that a Claimer?  Doesn’t a Disclaimer mean you don’t have certain relationships to specified matters?  For example when Usenet news postings used to identify which organization a writer was involved with, a disclaimer meant that that the posting wasn’t the organization’s official policy.  For example, this comment wasn’t written by MSDN.

    Metaclaim:  Claimer wrote this metaclaim.

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index