here is the exe
yours also crashes, but it returns from the callback, at least 6 or 8 times before entering onto the RtfOut function. If you have Idapro, try debugging your version you see what is happenning. I debugged in RosAs, but i didn´t make RosAsm shows the source when is debugging inside a external file (dll for example) - It would be needed a codelevel debbuging and not a source level debugging as it is current.
This cnv files seems a huge pile of crap due to those errors, but, once we are able to fix it, we can use all converters dispites those problems and make a correct documentation on how to use them. Damn M$!
I tried to add more parameters for that function, and nothing. The original C code for this is:
/* F O R E I G N T O R T F 3 2 */
/*----------------------------------------------------------------------------
%%Function: ForeignToRtf32
Purpose:
Convert a file to Rtf using the format specified in ghszClass.
Parameters:
ghszFile : global handle to '\0'-terminated filename to be read
pstgForeign : pointer to IStorage of embedding being converted,
NULL for non-OLE2 docfile converters.
ghBuff : global handle to buffer in which chunks of Rtf are passed
to WinWord.
ghszClass: identifies which file format to translate. This
string is the one selected by the user in the 'Confirm
Conversions' dialog box in Word.
ghszSubset: identifies which subset of the file is to be converted.
Typically used by spreadsheet converters to identify
subranges of the entire spreadsheet to import.
lpfnOut: callback function provided by WinWord to be called whenever
we have a chunk of Rtf to return.
Returns:
fce indicating success or failure and cause
----------------------------------------------------------------------------*/
FCE PASCAL ForeignToRtf32(HANDLE ghszFile, IStorage *pstgForeign, HANDLE ghBuff, HANDLE ghszClass, HANDLE ghszSubset, PFN_RTF lpfnOut)
{
#ifndef CANT_IMPORT
HANDLE hFile;
char FAR *lpBuff;
char szFileName[260];
long cbFile;
long cbOrig;
short cbPass;
FCE fceRet = fceNoErr;
char rgb[cchFilePrefix];
long cbr;
AssertSz(((ghszFile == NULL) ^ (pstgForeign == NULL)),
"Need exactly one of ghszFile and pstgForeign");
if (pstgForeign)
return fceInvalidDoc;
// copy filename locally; file open doesn't want a global handle
AssertSz(ghszFile != NULL, "NULL filename in ForeignToRtf");
if (!PchBltSzHx(szFileName, ghszFile))
return fceNoMemory;
// translate filename from the oem character set to the windows set
if (!lfRegApp.fDontNeedOemConvert)
OemToChar((LPCSTR)szFileName, (LPSTR)szFileName);
// open file and read sufficient bytes to identify file type.
// Note that we cannot assume that IsFormatCorrect was previously called;
// we must check ourselves, again.
if ((hFile = CreateFile((LPSTR)szFileName, GENERIC_READ,
FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES)0,
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN,
(HANDLE)NULL)) == INVALID_HANDLE_VALUE)
{
return fceOpenInFileErr;
}
ReadFile(hFile, rgb, cchFilePrefix, &cbr, NULL);
if (strncmp(szFilePrefix, rgb, cchFilePrefix) != 0)
{
CloseHandle(hFile);
return fceInvalidFile;
}
// determine file size and restore current file position
cbOrig = cbFile = SetFilePointer(hFile, 0L, NULL, FILE_END) - (long)cchFilePrefix;
SetFilePointer(hFile, cchFilePrefix, NULL, FILE_BEGIN);
// do the actual file import conversion. We've already read the prefix,
// all that remains is to copy the remainder of the file.
for (; cbFile > 0 && fceRet >= 0; cbFile -= (long)cbPass)
{
// write at most 2K of Rtf on each WinWord callback
cbPass = (cbFile > 2048L) ? 2048 : (short)cbFile;
// we must resize the buffer, each time, ourselves.
if (GlobalReAlloc(ghBuff, (long)cbPass, GMEM_MOVEABLE) == NULL)
{
CloseHandle(hFile);
return fceNoMemory;
}
if ((lpBuff = (char FAR *)GlobalLock(ghBuff)) == NULL)
{
CloseHandle(hFile);
return fceNoMemory;
}
ReadFile(hFile, lpBuff, cbPass, &cbr, NULL);
GlobalUnlock(ghBuff);
// pass the Rtf to WinWord. Word will check for a user abort and
// may return any of our fce values to us. If negative, we need to
// ourselves abort and return that same fce.
fceRet = (FCE)((lpfnOut)(cbPass, (long)((cbOrig - cbFile) * 100 / cbOrig)));
}
CloseHandle(hFile);
return fceRet;
#else
AssertSz(fFalse, "ForeignToRtf32: This converter can't import.");
return fceOpenConvErr;
#endif // !CANT_IMPORT
}
#ifndef CANT_EXPORT
/* R T F T O F O R E I G N 3 2 */
I tried to compile this, but Visual Studio refuses it.