Discussion:
Problems with own Converter in Word 2003
(too old to reply)
Stefan Wanger
2006-04-05 11:05:47 UTC
Permalink
Hi,

hope anyone can help me.

I wrote a Text Converter. It works fine with Word XP and 2000, but in 2003 i
have these 2 problems:

1. Word 2003 shows a security warning when using my converter. Is there a
possibility to avoid this warning.

2. When I use Word's SaveAs with Filename and SaveFormat for my converter,
it seems that the SaveFormat is not correct and Word displays the SaveAs
Dialog. I took the SaveFormat from the FileConverters Collection!

Stefan
Peter Jamieson
2006-04-05 13:43:21 UTC
Permalink
For problem 1, there is an additional option in the converter API - MS sent
me the following info back in 2003, but I don't think they ever got around
to updating the Converter SDK:

MS were particularly keen that you don't let the calling app suppress the
prompt if there is a possibility of a buffer overflow.

I think there was a bit more but this is the only part that I have to hand.

I can't answer problem 2 but maybe fixing problem 1 will have an impact on
that.

I'll be offline for a few days.

Peter Jamieson
-------------------------------------------------------------------
Here are the details for the new RegisterApp opcode. The implementation is
simple in theory; the actual difficulty will depend on how they have
implemented their RegisterApp function.

First, some background on RegisterApp. This converter API has been around
for along time - it allows a variable number of "opcodes" to be sent from
the calling application to the converter, and another variable set of
"opcodes" to be returned from the converter to the calling application. To
date, this has been used for things like filename character sets (to shed
the old OEM charset dependency), unicode RTF, etc.

The new Security opcode is just another opcode that the converter can return
to the application. It requests that the application suppress the new
Security Warning.

Here are the changes that I made to our core converters to support this
(highlighted lines were added; the other lines are included for context)

// REGAPPRET byte opcodes

#define RegAppOpcodeVer 0x01 // Rtf version converter is
prepared to accept

#define RegAppOpcodeDocfile 0x02 // converter's ability to
handle regular and docfiles

#define RegAppOpcodeCharset 0x03 // converter is prepared to
handle filenames in this character set

#define RegAppOpcodeReloadOnSave 0x04 // app should reload
document after exporting

#define RegAppOpcodePicPlacehold 0x05 // app should send
placeholder pictures (with size info) for includepicture \d fields

#define RegAppOpcodeFavourUnicode 0x06 // app should output Unicode
RTF whenever possible, especially for DBCS; \uc0 is good

#define RegAppOpcodeNoClassifyChars 0x07 // app should not break text
runs by character set clasification

#define RegAppOpcodeReturnHtml 0x08 // Converter will return
HTML instead of RTF

#define RegAppOpcodeRtfCodepage 0x09 // app sould return RTF in
the specified codepage

#define RegAppOpcode7BitRtf 0x0a // app should return 7bit
rtf
#define RegAppOpcodeSuppressSecurityPrompt 0x0b // app can suppress
the security prompt -- this converter has been security reviewed

#pragma pack(1)

typedef struct _REGAPPRET // we always return these RegApp flags, so we
just put this in a structure.

{
short cbStruct; // size of this structure
// Does this converter understand docfiles and/or non-docfiles?
char cbSizefDocfile;
char opcodefDocfile;
union
{
struct
{
short fDocfile : 1;
short fNonDocfile : 1;
short : 14;
};
short grfType;
};

// Version of Word for which converter's Rtf is compliant
char cbSizeVer; //
==sizeof(char)+sizeof(char)+sizeof(short)+sizeof(short)
char opcodeVer;
short verMajor; // Major version of Word for which Rtf is
compliant
short verMinor; // Minor version of Word for which Rtf is
compliant

// What character set do we want all filenames to be in.
char cbSizeCharset;
char opcodeCharset;
char charset;

char opcodesOptional[]; // optional additional stuff
} REGAPPRET;

#pragma pack()

// Allocate return structure (allocation the largest possible block)

< if ((hRegAppRet = GlobalAlloc(GMEM_MOVEABLE, sizeof(REGAPPRET) + 10)) ==
NULL)
if ((hRegAppRet = GlobalAlloc(GMEM_MOVEABLE, sizeof(REGAPPRET) + 12)) ==
NULL)

return (HGLOBAL)0;
pbOpcodesOptional = lpRegAppRet->opcodesOptional;
*pbOpcodesOptional++ = 2; // cb of 0
*pbOpcodesOptional++ = RegAppOpcodeSuppressSecurityPrompt;
lpRegAppRet->cbStruct = (short)((ULONG_PTR)(pbOpcodesOptional) -
(ULONG_PTR)(lpRegAppRet));
GlobalUnlock(hRegAppRet);
return hRegAppRet;
-------------------------------------------------------------------
Hi,
hope anyone can help me.
I wrote a Text Converter. It works fine with Word XP and 2000, but in 2003
1. Word 2003 shows a security warning when using my converter. Is there a
possibility to avoid this warning.
2. When I use Word's SaveAs with Filename and SaveFormat for my converter,
it seems that the SaveFormat is not correct and Word displays the SaveAs
Dialog. I took the SaveFormat from the FileConverters Collection!
Stefan
Peter Jamieson
2006-04-05 13:48:34 UTC
Permalink
Oh, found the new convapi.h and converr.h - see below.

Peter Jamieson

convapi.h
------------------------------------
/*--------------------------------------------------------------------------
%%File: CONVAPI.H
%%Unit: CORE
%%Contact: ***@microsoft.com

This header is distributed as part of the 32-bit Conversions SDK.

Changes to this header file should be sent to ***@microsoft.com

Revision History: (Current=1.031)

3/14/97 tidy up and remove references to derived types
3/16/97 MacPPC callback prototype fix
4/21/97 explicit packing, MacPPC prototype fixes, C++ friendliness
6/24/97 CchFetchLpszError for MacPPC, some formal parameter names tidied
1/17/03 constness in InitConverter32 prototype
2/27/03 RegAppOpcodeReturnHtml through RegAppOpcodeSuppressSecurityPrompt
------------------------------------------------------------------------*/

#ifndef CONVAPI_H
#define CONVAPI_H

