Page 1 of 1

Deployment in Windows (DLL)

Posted: 2015-06-10T04:29:45-07:00
by dbautista
Hi to all!

I have developed a simple console program that takes a coloured PDF and makes it a black and white PDF. It works OK in my development machine (Windows XP 32 bits, Visual Studio 2010) but it always fails in the function MagickReadImage in other machines (Windows 7 and 8.1 without ImageMagick installed).

This is the program:

Code: Select all

// magickexample.cpp
#include "stdafx.h"
#include "wand/MagickWand.h"
#include <stdio.h>

int main(int argc, const char* argv[]) {
	if (argc != 3) {
		printf("\nUse: %s color_file.pdf bn_file.pdf\n\n", argv[0]);
		return -1;
	}
	const char* ifile = argv[1];
	const char* ofile = argv[2];
	int threshold = 80;

	MagickWandGenesis();
	MagickWand* m_wand = NewMagickWand();

	MagickBooleanType status = MagickReadImage(m_wand, ifile);
	if (status == MagickFalse)
		printf("!MagickReadImage (%d)\n", __LINE__);
	else {
		int npages = MagickGetNumberImages(m_wand);
		printf("npages = %d\n", npages);
		//MagickSetResolution(m_wand, 209.10, 98);
		MagickSetImageFormat(m_wand, "FAX");
		MagickResetIterator(m_wand);
		while (MagickNextImage(m_wand) != MagickFalse)
			MagickThresholdImage(m_wand, (double)threshold*(QuantumRange/100));
		status = MagickWriteImages(m_wand, ofile, MagickTrue);
		if (status == MagickFalse)
			printf("!MagickWriteImages (%d)\n", __LINE__);
	}
	DestroyMagickWand(m_wand);
	MagickWandTerminus();

	return 0;
}
The compiling options:

Code: Select all

/I"C:\ImageMagick-6.9.0-Q16-dll\include" /Zi /nologo /W3 /WX- /O2 /Oi /Oy- /GL /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm- /EHsc /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Yu"StdAfx.h" /Fp"Release\magickexample.pch" /Fa"Release\" /Fo"Release\" /Fd"Release\vc100.pdb" /Gd /analyze- /errorReport:queue 
The linking options:

Code: Select all

/OUT:"C:\Documents and Settings\daniel\Mis documentos\Visual Studio 2010\Projects\magickexample\Release\magickexample.exe" /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\ImageMagick-6.9.0-Q16-dll\lib" "CORE_RL_wand_.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Release\magickexample.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Documents and Settings\daniel\Mis documentos\Visual Studio 2010\Projects\magickexample\Release\magickexample.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /PGD:"C:\Documents and Settings\daniel\Mis documentos\Visual Studio 2010\Projects\magickexample\Release\magickexample.pgd" /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE 
These are the DLLs I include with the magickexample.exe:
  • CORE_RL_bzlib_.dll
  • CORE_RL_glib_.dll
  • CORE_RL_lcms_.dll
  • CORE_RL_lqr_.dll
  • CORE_RL_magick_.dll
  • CORE_RL_ttf_.dll
  • CORE_RL_wand_.dll
  • CORE_RL_zlib_.dll
  • MSVCP100.dll
  • MSVCR100.dll
  • VCOMP100.dll
Outside my development machine, it always fails with:

Code: Select all

!MagickReadImage (22)
What am I doing wrong?

Thanks in advance!

Re: Deployment in Windows (DLL)

Posted: 2015-06-15T03:20:51-07:00
by dbautista
OK, I finally found what it's needed to make it work:
  • Put ALL the CORE_RL_*.dll in the executable folder.
  • Put ALL the IM_MOD_RL_*.dll into an arbitraty folder (for instance, C:\ImageMagick\coders). Putting them in the executable folder WON'T WORK :roll:
  • Define an environment variable MAGICK_CODER_MODULE_PATH that points to the previous path (MAGICK_CODER_MODULE_PATH=C:\ImageMagick\coders). Although this should be done with the Registry... :oops:
  • Install ghostscript, because ImageMagick calls it for the conversion from/to PDF :shock:
Some links:

http://stackoverflow.com/questions/3050 ... gick-c-api