ConcatenateFiles dynamically loaded crashes randomly ???

The Amyuni PDF Converter is our Printer Driver that enables you to convert any documents to PDF format. If you have any questions about installing and using the Amyuni PDF Converter please post them here.
Post Reply
dCollins
Posts: 10
Joined: Fri Feb 20 2004

ConcatenateFiles dynamically loaded crashes randomly ???

Post by dCollins »

Hello,

I am loading the cdintf300.dll dynamically, in order to call concatenateFiles.

Thats how I implemented it so far:

Code: Select all

typedef BOOL (CALLBACK *lpfnConcatenateFiles)(LPCSTR file1, LPCSTR file2, LPCSTR fileDest);

// C-tor of class
HINSTANCE hModule = LoadLibrary( _T("CDINTF300.DLL") );
if (NULL == hModule)
		THROW("Error");

ConcatenateFiles = (lpfnConcatenateFiles)GetProcAddress( hModule, _T("ConcatenateFiles") );
...

//; memberfunction of class
for (i = 0; i < 10; i++){
ret = ConcatenateFiles(strFinalName.c_str(),strFile2.c_str(),strFinalName.c_str());
}
...

// d-tor of class
FreeLibrary(hModule);
during tests I experienced that the software often crashes within a call of ConcatenateFiles, with no chance of catching whatever is thrown or going wrong.
On some systems the crash happens during the first call of the for loop on other systems the second or even later. It also doesnt seem to matter wether our company PDF printer is installed or not.

I experimented a little bit and it seemed like loading and freeing the library before every single call of ConcatenateFiles, helps a little bit, but doesnt cure the crash.

Am I missing something or doing something wrong?
Is it neccessary to call pdf-Initialization /-Deinitialization functions (e.g. DriverInit, DriverEnd) to make sure that concatenateFiles is successful?
Is it neccessary to have the PDF-printer installed?

We are using AMYUNI PDF Converter developer professional v3.00.

I couldnt find any further information in the documentation,
so any ideas or help and some answers are greatly appreciated.

Thanks in advance, DCo
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello,

There is no need to initialize the printer before calling ConcatenateFIles, also there is not need for the PDF Printer to be installed on the system.

When using ConcatenateFiles() you need to call SetLicenseKey() before your call to ConcatenateFiles().

Are you getting the crash with specific files or with all the files you try to concatenated? To know this please replace your current files with simplers PDFs and run your application again.
Last edited by Joan on Mon May 28 2007, edited 1 time in total.
dCollins
Posts: 10
Joined: Fri Feb 20 2004

Post by dCollins »

thank you for you answer joan,

i think it happens with any kind of pdf documents, we tried to concatenate simple as well as more complex documents.

in my test application I started calling all the functions for de-/initializing and and it didn't crash no more on my system; but it still crashed on another system where the pdf-printer is not installed, thats why I asked the questions in my first post.

I will give your suggestion a shot tomorrow and post my results and findings here.

Thanks again,
Dco
dCollins
Posts: 10
Joined: Fri Feb 20 2004

Post by dCollins »

hello, I am back ... with not so good results,

as you suggested I implemented the call of SetLicenseKey too;
but the crash still occurs.
It still happens very randomly and when generating debug output the last function called is ConcatenateFiles and a callstack with only an address and no module and the error code of an access violation.

What I forgot to mention in my previous posts is:
- The first pdf-document is either a PDF-Document directly created via our amyuni printer or a copy of an already existing PDF-Document
- The maximum number of PDFs concatenated is 16 Documents (all different sizes, containing text,no graphics, created with adobe)
- The crash happen very easily/quickly when the first document is directly created by our amyuni printer, that means concat an adobe document to an amyuni document if you will.
- When it once crashes it seems like whenever you call the function again it crashes as well (even after restarting the software).

we are at our wits end and wonder whats going wrong.
I searched the message board and couldnt find any problem like ours.

So please, dear amyuni team and/or message board community do you have any more suggestions/ideas???

thanks in advance,
DCo
Jose
Amyuni Team
Posts: 553
Joined: Tue Oct 01 2002
Contact:

Post by Jose »

Hello,

If you wish to append a number of documents into one larger document using the DLL interface, I suggest that you code snippet below. This come is more efficient and faster that the ConcatenateFiles() function because it doesn't have to open the source document each time.

In the code snippet below, the main docuetn is opened once and all other documents are appended to it.

Let us know if this helps?

/************document processing functions*************/ typedef HANDLE EXTDOCHANDLE;
typedef int (CALLBACK* lpfnDocOpenAProc)(EXTDOCHANDLE* pedhDocument, LPCSTR szFileName, LPCSTR szPassword);
typedef int (CALLBACK* lpfnDocSaveAProc)(EXTDOCHANDLE edhDocument, LPCSTR szFileName);
typedef int (CALLBACK* lpfnDocCloseProc)(EXTDOCHANDLE edhDocument);
typedef bool(CALLBACK* lpfnSetLicenseKeyAProc)(LPCSTR szCompany, LPCSTR szLicKey);

lpfnDocDigitalSignatureAProc DocDigitalSignatureA = NULL;
lpfnDocOpenAProc DocOpenA = NULL;
lpfnDocSaveAProc DocSaveA = NULL;
lpfnDocCloseProc DocClose = NULL;


void CAppend_testDlg::OnBtnTestCode()
{
EXTDOCHANDLE doc; // Handle to Document
EXTDOCHANDLE docTemp; // Handle to TEMP Document

HINSTANCE hDLL; // Handle to DLL
hDLL = LoadLibrary( _T("cdintf300.DLL") );
if ( hDLL != NULL )
{

//Must check return codes of all functions
DocOpenA = (lpfnDocOpenAProc) GetProcAddress (hDLL, _T("DocOpenA"));
DocSaveA = (lpfnDocSaveAProc) GetProcAddress (hDLL, _T("DocSaveA"));
DocClose = (lpfnDocCloseProc) GetProcAddress (hDLL, _T("DocClose"));
DocAppend = (lpfnDocAppend) GetProcAddress (hDLL, "DocAppend");
DocPrintA = (lpfnDocPrintA) GetProcAddress (hDLL, "DocPrintA");
SetLicenseKeyA = (lpfnSetLicenseKeyAProc) GetProcAddress (hDLL, _T("SetLicenseKeyA"));


(*SetLicenseKeyA) (_T("Amyuni Pro"), _T("07EFCDA....1F63"));

//Open main document
(*DocOpenA)(&doc, _T("c:\\temp\\append\\1.pdf"), _T(""));

//Loop through your files
for (int i = 0; i < 16; i++)
{
CString MFCString;
MFCString.Format("%d", i);

//Open document to append
(*DocOpenA)(&docTemp, _T("c:\\temp\\append\\sample" + MFCString + ".pdf"), _T(""));

//append doccument
(*DocAppend)(doc, docTemp);

//close document
(*DocClose)(docTemp);
}

(*DocSaveA)(doc, _T("c:\\temp\\input_sign.pdf"));

//close main document
(*DocClose)(doc);

//clean up
FreeLibrary(hDLL);
}
else
{
AfxMessageBox (_T("Oops"));
}

}

Hope this helps?
dCollins
Posts: 10
Joined: Fri Feb 20 2004

Post by dCollins »

thanks, jose for the email and for posting the code here too.

I implemented the code into our software, but didnt do no intensive tests yet.
During the few tests we did with the new implementation, we still had crashes, but not as often as with using ConcatenateFiles.
And the speed increase is very pleasant.


so much for the current status,
thanks again for your help

DCo
dCollins
Posts: 10
Joined: Fri Feb 20 2004

Post by dCollins »

hello,

we did some more testing. And as I mentioned last friday, crashes still occur; even though it doesnt happen as often as it used to.

Do you have anymore ideas how to fix that or any other suggestions to minimize the crashes in the concatenation process? (e.g. which pdf-Version to use, which encryption or security should be used with the documents)


Thanks for your support,
DCo
Post Reply