#ifdef __cplusplus
extern "C" {
#endif

#ifdef WIN16
#include "crmgr.h" // for PFN_CRMGR
#endif

#include "converr.h"


// Rtf to foreign Percent ConVersion compleTe
#pragma pack(2)
typedef struct _PCVT
{
short cbpcvt; // size of this structure
short wVersion; // version # for determining size of struct
short wPctWord; // current %-complete according to application
short wPctConvtr; // current %-complete according to the converter
} PCVT;
#pragma pack()


// Rtf to Foreign User OPTions
#pragma pack(2)
typedef struct _RFUOPT
{
union
{
short rgf;
struct
{
short fPicture : 1; // converter wants pictures (binary implied)
short fLayoutInfo : 1; // converter wants (slow) layout info
short fPctComplete : 1; // converter will provide percent complete
short : 13;
};
};
} RFUOPT;
#pragma pack()

// Rtf to foreign user options, again
#define fOptPicture 0x0001
#define fOptLayoutInfo 0x0002
#define fOptPctComplete 0x0004



// RegisterApp input flags
#pragma pack(2)
typedef struct _LFREGAPP
{
union
{
struct
{
unsigned long fAcceptPctComp : 1;
unsigned long fNoBinary : 1;
unsigned long fPreview : 1;
unsigned long fDontNeedOemConvert : 1;
unsigned long fIndexing : 1;
unsigned long unused : 27;
};
unsigned long lfRegApp;
};
} LFREGAPP;
#pragma pack()

// RegisterApp input flags, again
#define fRegAppPctComp 0x00000001 // app is prepared to accept percent
complete numbers in export
#define fRegAppNoBinary 0x00000002 // app is not prepared to accept
binary-encoded picture and other data
#define fRegAppPreview 0x00000004 // converter should display no message
boxes or dialogs
#define fRegAppSupportNonOem 0x00000008 // app is prepared to provide
non-OEM character set filenames
#define fRegAppIndexing 0x00000010 // converter can omit non-content Rtf


// REGister APP structure (received from client)
#pragma pack(1)
typedef struct _REGAPP {
short cbStruct; // size of this structure
char rgbOpcodeData[];
} REGAPP;
#pragma pack()

// REGAPP byte opcodes
#define RegAppOpcodeFilename 0x80 // true final filename of exported file
#define RegAppOpcodeInterimPath 0x81 // path being exported to is not the
final location


// REGister APP RETurn structure (passed to client)
#pragma pack(1)
typedef struct _REGAPPRET
{
short cbStruct; // size of this structure

// Does this converter understand docfiles and/or non-docfiles?
char cbSizefDocfile;
char opcodefDocfile;
union
{
struct
{
short fDocfile : 1;
short fNonDocfile : 1;
short : 14;
};
short grfType;
};

// Version of Word for which converter's Rtf is compliant
char cbSizeVer; // ==
sizeof(char)+sizeof(char)+sizeof(short)+sizeof(short)
char opcodeVer;
short verMajor; // Major version of Word for which Rtf is compliant
short verMinor; // Minor version of Word for which Rtf is compliant

#if defined(WIN16) || defined(WIN32)
// What character set do we want all filenames to be in.
char cbSizeCharset;
char opcodeCharset;
char charset;
#endif

char cbSizeSecurityPrompt;
char opcodeSecurityPrompt;

char opcodesOptional[]; // optional additional stuff
} REGAPPRET;
#pragma pack()

// REGAPPRET byte opcodes
#define RegAppOpcodeVer 0x01 // Rtf version converter is prepared to
accept
#define RegAppOpcodeDocfile 0x02 // converter's ability to handle regular
and docfiles
#define RegAppOpcodeCharset 0x03 // converter is prepared to handle
filenames in this character set
#define RegAppOpcodeReloadOnSave 0x04 // app should reload document after
exporting
#define RegAppOpcodePicPlacehold 0x05 // app should send placeholder
pictures (with size info) for includepicture \d fields
#define RegAppOpcodeFavourUnicode 0x06 // app should output Unicode RTF
whenever possible, especially for DBCS; \uc0 is good
#define RegAppOpcodeNoClassifyChars 0x07 // app should not break text runs
by character set clasification
#define RegAppOpcodeReturnHtml 0x08 // we will return HTML instead of RTF
(no converter does this currently)
#define RegAppOpcodeRtfCodepage 0x09 // app should give us RTF in the
specified codepage
#define RegAppOpcode7BitRtf 0x0a // app should give us 7bit RTF
#define RegAppOpcodeSuppressSecurityPrompt 0x0b // app can suppress the
security warning prompt



// Principal converter entrypoints
#ifdef WIN16

// callback type
typedef PFN_CRMGR PFN_RTF;

HANDLE PASCAL InitConverter(HANDLE hStack, HANDLE hwnd);
void PASCAL GetClassNames(HANDLE ghszClassNames);
void PASCAL GetIniEntry(HANDLE ghIniName, HANDLE ghIniExt);
HGLOBAL PASCAL RegisterApp(unsigned long lFlags, void FAR *lpFuture);
FCE PASCAL IsFormatCorrect(HANDLE ghszFile, HANDLE ghszDescrip);
FCE PASCAL ForeignToRtf(HANDLE ghszFile, HANDLE ghBuff, HANDLE ghszDescrip,
HANDLE ghszSubset, PFN_RTF lpfnOut);
FCE PASCAL RtfToForeign(HANDLE ghszFile, HANDLE ghBuff, HANDLE ghszDescrip,
PFN_RTF lpfnIn);

#elif defined(WIN32)

// callback type
typedef long (PASCAL *PFN_RTF)();

long PASCAL InitConverter32(HANDLE hwndApp, const char *szModule);
void PASCAL UninitConverter(void);
void PASCAL GetReadNames(HANDLE hszClass, HANDLE hszDescrip, HANDLE hszExt);
void PASCAL GetWriteNames(HANDLE hszClass, HANDLE hszDescrip, HANDLE
hszExt);
HGLOBAL PASCAL RegisterApp(unsigned long lFlags, void *lpRegApp);
FCE PASCAL IsFormatCorrect32(HANDLE hszFile, HANDLE hszClass);
FCE PASCAL ForeignToRtf32(HANDLE hszFile, void *pstgForeign, HANDLE hBuf,
HANDLE hszClass, HANDLE hszSubset, PFN_RTF lpfnOut);
FCE PASCAL RtfToForeign32(HANDLE hszFile, void *pstgForeign, HANDLE hBuf,
HANDLE hszClass, PFN_RTF lpfnIn);
long PASCAL CchFetchLpszError(long fce, char *lpszError, long cb);
long PASCAL FRegisterConverter(HANDLE hkeyRoot);

#elif defined(MAC)

typedef struct _GFIB // Graphics File Information Block.
{
short fh; // File handle to the open file.
long fcSrc; // FC where the WPG Data will reside.
long lcbSrc; // Count of bytes for WPG Data.
} GFIB;

typedef struct _PINFO
{
Rect box; // Dimensions of the binding rectangle for the picture.
short inch; // Units/Inch in which these dimensions are given.
} PINFO;
typedef PINFO **HPINFO;

// grfs for wOleFlags
#define grfOleDocFile 0x0100
#define grfOleNonDocFile 0x0200
#define grfOleInited 0x0001

#ifdef MAC68K
// function type of Rtf callback function
typedef short (PASCAL * PFNRTFXFER)(short, unsigned short);

typedef struct _FIC
{
short icr; /* Index to the converter routine */
union
{
char **hstFileName; /* File Name */
long **hrgTyp; /* Types of files known to this converter */
GFIB **hgfib; /* Graphics File Info Block */
void *lpFuture; // for RegisterApp()
} hun;
short vRefNum; /* vRefNum for the file */
short refNum; /* Path for file */
union
{
long ftg;
unsigned long lFlags; /* for RegisterApp */
};
char **hszDescrip; /* Description of file */
PFNRTFXFER pfn; /* Pointer into Word of function to
call for more RTF or to convert RTF */
union
{
Handle hBuffer; /* Buffer through which RTF will be
passed. */
Handle hRegAppRet; /* handle to return RegAppRet structure,
NULL if couldn't be allocated */
};
short wReturn; /* Code returned by converter */

// Following are new to Mac Word 6.0
short wVersion;
Handle hszClass;
Handle hszSubset;
HPINFO hpinfo; /* Handle to PINFO Struct for Graphics */
union
{
struct
{
char fDocFile : 1;
char fNonDocFile : 1;
char : 6;
char fOleInited : 1;
char : 7;
};
short wOleFlags;
};
} FIC;

typedef FIC *PFIC;
typedef PFIC *HFIC;
#define cbFIC sizeof(FIC)
#define cbFIC5 offsetof(FIC, wVersion) /* size of a Word 5 FIC */

/* Constants for Switch routine */
#define icrInitConverter 0
#define icrIsFormatCorrect 1
#define icrGetReadTypes 2
#define icrGetWriteTypes 3
#define icrForeignToRtf 4
#define icrRtfToForeign 5
#define icrRegisterApp 6
#define icrConverterForeignToRTF 7

void _pascal CodeResourceEntry(long *plUsr, FIC **hfic);
#endif

#ifdef MACPPC
// function type of Rtf callback function
typedef short (* PFNRTFXFER)(short, unsigned short);

long InitConverter(long *plw);
void UninitConverter(void);
Handle RegisterApp(unsigned long lFlags, void *lpRegApp);
void GetReadNames(Handle hszClass, Handle hszDescrip, Handle hrgTyp);
void GetWriteNames(Handle hszClass, Handle hszDescrip, Handle hrgTyp);
FCE IsFormatCorrect(FSSpecPtr pfsFile, Handle hszClass);
FCE ForeignToRtf(FSSpecPtr pfsFile, void *pstgForeign, Handle hBuf, Handle
hszClass, Handle hszSubset, PFNRTFXFER lpfnOut);
FCE RtfToForeign(FSSpecPtr pfsFile, void *pstgForeign, Handle hBuf, Handle
hszClass, PFNRTFXFER lpfnIn);
long CchFetchLpszError(long fce, char *lpszError, long cb);
#endif

#else
#error Unknown platform.
#endif

#ifdef __cplusplus
}
#endif

