KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q40356: FileWrite() Function Fails to Write Back Out to the File

Article: Q40356
Product(s): See article
Version(s): 1.00   | 1.00
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | | mspl13_basic
Last Modified: 15-MAY-1989

Problem:

I have a problem using the FileWrite Function programming with the M
and MEP Editor Version 1.00. I want to read a file (EXAMPLE.DOC) and
write exactly the same in a new file (FOO.DOC).

Response:

To test the example below, you only have to create a file named
EXAMPLE.DOC. See the compiler switches at the end of this article. The
second file FOO.DOC is created, but it is never written to it always
has zero length.

This is a problem with MEP Version 1.00's FileWrite() function. This
is one of the problems that kept the filter extension described in the
"Microsoft Systems Journal" September 1988 from working in Version
1.00.

Microsoft has confirmed this to be a problem in Version 1.00. We are
researching this problem and will post new information as it becomes
available.

The following is a short example where the problem (Function FileWrite
does not write) occurs:

#include "ext.h"
#define TRUE    -1
#define FALSE   0
#define NULL    ((char *) 0)

flagType pascal EXTERNAL Write(
unsigned int argData,
ARG far * pArg,
flagType fMeta)
{
    flagType flg;
    PFILE pFile;
    char  *p = "EXAMPLE.DOC";
    char  *w = "FOO.DOC";

    if((pFile = FileNameToHandle(p,NULL)) == 0)
    {
        pFile = AddFile(p);
        FileRead(p, pFile);
    }
    flg = FileWrite(w, pFile);
    return (flg);
}

struct swiDesc  swiTable[] ={
    { NULL, NULL, 0 }
};

struct cmdDesc  cmdTable[] ={
    {"Write", Write, 0, NOARG },
    {NULL,  NULL, 0, 0}
};

void EXTERNAL WhenLoaded (void)
{
    SetKey("Write", "alt+w");
    DoMessage("Write function now loaded.");
}

/*

*** Compiler switches I used ***

cl /c /Gs /Asfu %1.c
cl /Lp /AC /Fe%1.dll exthdrp.obj %1.obj skel.def

  */

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.