By looking at ImageMagick source code: http://code.metager.de/source/xref/ImageMagick/MagickCore/module.c#552
First Look for: Module_path=getenvironmentvalue ("Magick_coder_module_path"); That is, getenv ("Magick_coder_module_path"); Read System Variables
The entire test is divided into two parts, first tested by setting [environment variable]:magick_coder_module_path
Instructions for modifying [environment variables]
Putenv () is used to change or increase the contents of an environment variable. The format of the parameter Envvar is envvar=value, if the environment variable originally exists, then the variable content will be changed according to the parameters Envvar
Otherwise, the content of this parameter becomes the new environment variable, the return value: Execution succeeds returns 0, error occurs returns-1: Unable to configure new environment variable space
Note: The setting environment is only valid for the program itself (visual inspection of DLLs already loaded in the process is not valid).
The changes you make in the program are not reflected in the external environment, because the value of the variable is not propagated from the child process to the parent process, which is more secure.
However: the child process inherits the environment variable of the parent process (by default, the child process inherits a copy of the parent process environment variable memory block)
//Last Note: By testing on XP and win8.1, it shows that:
Tested under XP, by setting Magick_coder_module_path (after using the full path), SetCurrentDirectory (App_folder_path) is no longer required; You can load the baby picture properly.
Test under win8.1, by setting the Magick_coder_module_path (after using the full path), without using setcurrentdirectory (App_folder_path); , an error is still occurring:
IMAGE.C unknow 916 nodecodedelegateforthisimageformat ' JPEG ' @ error/constitute.c/readimage/501
From this result, it doesn't make sense to set the environment variable Magick_coder_module_path in the program, it is the same as the result of using the registry, the software can only be run in English folder on some win8.1.
/*
Char *pmagickcodermodulepath = getenv ("Magick_coder_module_path");
if (Pmagickcodermodulepath = = NULL)
{
Char coders_gbk[] = "D:\\soft\\c\\....\\bin\\release\\modules\\coders";
int coders_gbk_len = strlen (CODERS_GBK);
int Coders_utf8_len = Coders_gbk_len * 2;
Char Coders_utf8[coders_utf8_len];
size_t Outedsize;
Iconvstr ("GBK", "Utf-8", CODERS_GBK, Coders_gbk_len, Coders_utf8, Coders_utf8_len, &outedsize);
Char text[4096];
sprintf (text, "magick_coder_module_path=%s", Coders_utf8);
Putenv ("Magick_coder_module_path=modules\\coders"); Relative paths can also be used, but must be setcurrentdirectory (App_folder_path);
Putenv (text);
Char Exefilepath[max_path];
int len = GetModuleFileName (NULL, Exefilepath, MAX_PATH); Long, if executed successfully, returns the actual number of characters copied to lpFileName, and 0 indicates failure.
if (len > 0)
{
printf ("exefilepath:%s\n", Exefilepath);
int status = (int) ShellExecute (null, "open", Exefilepath, NULL, NULL, SW_SHOW); Open with default program
printf ("status:%d\n", status);
System ("pause");
Exit (0);
}
}
Else
{
printf ("magick_coder_module_path:%s\n", getenv ("Magick_coder_module_path"));
}
*/
Then test through the registry:
/*
[Hkey_current_user\software\imagemagick\6.8.9\q:16]
"BinPath" = "C:\\imagemagick"//Tested Discovery: BinPath parameter is not required, can not
"Configurepath" = "C:\\imagemagick"//Tested Discovery: Configurepath parameter is not required, can not
"LibPath" = "C:\\imagemagick"//Tested Discovery: LibPath parameter is not required, can not
"Codermodulespath" = "c:\\imagemagick\\modules\\coders"//Tested Discovery: This path is either a relative path, or if it is an absolute path, it must be UTF-8 encoded
"Filtermodulespath" = "c:\\imagemagick\\modules\\filters"//Tested Discovery: This path is either a relative path, or if it is an absolute path, it must be UTF-8 encoded
*/
With regard to the Codermodulespath and Filtermodulespath parameters, under XP, using the full path (utf-8), SetCurrentDirectory (App_folder_path) is no longer required;
But under win8.1 test, use the full path (UTF-8) to load the baby failure, error message:
Unabletoloadmodule ' c:\....\ Juan trajectory 嗛 V6.0\modules\coders\im_mod_rl_jpeg_.dll: The specified module could not be found (note: Trickle trajectory is actually the 嗛 code of the Chinese folder
This error message to see, in the xp,2003 system, ImageMagick load DLL, the UTF-8 code to convert to GBK, and then can load the corresponding DLL file properly
But under win8.1, the UTF-8 encoding is not transcoded, directly loaded, causing the DLL to find
Add SetCurrentDirectory (App_folder_path) under the win8.1; It's normal to load the baby again.
The test results in two ways can be seen:
ImageMagick internal loading of the Coder module code implementation is very wonderful.
Either by setting the environment variable:magick_coder_module_path, or the registry key:Codermodulespath
If the coders uses the full path after Utf-8 encoding, under XP, 2003, no SetCurrentDirectory (App_folder_path) is required; Can load the relevant DLL normally, but under win8.1, must setcurrentdirectory (App_folder_path);
And under a very small number of 64-bit win8.1, even setcurrentdirectory (App_folder_path); Also, the entire software must be placed in the [All English folder path] in order to properly load the DLL processing pictures.
Using relative paths: Modules\coders combined with setcurrentdirectory (App_folder_path); In a very small number of 64-bit win8.1 on the problem, must be stored in the [All English folder path] in order to properly load the DLL processing pictures.
There is also a workaround:
Recompile the ImageMagick source code to generate a static link library.
This may solve all problems, but the resulting EXE file will be very large, at least 5m+
Reference: http://blog.csdn.net/wwwsq/article/details/7352777
2015-04-16
Imagemagick-magick_coder_module_path test results, very wounded.