#endif // CONVAPI_H
------------------------------------

converr.h
------------------------------------
%%File: CONVERR.H
%%Unit: CORE
%%Contact: smueller

Conversions error return values.
------------------------------------------------------------------------*/

#ifndef CONVERR_H
#define CONVERR_H


typedef short FCE;

// File Conversion Errors
#define fceNoErr 0 // success

#define fceOpenInFileErr (-1) // could not open input file
#define fceReadErr (-2) // error during read
#define fceOpenConvErr (-3) // error opening conversion file
#define fceWriteErr (-4) // error during write
#define fceInvalidFile (-5) // invalid data in conversion file
#define fceOpenExceptErr (-6) // error opening exception file
#define fceWriteExceptErr (-7) // error writing exception file
#define fceNoMemory (-8) // out of memory
#define fceInvalidDoc (-9) // invalid document
#define fceDiskFull (-10) // out of space on output
#define fceDocTooLarge (-11) // conversion document too large for target
#define fceOpenOutFileErr (-12) // could not open output file
#define fceUserCancel (-13) // conversion cancelled by user
#define fceWrongFileType (-14) // wrong file type for this converter


#if defined(WIN32) || defined(MACPPC)
// These errors are obsolete. Map all usages to smaller, current set.
#undef fceOpenConvErr
#define fceOpenConvErr fceOpenInFileErr
#undef fceOpenExceptErr
#define fceOpenExceptErr fceOpenInFileErr
#undef fceWriteExceptErr
#define fceWriteExceptErr fceWriteErr
#undef fceInvalidDoc
#define fceInvalidDoc fceInvalidFile
#undef fceDiskFull
#define fceDiskFull fceWriteErr
#undef fceDocTooLarge
#define fceDocTooLarge fceWriteErr
#endif


#endif // CONVERR_H
------------------------------------
Post by Peter Jamieson
For problem 1, there is an additional option in the converter API - MS
sent me the following info back in 2003, but I don't think they ever got
MS were particularly keen that you don't let the calling app suppress the
prompt if there is a possibility of a buffer overflow.
I think there was a bit more but this is the only part that I have to hand.
I can't answer problem 2 but maybe fixing problem 1 will have an impact on
that.
I'll be offline for a few days.
Peter Jamieson
-------------------------------------------------------------------
Here are the details for the new RegisterApp opcode. The implementation is
simple in theory; the actual difficulty will depend on how they have
implemented their RegisterApp function.
First, some background on RegisterApp. This converter API has been around
for along time - it allows a variable number of "opcodes" to be sent from
the calling application to the converter, and another variable set of
"opcodes" to be returned from the converter to the calling application.
To
date, this has been used for things like filename character sets (to shed
the old OEM charset dependency), unicode RTF, etc.
The new Security opcode is just another opcode that the converter can return
to the application. It requests that the application suppress the new
Security Warning.
Here are the changes that I made to our core converters to support this
(highlighted lines were added; the other lines are included for context)
// REGAPPRET byte opcodes
#define RegAppOpcodeVer 0x01 // Rtf version converter is
prepared to accept
#define RegAppOpcodeDocfile 0x02 // converter's ability to
handle regular and docfiles
#define RegAppOpcodeCharset 0x03 // converter is prepared to
handle filenames in this character set
#define RegAppOpcodeReloadOnSave 0x04 // app should reload
document after exporting
#define RegAppOpcodePicPlacehold 0x05 // app should send
placeholder pictures (with size info) for includepicture \d fields
#define RegAppOpcodeFavourUnicode 0x06 // app should output Unicode
RTF whenever possible, especially for DBCS; \uc0 is good
#define RegAppOpcodeNoClassifyChars 0x07 // app should not break text
runs by character set clasification
#define RegAppOpcodeReturnHtml 0x08 // Converter will return
HTML instead of RTF
#define RegAppOpcodeRtfCodepage 0x09 // app sould return RTF in
the specified codepage
#define RegAppOpcode7BitRtf 0x0a // app should return 7bit
rtf
#define RegAppOpcodeSuppressSecurityPrompt 0x0b // app can suppress
the security prompt -- this converter has been security reviewed
#pragma pack(1)
typedef struct _REGAPPRET // we always return these RegApp flags, so we
just put this in a structure.
{
short cbStruct; // size of this structure
// Does this converter understand docfiles and/or non-docfiles?
char cbSizefDocfile;
char opcodefDocfile;
union
{
struct
{
short fDocfile : 1;
short fNonDocfile : 1;
short : 14;
};
short grfType;
};
// Version of Word for which converter's Rtf is compliant
char cbSizeVer; //
==sizeof(char)+sizeof(char)+sizeof(short)+sizeof(short)
char opcodeVer;
short verMajor; // Major version of Word for which Rtf is
compliant
short verMinor; // Minor version of Word for which Rtf is
compliant
// What character set do we want all filenames to be in.
char cbSizeCharset;
char opcodeCharset;
char charset;
char opcodesOptional[]; // optional additional stuff
} REGAPPRET;
#pragma pack()
// Allocate return structure (allocation the largest possible block)
< if ((hRegAppRet = GlobalAlloc(GMEM_MOVEABLE, sizeof(REGAPPRET) + 10)) ==
NULL)
if ((hRegAppRet = GlobalAlloc(GMEM_MOVEABLE, sizeof(REGAPPRET) + 12)) ==
NULL)
return (HGLOBAL)0;
pbOpcodesOptional = lpRegAppRet->opcodesOptional;
*pbOpcodesOptional++ = 2; // cb of 0
*pbOpcodesOptional++ = RegAppOpcodeSuppressSecurityPrompt;
lpRegAppRet->cbStruct = (short)((ULONG_PTR)(pbOpcodesOptional) -
(ULONG_PTR)(lpRegAppRet));
GlobalUnlock(hRegAppRet);
return hRegAppRet;
-------------------------------------------------------------------
Hi,
hope anyone can help me.
I wrote a Text Converter. It works fine with Word XP and 2000, but in
1. Word 2003 shows a security warning when using my converter. Is there a
possibility to avoid this warning.
2. When I use Word's SaveAs with Filename and SaveFormat for my
converter, it seems that the SaveFormat is not correct and Word displays
the SaveAs Dialog. I took the SaveFormat from the FileConverters
Collection!
Stefan
Stefan Wanger
2006-04-05 15:33:12 UTC
Permalink
Added the new Headers and set:

lpRegAppRet->cbSizeSecurityPrompt = sizeof(CHAR)+sizeof(CHAR);
lpRegAppRet->opcodeSecurityPrompt = RegAppOpcodeSuppressSecurityPrompt;

But no effect.
i do not have optional opcodes. so i think allocating the structure like
this should be OK:

if ((hRegAppRet = GlobalAlloc(GMEM_MOVEABLE, sizeof(REGAPPRET))) == NULL)
return (HGLOBAL)0;

lpRegAppRet = (REGAPPRET FAR *)GlobalLock(hRegAppRet);
Assert(lpRegAppRet != NULL);

lpRegAppRet->cbStruct = sizeof(REGAPPRET);



Thanks

Stefan
Post by Peter Jamieson
Oh, found the new convapi.h and converr.h - see below.
Peter Jamieson
convapi.h
------------------------------------
/*--------------------------------------------------------------------------
%%File: CONVAPI.H
%%Unit: CORE
This header is distributed as part of the 32-bit Conversions SDK.
Revision History: (Current=1.031)
3/14/97 tidy up and remove references to derived types
3/16/97 MacPPC callback prototype fix
4/21/97 explicit packing, MacPPC prototype fixes, C++ friendliness
6/24/97 CchFetchLpszError for MacPPC, some formal parameter names tidied
1/17/03 constness in InitConverter32 prototype
2/27/03 RegAppOpcodeReturnHtml through RegAppOpcodeSuppressSecurityPrompt
------------------------------------------------------------------------*/
#ifndef CONVAPI_H
#define CONVAPI_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WIN16
#include "crmgr.h" // for PFN_CRMGR
#endif
#include "converr.h"
// Rtf to foreign Percent ConVersion compleTe
#pragma pack(2)
typedef struct _PCVT
{
short cbpcvt; // size of this structure
short wVersion; // version # for determining size of struct
short wPctWord; // current %-complete according to application
short wPctConvtr; // current %-complete according to the converter
} PCVT;
#pragma pack()
// Rtf to Foreign User OPTions
#pragma pack(2)
typedef struct _RFUOPT
{
union
{
short rgf;
struct
{
short fPicture : 1; // converter wants pictures (binary implied)
short fLayoutInfo : 1; // converter wants (slow) layout info
short fPctComplete : 1; // converter will provide percent complete
short : 13;
};
};
} RFUOPT;
#pragma pack()
// Rtf to foreign user options, again
#define fOptPicture 0x0001
#define fOptLayoutInfo 0x0002
#define fOptPctComplete 0x0004
// RegisterApp input flags
#pragma pack(2)
typedef struct _LFREGAPP
{
union
{
struct
{
unsigned long fAcceptPctComp : 1;
unsigned long fNoBinary : 1;
unsigned long fPreview : 1;
unsigned long fDontNeedOemConvert : 1;
unsigned long fIndexing : 1;
unsigned long unused : 27;
};
unsigned long lfRegApp;
};
} LFREGAPP;
#pragma pack()
// RegisterApp input flags, again
#define fRegAppPctComp 0x00000001 // app is prepared to accept percent
complete numbers in export
#define fRegAppNoBinary 0x00000002 // app is not prepared to accept
binary-encoded picture and other data
#define fRegAppPreview 0x00000004 // converter should display no message
boxes or dialogs
#define fRegAppSupportNonOem 0x00000008 // app is prepared to provide
non-OEM character set filenames
#define fRegAppIndexing 0x00000010 // converter can omit non-content Rtf
// REGister APP structure (received from client)
#pragma pack(1)
typedef struct _REGAPP {
short cbStruct; // size of this structure
char rgbOpcodeData[];
} REGAPP;
#pragma pack()
// REGAPP byte opcodes
#define RegAppOpcodeFilename 0x80 // true final filename of exported file
#define RegAppOpcodeInterimPath 0x81 // path being exported to is not the
final location
// REGister APP RETurn structure (passed to client)
#pragma pack(1)
typedef struct _REGAPPRET
{
short cbStruct; // size of this structure
// Does this converter understand docfiles and/or non-docfiles?
char cbSizefDocfile;
char opcodefDocfile;
union
{
struct
{
short fDocfile : 1;
short fNonDocfile : 1;
short : 14;
};
short grfType;
};
// Version of Word for which converter's Rtf is compliant
char cbSizeVer; // ==
sizeof(char)+sizeof(char)+sizeof(short)+sizeof(short)
char opcodeVer;
short verMajor; // Major version of Word for which Rtf is compliant
short verMinor; // Minor version of Word for which Rtf is compliant
#if defined(WIN16) || defined(WIN32)
// What character set do we want all filenames to be in.
char cbSizeCharset;
char opcodeCharset;
char charset;
#endif
char cbSizeSecurityPrompt;
char opcodeSecurityPrompt;
char opcodesOptional[]; // optional additional stuff
} REGAPPRET;
#pragma pack()
// REGAPPRET byte opcodes
#define RegAppOpcodeVer 0x01 // Rtf version converter is prepared to
accept
#define RegAppOpcodeDocfile 0x02 // converter's ability to handle
regular and docfiles
#define RegAppOpcodeCharset 0x03 // converter is prepared to handle
filenames in this character set
#define RegAppOpcodeReloadOnSave 0x04 // app should reload document after
exporting
#define RegAppOpcodePicPlacehold 0x05 // app should send placeholder
pictures (with size info) for includepicture \d fields
#define RegAppOpcodeFavourUnicode 0x06 // app should output Unicode RTF
whenever possible, especially for DBCS; \uc0 is good
#define RegAppOpcodeNoClassifyChars 0x07 // app should not break text runs
by character set clasification
#define RegAppOpcodeReturnHtml 0x08 // we will return HTML instead of RTF
(no converter does this currently)
#define RegAppOpcodeRtfCodepage 0x09 // app should give us RTF in the
specified codepage
#define RegAppOpcode7BitRtf 0x0a // app should give us 7bit RTF
#define RegAppOpcodeSuppressSecurityPrompt 0x0b // app can suppress the
security warning prompt
// Principal converter entrypoints
#ifdef WIN16
// callback type
typedef PFN_CRMGR PFN_RTF;
HANDLE PASCAL InitConverter(HANDLE hStack, HANDLE hwnd);
void PASCAL GetClassNames(HANDLE ghszClassNames);
void PASCAL GetIniEntry(HANDLE ghIniName, HANDLE ghIniExt);
HGLOBAL PASCAL RegisterApp(unsigned long lFlags, void FAR *lpFuture);
FCE PASCAL IsFormatCorrect(HANDLE ghszFile, HANDLE ghszDescrip);
FCE PASCAL ForeignToRtf(HANDLE ghszFile, HANDLE ghBuff, HANDLE
ghszDescrip, HANDLE ghszSubset, PFN_RTF lpfnOut);
FCE PASCAL RtfToForeign(HANDLE ghszFile, HANDLE ghBuff, HANDLE
ghszDescrip, PFN_RTF lpfnIn);
#elif defined(WIN32)
// callback type
typedef long (PASCAL *PFN_RTF)();
long PASCAL InitConverter32(HANDLE hwndApp, const char *szModule);
void PASCAL UninitConverter(void);
void PASCAL GetReadNames(HANDLE hszClass, HANDLE hszDescrip, HANDLE hszExt);
void PASCAL GetWriteNames(HANDLE hszClass, HANDLE hszDescrip, HANDLE
hszExt);
HGLOBAL PASCAL RegisterApp(unsigned long lFlags, void *lpRegApp);
FCE PASCAL IsFormatCorrect32(HANDLE hszFile, HANDLE hszClass);
FCE PASCAL ForeignToRtf32(HANDLE hszFile, void *pstgForeign, HANDLE hBuf,
HANDLE hszClass, HANDLE hszSubset, PFN_RTF lpfnOut);
FCE PASCAL RtfToForeign32(HANDLE hszFile, void *pstgForeign, HANDLE hBuf,
HANDLE hszClass, PFN_RTF lpfnIn);
long PASCAL CchFetchLpszError(long fce, char *lpszError, long cb);
long PASCAL FRegisterConverter(HANDLE hkeyRoot);
#elif defined(MAC)
typedef struct _GFIB // Graphics File Information Block.
{
short fh; // File handle to the open file.
long fcSrc; // FC where the WPG Data will reside.
long lcbSrc; // Count of bytes for WPG Data.
} GFIB;
typedef struct _PINFO
{
Rect box; // Dimensions of the binding rectangle for the picture.
short inch; // Units/Inch in which these dimensions are given.
} PINFO;
typedef PINFO **HPINFO;
// grfs for wOleFlags
#define grfOleDocFile 0x0100
#define grfOleNonDocFile 0x0200
#define grfOleInited 0x0001
#ifdef MAC68K
// function type of Rtf callback function
typedef short (PASCAL * PFNRTFXFER)(short, unsigned short);
typedef struct _FIC
{
short icr; /* Index to the converter routine */
union
{
char **hstFileName; /* File Name */
long **hrgTyp; /* Types of files known to this converter */
GFIB **hgfib; /* Graphics File Info Block */
void *lpFuture; // for RegisterApp()
} hun;
short vRefNum; /* vRefNum for the file */
short refNum; /* Path for file */
union
{
long ftg;
unsigned long lFlags; /* for RegisterApp */
};
char **hszDescrip; /* Description of file */
PFNRTFXFER pfn; /* Pointer into Word of function to
call for more RTF or to convert RTF */
union
{
Handle hBuffer; /* Buffer through which RTF will be
passed. */
Handle hRegAppRet; /* handle to return RegAppRet structure,
NULL if couldn't be allocated */
};
short wReturn; /* Code returned by converter */
// Following are new to Mac Word 6.0
short wVersion;
Handle hszClass;
Handle hszSubset;
HPINFO hpinfo; /* Handle to PINFO Struct for Graphics */
union
{
struct
{
char fDocFile : 1;
char fNonDocFile : 1;
char : 6;
char fOleInited : 1;
char : 7;
};
short wOleFlags;
};
} FIC;
typedef FIC *PFIC;
typedef PFIC *HFIC;
#define cbFIC sizeof(FIC)
#define cbFIC5 offsetof(FIC, wVersion) /* size of a Word 5 FIC */
/* Constants for Switch routine */
#define icrInitConverter 0
#define icrIsFormatCorrect 1
#define icrGetReadTypes 2
#define icrGetWriteTypes 3
#define icrForeignToRtf 4
#define icrRtfToForeign 5
#define icrRegisterApp 6
#define icrConverterForeignToRTF 7
void _pascal CodeResourceEntry(long *plUsr, FIC **hfic);
#endif
#ifdef MACPPC
// function type of Rtf callback function
typedef short (* PFNRTFXFER)(short, unsigned short);
long InitConverter(long *plw);
void UninitConverter(void);
Handle RegisterApp(unsigned long lFlags, void *lpRegApp);
void GetReadNames(Handle hszClass, Handle hszDescrip, Handle hrgTyp);
void GetWriteNames(Handle hszClass, Handle hszDescrip, Handle hrgTyp);
FCE IsFormatCorrect(FSSpecPtr pfsFile, Handle hszClass);
FCE ForeignToRtf(FSSpecPtr pfsFile, void *pstgForeign, Handle hBuf, Handle
hszClass, Handle hszSubset, PFNRTFXFER lpfnOut);
FCE RtfToForeign(FSSpecPtr pfsFile, void *pstgForeign, Handle hBuf, Handle
hszClass, PFNRTFXFER lpfnIn);
long CchFetchLpszError(long fce, char *lpszError, long cb);
#endif
#else
#error Unknown platform.
#endif
#ifdef __cplusplus
}
#endif
#endif // CONVAPI_H
------------------------------------
converr.h
------------------------------------
%%File: CONVERR.H
%%Unit: CORE
%%Contact: smueller
Conversions error return values.
------------------------------------------------------------------------*/
#ifndef CONVERR_H
#define CONVERR_H
typedef short FCE;
// File Conversion Errors
#define fceNoErr 0 // success
#define fceOpenInFileErr (-1) // could not open input file
#define fceReadErr (-2) // error during read
#define fceOpenConvErr (-3) // error opening conversion file
#define fceWriteErr (-4) // error during write
#define fceInvalidFile (-5) // invalid data in conversion file
#define fceOpenExceptErr (-6) // error opening exception file
#define fceWriteExceptErr (-7) // error writing exception file
#define fceNoMemory (-8) // out of memory
#define fceInvalidDoc (-9) // invalid document
#define fceDiskFull (-10) // out of space on output
#define fceDocTooLarge (-11) // conversion document too large for target
#define fceOpenOutFileErr (-12) // could not open output file
#define fceUserCancel (-13) // conversion cancelled by user
#define fceWrongFileType (-14) // wrong file type for this converter
#if defined(WIN32) || defined(MACPPC)
// These errors are obsolete. Map all usages to smaller, current set.
#undef fceOpenConvErr
#define fceOpenConvErr fceOpenInFileErr
#undef fceOpenExceptErr
#define fceOpenExceptErr fceOpenInFileErr
#undef fceWriteExceptErr
#define fceWriteExceptErr fceWriteErr
#undef fceInvalidDoc
#define fceInvalidDoc fceInvalidFile
#undef fceDiskFull
#define fceDiskFull fceWriteErr
#undef fceDocTooLarge
#define fceDocTooLarge fceWriteErr
#endif
#endif // CONVERR_H
------------------------------------
Post by Peter Jamieson
For problem 1, there is an additional option in the converter API - MS
sent me the following info back in 2003, but I don't think they ever got
MS were particularly keen that you don't let the calling app suppress the
prompt if there is a possibility of a buffer overflow.
I think there was a bit more but this is the only part that I have to hand.
I can't answer problem 2 but maybe fixing problem 1 will have an impact
on that.
I'll be offline for a few days.
Peter Jamieson
-------------------------------------------------------------------
Here are the details for the new RegisterApp opcode. The implementation is
simple in theory; the actual difficulty will depend on how they have
implemented their RegisterApp function.
First, some background on RegisterApp. This converter API has been around
for along time - it allows a variable number of "opcodes" to be sent from
the calling application to the converter, and another variable set of
"opcodes" to be returned from the converter to the calling application.
To
date, this has been used for things like filename character sets (to shed
the old OEM charset dependency), unicode RTF, etc.
The new Security opcode is just another opcode that the converter can return
to the application. It requests that the application suppress the new
Security Warning.
Here are the changes that I made to our core converters to support this
(highlighted lines were added; the other lines are included for context)
// REGAPPRET byte opcodes
#define RegAppOpcodeVer 0x01 // Rtf version converter is
prepared to accept
#define RegAppOpcodeDocfile 0x02 // converter's ability to
handle regular and docfiles
#define RegAppOpcodeCharset 0x03 // converter is prepared to
handle filenames in this character set
#define RegAppOpcodeReloadOnSave 0x04 // app should reload
document after exporting
#define RegAppOpcodePicPlacehold 0x05 // app should send
placeholder pictures (with size info) for includepicture \d fields
#define RegAppOpcodeFavourUnicode 0x06 // app should output Unicode
RTF whenever possible, especially for DBCS; \uc0 is good
#define RegAppOpcodeNoClassifyChars 0x07 // app should not break text
runs by character set clasification
#define RegAppOpcodeReturnHtml 0x08 // Converter will return
HTML instead of RTF
#define RegAppOpcodeRtfCodepage 0x09 // app sould return RTF in
the specified codepage
#define RegAppOpcode7BitRtf 0x0a // app should return 7bit
rtf
#define RegAppOpcodeSuppressSecurityPrompt 0x0b // app can suppress
the security prompt -- this converter has been security reviewed
#pragma pack(1)
typedef struct _REGAPPRET // we always return these RegApp flags, so we
just put this in a structure.
{
short cbStruct; // size of this structure
// Does this converter understand docfiles and/or non-docfiles?
char cbSizefDocfile;
char opcodefDocfile;
union
{
struct
{
short fDocfile : 1;
short fNonDocfile : 1;
short : 14;
};
short grfType;
};
// Version of Word for which converter's Rtf is compliant
char cbSizeVer; //
==sizeof(char)+sizeof(char)+sizeof(short)+sizeof(short)
char opcodeVer;
short verMajor; // Major version of Word for which Rtf is
compliant
short verMinor; // Minor version of Word for which Rtf is
compliant
// What character set do we want all filenames to be in.
char cbSizeCharset;
char opcodeCharset;
char charset;
char opcodesOptional[]; // optional additional stuff
} REGAPPRET;
#pragma pack()
// Allocate return structure (allocation the largest possible block)
< if ((hRegAppRet = GlobalAlloc(GMEM_MOVEABLE, sizeof(REGAPPRET) + 10)) ==
NULL)
if ((hRegAppRet = GlobalAlloc(GMEM_MOVEABLE, sizeof(REGAPPRET) + 12)) ==
NULL)
return (HGLOBAL)0;
pbOpcodesOptional = lpRegAppRet->opcodesOptional;
*pbOpcodesOptional++ = 2; // cb of 0
*pbOpcodesOptional++ = RegAppOpcodeSuppressSecurityPrompt;
lpRegAppRet->cbStruct = (short)((ULONG_PTR)(pbOpcodesOptional) -
(ULONG_PTR)(lpRegAppRet));
GlobalUnlock(hRegAppRet);
return hRegAppRet;
-------------------------------------------------------------------
Hi,
hope anyone can help me.
I wrote a Text Converter. It works fine with Word XP and 2000, but in
1. Word 2003 shows a security warning when using my converter. Is there
a possibility to avoid this warning.
2. When I use Word's SaveAs with Filename and SaveFormat for my
converter, it seems that the SaveFormat is not correct and Word displays
the SaveAs Dialog. I took the SaveFormat from the FileConverters
Collection!
Stefan
Stefan Wanger
2006-04-05 16:02:44 UTC
Permalink
Sorry,

found the error. I had put the code in the wrong place.

Everything works fine.
You're great.

Even 2) is solved. when registering the converter under SharedTools

Thanks

Stefan
Post by Stefan Wanger
lpRegAppRet->cbSizeSecurityPrompt = sizeof(CHAR)+sizeof(CHAR);
lpRegAppRet->opcodeSecurityPrompt = RegAppOpcodeSuppressSecurityPrompt;
But no effect.
i do not have optional opcodes. so i think allocating the structure like
if ((hRegAppRet = GlobalAlloc(GMEM_MOVEABLE, sizeof(REGAPPRET))) == NULL)
return (HGLOBAL)0;
lpRegAppRet = (REGAPPRET FAR *)GlobalLock(hRegAppRet);
Assert(lpRegAppRet != NULL);
lpRegAppRet->cbStruct = sizeof(REGAPPRET);
Thanks
Stefan
Post by Peter Jamieson
Oh, found the new convapi.h and converr.h - see below.
Peter Jamieson
convapi.h
------------------------------------
/*--------------------------------------------------------------------------
%%File: CONVAPI.H
%%Unit: CORE
This header is distributed as part of the 32-bit Conversions SDK.
Revision History: (Current=1.031)
3/14/97 tidy up and remove references to derived types
3/16/97 MacPPC callback prototype fix
4/21/97 explicit packing, MacPPC prototype fixes, C++ friendliness
6/24/97 CchFetchLpszError for MacPPC, some formal parameter names tidied
1/17/03 constness in InitConverter32 prototype
2/27/03 RegAppOpcodeReturnHtml through RegAppOpcodeSuppressSecurityPrompt
------------------------------------------------------------------------*/
#ifndef CONVAPI_H
#define CONVAPI_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WIN16
#include "crmgr.h" // for PFN_CRMGR
#endif
#include "converr.h"
// Rtf to foreign Percent ConVersion compleTe
#pragma pack(2)
typedef struct _PCVT
{
short cbpcvt; // size of this structure
short wVersion; // version # for determining size of struct
short wPctWord; // current %-complete according to application
short wPctConvtr; // current %-complete according to the converter
} PCVT;
#pragma pack()
// Rtf to Foreign User OPTions
#pragma pack(2)
typedef struct _RFUOPT
{
union
{
short rgf;
struct
{
short fPicture : 1; // converter wants pictures (binary implied)
short fLayoutInfo : 1; // converter wants (slow) layout info
short fPctComplete : 1; // converter will provide percent complete
short : 13;
};
};
} RFUOPT;
#pragma pack()
// Rtf to foreign user options, again
#define fOptPicture 0x0001
#define fOptLayoutInfo 0x0002
#define fOptPctComplete 0x0004
// RegisterApp input flags
#pragma pack(2)
typedef struct _LFREGAPP
{
union
{
struct
{
unsigned long fAcceptPctComp : 1;
unsigned long fNoBinary : 1;
unsigned long fPreview : 1;
unsigned long fDontNeedOemConvert : 1;
unsigned long fIndexing : 1;
unsigned long unused : 27;
};
unsigned long lfRegApp;
};
} LFREGAPP;
#pragma pack()
// RegisterApp input flags, again
#define fRegAppPctComp 0x00000001 // app is prepared to accept percent
complete numbers in export
#define fRegAppNoBinary 0x00000002 // app is not prepared to accept
binary-encoded picture and other data
#define fRegAppPreview 0x00000004 // converter should display no
message boxes or dialogs
#define fRegAppSupportNonOem 0x00000008 // app is prepared to provide
non-OEM character set filenames
#define fRegAppIndexing 0x00000010 // converter can omit non-content Rtf
// REGister APP structure (received from client)
#pragma pack(1)
typedef struct _REGAPP {
short cbStruct; // size of this structure
char rgbOpcodeData[];
} REGAPP;
#pragma pack()
// REGAPP byte opcodes
#define RegAppOpcodeFilename 0x80 // true final filename of exported file
#define RegAppOpcodeInterimPath 0x81 // path being exported to is not the
final location
// REGister APP RETurn structure (passed to client)
#pragma pack(1)
typedef struct _REGAPPRET
{
short cbStruct; // size of this structure
// Does this converter understand docfiles and/or non-docfiles?
char cbSizefDocfile;
char opcodefDocfile;
union
{
struct
{
short fDocfile : 1;
short fNonDocfile : 1;
short : 14;
};
short grfType;
};
// Version of Word for which converter's Rtf is compliant
char cbSizeVer; // ==
sizeof(char)+sizeof(char)+sizeof(short)+sizeof(short)
char opcodeVer;
short verMajor; // Major version of Word for which Rtf is compliant
short verMinor; // Minor version of Word for which Rtf is compliant
#if defined(WIN16) || defined(WIN32)
// What character set do we want all filenames to be in.
char cbSizeCharset;
char opcodeCharset;
char charset;
#endif
char cbSizeSecurityPrompt;
char opcodeSecurityPrompt;
char opcodesOptional[]; // optional additional stuff
} REGAPPRET;
#pragma pack()
// REGAPPRET byte opcodes
#define RegAppOpcodeVer 0x01 // Rtf version converter is prepared to
accept
#define RegAppOpcodeDocfile 0x02 // converter's ability to handle
regular and docfiles
#define RegAppOpcodeCharset 0x03 // converter is prepared to handle
filenames in this character set
#define RegAppOpcodeReloadOnSave 0x04 // app should reload document after
exporting
#define RegAppOpcodePicPlacehold 0x05 // app should send placeholder
pictures (with size info) for includepicture \d fields
#define RegAppOpcodeFavourUnicode 0x06 // app should output Unicode RTF
whenever possible, especially for DBCS; \uc0 is good
#define RegAppOpcodeNoClassifyChars 0x07 // app should not break text
runs by character set clasification
#define RegAppOpcodeReturnHtml 0x08 // we will return HTML instead of
RTF (no converter does this currently)
#define RegAppOpcodeRtfCodepage 0x09 // app should give us RTF in the
specified codepage
#define RegAppOpcode7BitRtf 0x0a // app should give us 7bit RTF
#define RegAppOpcodeSuppressSecurityPrompt 0x0b // app can suppress the
security warning prompt
// Principal converter entrypoints
#ifdef WIN16
// callback type
typedef PFN_CRMGR PFN_RTF;
HANDLE PASCAL InitConverter(HANDLE hStack, HANDLE hwnd);
void PASCAL GetClassNames(HANDLE ghszClassNames);
void PASCAL GetIniEntry(HANDLE ghIniName, HANDLE ghIniExt);
HGLOBAL PASCAL RegisterApp(unsigned long lFlags, void FAR *lpFuture);
FCE PASCAL IsFormatCorrect(HANDLE ghszFile, HANDLE ghszDescrip);
FCE PASCAL ForeignToRtf(HANDLE ghszFile, HANDLE ghBuff, HANDLE
ghszDescrip, HANDLE ghszSubset, PFN_RTF lpfnOut);
FCE PASCAL RtfToForeign(HANDLE ghszFile, HANDLE ghBuff, HANDLE
ghszDescrip, PFN_RTF lpfnIn);
#elif defined(WIN32)
// callback type
typedef long (PASCAL *PFN_RTF)();
long PASCAL InitConverter32(HANDLE hwndApp, const char *szModule);
void PASCAL UninitConverter(void);
void PASCAL GetReadNames(HANDLE hszClass, HANDLE hszDescrip, HANDLE hszExt);
void PASCAL GetWriteNames(HANDLE hszClass, HANDLE hszDescrip, HANDLE
hszExt);
HGLOBAL PASCAL RegisterApp(unsigned long lFlags, void *lpRegApp);
FCE PASCAL IsFormatCorrect32(HANDLE hszFile, HANDLE hszClass);
FCE PASCAL ForeignToRtf32(HANDLE hszFile, void *pstgForeign, HANDLE
hBuf, HANDLE hszClass, HANDLE hszSubset, PFN_RTF lpfnOut);
FCE PASCAL RtfToForeign32(HANDLE hszFile, void *pstgForeign, HANDLE
hBuf, HANDLE hszClass, PFN_RTF lpfnIn);
long PASCAL CchFetchLpszError(long fce, char *lpszError, long cb);
long PASCAL FRegisterConverter(HANDLE hkeyRoot);
#elif defined(MAC)
typedef struct _GFIB // Graphics File Information Block.
{
short fh; // File handle to the open file.
long fcSrc; // FC where the WPG Data will reside.
long lcbSrc; // Count of bytes for WPG Data.
} GFIB;
typedef struct _PINFO
{
Rect box; // Dimensions of the binding rectangle for the picture.
short inch; // Units/Inch in which these dimensions are given.
} PINFO;
typedef PINFO **HPINFO;
// grfs for wOleFlags
#define grfOleDocFile 0x0100
#define grfOleNonDocFile 0x0200
#define grfOleInited 0x0001
#ifdef MAC68K
// function type of Rtf callback function
typedef short (PASCAL * PFNRTFXFER)(short, unsigned short);
typedef struct _FIC
{
short icr; /* Index to the converter routine */
union
{
char **hstFileName; /* File Name */
long **hrgTyp; /* Types of files known to this converter */
GFIB **hgfib; /* Graphics File Info Block */
void *lpFuture; // for RegisterApp()
} hun;
short vRefNum; /* vRefNum for the file */
short refNum; /* Path for file */
union
{
long ftg;
unsigned long lFlags; /* for RegisterApp */
};
char **hszDescrip; /* Description of file */
PFNRTFXFER pfn; /* Pointer into Word of function to
call for more RTF or to convert RTF */
union
{
Handle hBuffer; /* Buffer through which RTF will be
passed. */
Handle hRegAppRet; /* handle to return RegAppRet structure,
NULL if couldn't be allocated */
};
short wReturn; /* Code returned by converter */
// Following are new to Mac Word 6.0
short wVersion;
Handle hszClass;
Handle hszSubset;
HPINFO hpinfo; /* Handle to PINFO Struct for Graphics */
union
{
struct
{
char fDocFile : 1;
char fNonDocFile : 1;
char : 6;
char fOleInited : 1;
char : 7;
};
short wOleFlags;
};
} FIC;
typedef FIC *PFIC;
typedef PFIC *HFIC;
#define cbFIC sizeof(FIC)
#define cbFIC5 offsetof(FIC, wVersion) /* size of a Word 5 FIC */
/* Constants for Switch routine */
#define icrInitConverter 0
#define icrIsFormatCorrect 1
#define icrGetReadTypes 2
#define icrGetWriteTypes 3
#define icrForeignToRtf 4
#define icrRtfToForeign 5
#define icrRegisterApp 6
#define icrConverterForeignToRTF 7
void _pascal CodeResourceEntry(long *plUsr, FIC **hfic);
#endif
#ifdef MACPPC
// function type of Rtf callback function
typedef short (* PFNRTFXFER)(short, unsigned short);
long InitConverter(long *plw);
void UninitConverter(void);
Handle RegisterApp(unsigned long lFlags, void *lpRegApp);
void GetReadNames(Handle hszClass, Handle hszDescrip, Handle hrgTyp);
void GetWriteNames(Handle hszClass, Handle hszDescrip, Handle hrgTyp);
FCE IsFormatCorrect(FSSpecPtr pfsFile, Handle hszClass);
FCE ForeignToRtf(FSSpecPtr pfsFile, void *pstgForeign, Handle hBuf,
Handle hszClass, Handle hszSubset, PFNRTFXFER lpfnOut);
FCE RtfToForeign(FSSpecPtr pfsFile, void *pstgForeign, Handle hBuf,
Handle hszClass, PFNRTFXFER lpfnIn);
long CchFetchLpszError(long fce, char *lpszError, long cb);
#endif
#else
#error Unknown platform.
#endif
#ifdef __cplusplus
}
#endif
#endif // CONVAPI_H
------------------------------------
converr.h
------------------------------------
%%File: CONVERR.H
%%Unit: CORE
%%Contact: smueller
Conversions error return values.
------------------------------------------------------------------------*/
#ifndef CONVERR_H
#define CONVERR_H
typedef short FCE;
// File Conversion Errors
#define fceNoErr 0 // success
#define fceOpenInFileErr (-1) // could not open input file
#define fceReadErr (-2) // error during read
#define fceOpenConvErr (-3) // error opening conversion file
#define fceWriteErr (-4) // error during write
#define fceInvalidFile (-5) // invalid data in conversion file
#define fceOpenExceptErr (-6) // error opening exception file
#define fceWriteExceptErr (-7) // error writing exception file
#define fceNoMemory (-8) // out of memory
#define fceInvalidDoc (-9) // invalid document
#define fceDiskFull (-10) // out of space on output
#define fceDocTooLarge (-11) // conversion document too large for target
#define fceOpenOutFileErr (-12) // could not open output file
#define fceUserCancel (-13) // conversion cancelled by user
#define fceWrongFileType (-14) // wrong file type for this converter
#if defined(WIN32) || defined(MACPPC)
// These errors are obsolete. Map all usages to smaller, current set.
#undef fceOpenConvErr
#define fceOpenConvErr fceOpenInFileErr
#undef fceOpenExceptErr
#define fceOpenExceptErr fceOpenInFileErr
#undef fceWriteExceptErr
#define fceWriteExceptErr fceWriteErr
#undef fceInvalidDoc
#define fceInvalidDoc fceInvalidFile
#undef fceDiskFull
#define fceDiskFull fceWriteErr
#undef fceDocTooLarge
#define fceDocTooLarge fceWriteErr
#endif
#endif // CONVERR_H
------------------------------------
Post by Peter Jamieson
For problem 1, there is an additional option in the converter API - MS
sent me the following info back in 2003, but I don't think they ever got
MS were particularly keen that you don't let the calling app suppress
the prompt if there is a possibility of a buffer overflow.
I think there was a bit more but this is the only part that I have to hand.
I can't answer problem 2 but maybe fixing problem 1 will have an impact
on that.
I'll be offline for a few days.
Peter Jamieson
-------------------------------------------------------------------
Here are the details for the new RegisterApp opcode. The implementation is
simple in theory; the actual difficulty will depend on how they have
implemented their RegisterApp function.
First, some background on RegisterApp. This converter API has been around
for along time - it allows a variable number of "opcodes" to be sent from
the calling application to the converter, and another variable set of
"opcodes" to be returned from the converter to the calling application.
To
date, this has been used for things like filename character sets (to shed
the old OEM charset dependency), unicode RTF, etc.
The new Security opcode is just another opcode that the converter can return
to the application. It requests that the application suppress the new
Security Warning.
Here are the changes that I made to our core converters to support this
(highlighted lines were added; the other lines are included for context)
// REGAPPRET byte opcodes
#define RegAppOpcodeVer 0x01 // Rtf version converter is
prepared to accept
#define RegAppOpcodeDocfile 0x02 // converter's ability to
handle regular and docfiles
#define RegAppOpcodeCharset 0x03 // converter is prepared to
handle filenames in this character set
#define RegAppOpcodeReloadOnSave 0x04 // app should reload
document after exporting
#define RegAppOpcodePicPlacehold 0x05 // app should send
placeholder pictures (with size info) for includepicture \d fields
#define RegAppOpcodeFavourUnicode 0x06 // app should output Unicode
RTF whenever possible, especially for DBCS; \uc0 is good
#define RegAppOpcodeNoClassifyChars 0x07 // app should not break text
runs by character set clasification
#define RegAppOpcodeReturnHtml 0x08 // Converter will return
HTML instead of RTF
#define RegAppOpcodeRtfCodepage 0x09 // app sould return RTF in
the specified codepage
#define RegAppOpcode7BitRtf 0x0a // app should return 7bit
rtf
#define RegAppOpcodeSuppressSecurityPrompt 0x0b // app can suppress
the security prompt -- this converter has been security reviewed
#pragma pack(1)
typedef struct _REGAPPRET // we always return these RegApp flags, so we
just put this in a structure.
{
short cbStruct; // size of this structure
// Does this converter understand docfiles and/or non-docfiles?
char cbSizefDocfile;
char opcodefDocfile;
union
{
struct
{
short fDocfile : 1;
short fNonDocfile : 1;
short : 14;
};
short grfType;
};
// Version of Word for which converter's Rtf is compliant
char cbSizeVer; //
==sizeof(char)+sizeof(char)+sizeof(short)+sizeof(short)
char opcodeVer;
short verMajor; // Major version of Word for which Rtf is
compliant
short verMinor; // Minor version of Word for which Rtf is
compliant
// What character set do we want all filenames to be in.
char cbSizeCharset;
char opcodeCharset;
char charset;
char opcodesOptional[]; // optional additional stuff
} REGAPPRET;
#pragma pack()
// Allocate return structure (allocation the largest possible block)
< if ((hRegAppRet = GlobalAlloc(GMEM_MOVEABLE, sizeof(REGAPPRET) + 10)) ==
NULL)
if ((hRegAppRet = GlobalAlloc(GMEM_MOVEABLE, sizeof(REGAPPRET) + 12)) ==
NULL)
return (HGLOBAL)0;
pbOpcodesOptional = lpRegAppRet->opcodesOptional;
*pbOpcodesOptional++ = 2; // cb of 0
*pbOpcodesOptional++ = RegAppOpcodeSuppressSecurityPrompt;
lpRegAppRet->cbStruct = (short)((ULONG_PTR)(pbOpcodesOptional) -
(ULONG_PTR)(lpRegAppRet));
GlobalUnlock(hRegAppRet);
return hRegAppRet;
-------------------------------------------------------------------
Hi,
hope anyone can help me.
I wrote a Text Converter. It works fine with Word XP and 2000, but in
1. Word 2003 shows a security warning when using my converter. Is there
a possibility to avoid this warning.
2. When I use Word's SaveAs with Filename and SaveFormat for my
converter, it seems that the SaveFormat is not correct and Word
displays the SaveAs Dialog. I took the SaveFormat from the
FileConverters Collection!
Stefan
Loading...