2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Windows NT Utility Methods for MagickCore %
20 % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 #include "MagickCore/studio.h"
42 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
43 #include "MagickCore/client.h"
44 #include "MagickCore/exception-private.h"
45 #include "MagickCore/locale_.h"
46 #include "MagickCore/log.h"
47 #include "MagickCore/magick.h"
48 #include "MagickCore/memory_.h"
49 #include "MagickCore/resource_.h"
50 #include "MagickCore/timer.h"
51 #include "MagickCore/string_.h"
52 #include "MagickCore/utility.h"
53 #include "MagickCore/version.h"
54 #if defined(MAGICKCORE_LTDL_DELEGATE)
57 #include "MagickCore/nt-base.h"
58 #if defined(MAGICKCORE_CIPHER_SUPPORT)
66 #if !defined(MAP_FAILED)
67 #define MAP_FAILED ((void *) -1)
73 #if !defined(MAGICKCORE_LTDL_DELEGATE)
75 *lt_slsearchpath = (char *) NULL;
82 *ghost_handle = (void *) NULL;
85 External declarations.
87 #if !defined(MAGICKCORE_WINDOWS_SUPPORT)
88 extern "C" BOOL WINAPI
89 DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved);
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 % DllMain() is an entry point to the DLL which is called when processes and
104 % threads are initialized and terminated, or upon calls to the Windows
105 % LoadLibrary and FreeLibrary functions.
107 % The function returns TRUE of it succeeds, or FALSE if initialization fails.
109 % The format of the DllMain method is:
111 % BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
113 % A description of each parameter follows:
115 % o handle: handle to the DLL module
117 % o reason: reason for calling function:
119 % DLL_PROCESS_ATTACH - DLL is being loaded into virtual address
120 % space of current process.
121 % DLL_THREAD_ATTACH - Indicates that the current process is
122 % creating a new thread. Called under the
123 % context of the new thread.
124 % DLL_THREAD_DETACH - Indicates that the thread is exiting.
125 % Called under the context of the exiting
127 % DLL_PROCESS_DETACH - Indicates that the DLL is being unloaded
128 % from the virtual address space of the
131 % o lpvReserved: Used for passing additional info during DLL_PROCESS_ATTACH
132 % and DLL_PROCESS_DETACH.
135 #if defined(_DLL) && defined( ProvideDllMain )
136 BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
140 case DLL_PROCESS_ATTACH:
148 module_path=(char *) AcquireQuantumMemory(MaxTextExtent,
149 sizeof(*module_path));
150 if (module_path == (char *) NULL)
152 count=(ssize_t) GetModuleFileName(handle,module_path,MaxTextExtent);
158 for ( ; count > 0; count--)
159 if (module_path[count] == '\\')
161 module_path[count+1]='\0';
164 MagickCoreGenesis(module_path,MagickFalse);
165 path=(char *) AcquireQuantumMemory(16UL*MaxTextExtent,sizeof(*path));
166 if (path == (char *) NULL)
168 module_path=DestroyString(module_path);
171 count=(ssize_t) GetEnvironmentVariable("PATH",path,16*MaxTextExtent);
172 if ((count != 0) && (strstr(path,module_path) == (char *) NULL))
174 if ((strlen(module_path)+count+1) < (16*MaxTextExtent-1))
179 variable=(char *) AcquireQuantumMemory(16UL*MaxTextExtent,
181 if (variable == (char *) NULL)
183 path=DestroyString(path);
184 module_path=DestroyString(module_path);
187 (void) FormatLocaleString(variable,16*MaxTextExtent,
188 "%s;%s",module_path,path);
189 SetEnvironmentVariable("PATH",variable);
190 variable=DestroyString(variable);
193 path=DestroyString(path);
195 module_path=DestroyString(module_path);
198 case DLL_PROCESS_DETACH:
200 MagickCoreTerminus();
211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 % Exit() calls TerminateProcess for Win95.
223 % The format of the exit method is:
225 % int Exit(int status)
227 % A description of each parameter follows:
229 % o status: an integer value representing the status of the terminating
233 MagickExport int Exit(int status)
236 TerminateProcess(GetCurrentProcess(),(unsigned int) status);
241 #if !defined(__MINGW32__)
243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 % g e t t i m e o f d a y %
251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 % The gettimeofday() method get the time of day.
255 % The format of the gettimeofday method is:
257 % int gettimeofday(struct timeval *time_value,struct timezone *time_zone)
259 % A description of each parameter follows:
261 % o time_value: the time value.
263 % o time_zone: the time zone.
266 MagickExport int gettimeofday (struct timeval *time_value,
267 struct timezone *time_zone)
269 #define EpochFiletime MagickLLConstant(116444736000000000)
274 if (time_value != (struct timeval *) NULL)
285 GetSystemTimeAsFileTime(&file_time);
286 date_time.LowPart=file_time.dwLowDateTime;
287 date_time.HighPart=file_time.dwHighDateTime;
288 time=date_time.QuadPart;
291 time_value->tv_sec=(ssize_t) (time / 1000000);
292 time_value->tv_usec=(ssize_t) (time % 1000000);
294 if (time_zone != (struct timezone *) NULL)
301 time_zone->tz_minuteswest=_timezone/60;
302 time_zone->tz_dsttime=_daylight;
309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313 % I s W i n d o w s 9 5 %
317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
319 % IsWindows95() returns true if the system is Windows 95.
321 % The format of the IsWindows95 method is:
326 MagickExport int IsWindows95()
331 version_info.dwOSVersionInfoSize=sizeof(version_info);
332 if (GetVersionEx(&version_info) &&
333 (version_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS))
339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343 % N T A r g v T o U T F 8 %
347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
349 % NTArgvToUTF8() converts the wide command line arguments to UTF-8 to ensure
350 % compatibility with Linux.
352 % The format of the NTArgvToUTF8 method is:
354 % char **NTArgvToUTF8(const int argc,wchar_t **argv)
356 % A description of each parameter follows:
358 % o argc: the number of command line arguments.
360 % o argv: the wide-character command line arguments.
363 MagickExport char **NTArgvToUTF8(const int argc,wchar_t **argv)
371 utf8=(char **) AcquireQuantumMemory(argc,sizeof(*utf8));
372 if (utf8 == (char **) NULL)
373 ThrowFatalException(ResourceLimitFatalError,"UnableToConvertStringToARGV");
374 for (i=0; i < (ssize_t) argc; i++)
379 count=WideCharToMultiByte(CP_UTF8,0,argv[i],-1,NULL,0,NULL,NULL);
382 utf8[i]=(char *) AcquireQuantumMemory(count+1,sizeof(**utf8));
383 if (utf8[i] == (char *) NULL)
385 for (i--; i >= 0; i--)
386 utf8[i]=DestroyString(utf8[i]);
387 utf8=(char **) RelinquishMagickMemory(utf8);
388 ThrowFatalException(ResourceLimitFatalError,
389 "UnableToConvertStringToARGV");
391 count=WideCharToMultiByte(CP_UTF8,0,argv[i],-1,utf8[i],count,NULL,NULL);
398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402 % N T C l o s e D i r e c t o r y %
406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
408 % NTCloseDirectory() closes the named directory stream and frees the DIR
411 % The format of the NTCloseDirectory method is:
413 % int NTCloseDirectory(DIR *entry)
415 % A description of each parameter follows:
417 % o entry: Specifies a pointer to a DIR structure.
420 MagickExport int NTCloseDirectory(DIR *entry)
422 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
423 assert(entry != (DIR *) NULL);
424 FindClose(entry->hSearch);
425 entry=(DIR *) RelinquishMagickMemory(entry);
430 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
434 % N T C l o s e L i b r a r y %
438 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
440 % NTCloseLibrary() unloads the module associated with the passed handle.
442 % The format of the NTCloseLibrary method is:
444 % void NTCloseLibrary(void *handle)
446 % A description of each parameter follows:
448 % o handle: Specifies a handle to a previously loaded dynamic module.
451 MagickExport int NTCloseLibrary(void *handle)
454 return(FreeLibrary((HINSTANCE) handle));
455 return(!(FreeLibrary((HINSTANCE) handle)));
459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
463 % N T C o n t r o l H a n d l e r %
467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
469 % NTControlHandler() registers a control handler that is activated when, for
470 % example, a ctrl-c is received.
472 % The format of the NTControlHandler method is:
474 % int NTControlHandler(void)
478 static BOOL ControlHandler(DWORD type)
481 AsynchronousResourceComponentTerminus();
485 MagickExport int NTControlHandler(void)
487 return(SetConsoleCtrlHandler((PHANDLER_ROUTINE) ControlHandler,TRUE));
491 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
495 % N T E l a p s e d T i m e %
499 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
501 % NTElapsedTime() returns the elapsed time (in seconds) since the last call to
504 % The format of the ElapsedTime method is:
506 % double NTElapsedTime(void)
509 MagickExport double NTElapsedTime(void)
523 GetSystemTime(&system_time);
524 SystemTimeToFileTime(&system_time,&elapsed_time.filetime);
525 return((double) 1.0e-7*elapsed_time.filetime64);
529 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
533 + N T E r r o r H a n d l e r %
537 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
539 % NTErrorHandler() displays an error reason and then terminates the program.
541 % The format of the NTErrorHandler method is:
543 % void NTErrorHandler(const ExceptionType severity,const char *reason,
544 % const char *description)
546 % A description of each parameter follows:
548 % o severity: Specifies the numeric error category.
550 % o reason: Specifies the reason to display before terminating the
553 % o description: Specifies any description to the reason.
556 MagickExport void NTErrorHandler(const ExceptionType severity,
557 const char *reason,const char *description)
560 buffer[3*MaxTextExtent],
564 if (reason == (char *) NULL)
566 MagickCoreTerminus();
569 message=GetExceptionMessage(errno);
570 if ((description != (char *) NULL) && errno)
571 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s (%s) [%s].\n",
572 GetClientName(),reason,description,message);
574 if (description != (char *) NULL)
575 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s (%s).\n",
576 GetClientName(),reason,description);
579 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s [%s].\n",
580 GetClientName(),reason,message);
582 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s.\n",
583 GetClientName(),reason);
584 message=DestroyString(message);
585 (void) MessageBox(NULL,buffer,"ImageMagick Exception",MB_OK | MB_TASKMODAL |
586 MB_SETFOREGROUND | MB_ICONEXCLAMATION);
587 MagickCoreTerminus();
592 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
596 % N T E x i t L i b r a r y %
600 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
602 % NTExitLibrary() exits the dynamic module loading subsystem.
604 % The format of the NTExitLibrary method is:
606 % int NTExitLibrary(void)
609 MagickExport int NTExitLibrary(void)
615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
619 % N T G a t h e r R a n d o m D a t a %
623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
625 % NTGatherRandomData() gathers random data and returns it.
627 % The format of the GatherRandomData method is:
629 % MagickBooleanType NTGatherRandomData(const size_t length,
630 % unsigned char *random)
632 % A description of each parameter follows:
634 % length: the length of random data buffer
636 % random: the random data is returned here.
639 MagickExport MagickBooleanType NTGatherRandomData(const size_t length,
640 unsigned char *random)
642 #if defined(MAGICKCORE_CIPHER_SUPPORT) && defined(_MSC_VER) && (_MSC_VER > 1200)
649 handle=(HCRYPTPROV) NULL;
650 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
651 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET));
653 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
654 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET));
657 status=CryptGenRandom(handle,(DWORD) length,random);
660 status=CryptReleaseContext(handle,0);
663 status=CryptReleaseContext(handle,0);
674 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
678 % N T G e t E x e c u t i o n P a t h %
682 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
684 % NTGetExecutionPath() returns the execution path of a program.
686 % The format of the GetExecutionPath method is:
688 % MagickBooleanType NTGetExecutionPath(char *path,const size_t extent)
690 % A description of each parameter follows:
692 % o path: the pathname of the executable that started the process.
694 % o extent: the maximum extent of the path.
697 MagickExport MagickBooleanType NTGetExecutionPath(char *path,
700 GetModuleFileName(0,path,(DWORD) extent);
705 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
709 % N T G e t L a s t E r r o r %
713 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
715 % NTGetLastError() returns the last error that occurred.
717 % The format of the NTGetLastError method is:
719 % char *NTGetLastError(void)
722 char *NTGetLastError(void)
733 status=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
734 FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),
735 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR) &buffer,0,NULL);
737 reason=AcquireString("An unknown error occurred");
740 reason=AcquireString((const char *) buffer);
747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
751 % N T G e t L i b r a r y E r r o r %
755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
757 % Lt_dlerror() returns a pointer to a string describing the last error
758 % associated with a lt_dl method. Note that this function is not thread
759 % safe so it should only be used under the protection of a lock.
761 % The format of the NTGetLibraryError method is:
763 % const char *NTGetLibraryError(void)
766 MagickExport const char *NTGetLibraryError(void)
769 last_error[MaxTextExtent];
775 error=NTGetLastError();
777 (void) CopyMagickString(last_error,error,MaxTextExtent);
778 error=DestroyString(error);
783 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
787 % N T G e t L i b r a r y S y m b o l %
791 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
793 % NTGetLibrarySymbol() retrieve the procedure address of the method
794 % specified by the passed character string.
796 % The format of the NTGetLibrarySymbol method is:
798 % void *NTGetLibrarySymbol(void *handle,const char *name)
800 % A description of each parameter follows:
802 % o handle: Specifies a handle to the previously loaded dynamic module.
804 % o name: Specifies the procedure entry point to be returned.
807 void *NTGetLibrarySymbol(void *handle,const char *name)
812 lpfnDllFunc1=(LPFNDLLFUNC1) GetProcAddress((HINSTANCE) handle,name);
814 return((void *) NULL);
815 return((void *) lpfnDllFunc1);
819 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
823 % N T G e t M o d u l e P a t h %
827 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
829 % NTGetModulePath() returns the path of the specified module.
831 % The format of the GetModulePath method is:
833 % MagickBooleanType NTGetModulePath(const char *module,char *path)
835 % A description of each parameter follows:
837 % modith: the module name.
839 % path: the module path is returned here.
842 MagickExport MagickBooleanType NTGetModulePath(const char *module,char *path)
845 module_path[MaxTextExtent];
854 handle=GetModuleHandle(module);
855 if (handle == (HMODULE) NULL)
857 length=GetModuleFileName(handle,module_path,MaxTextExtent);
859 GetPathComponent(module_path,HeadPath,path);
864 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
868 % N T G h o s t s c r i p t D L L %
872 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
874 % NTGhostscriptDLL() returns the path to the most recent Ghostscript version
875 % DLL. The method returns TRUE on success otherwise FALSE.
877 % The format of the NTGhostscriptDLL method is:
879 % int NTGhostscriptDLL(char *path,int length)
881 % A description of each parameter follows:
883 % o path: return the Ghostscript DLL path here.
885 % o length: the buffer length.
889 static int NTGetRegistryValue(HKEY root,const char *key,const char *name,
890 char *value,int *length)
907 Get a registry value: key = root\\key, named value = name.
909 if (RegOpenKeyExA(root,key,0,KEY_READ,&hkey) != ERROR_SUCCESS)
910 return(1); /* no match */
914 if (p == (BYTE *) NULL)
915 p=(&byte); /* ERROR_MORE_DATA only if value is NULL */
916 status=RegQueryValueExA(hkey,(char *) name,0,&type,p,&extent);
918 if (status == ERROR_SUCCESS)
921 return(0); /* return the match */
923 if (status == ERROR_MORE_DATA)
926 return(-1); /* buffer not large enough */
928 return(1); /* not found */
931 static int NTLocateGhostscript(const char **product_family,int *major_version,
946 "Aladdin Ghostscript"
950 Find the most recent version of Ghostscript.
953 *product_family=NULL;
955 *minor_version=49; /* min version of Ghostscript is 5.50 */
956 for (i=0; i < (ssize_t) (sizeof(products)/sizeof(products[0])); i++)
968 (void) FormatLocaleString(key,MaxTextExtent,"SOFTWARE\\%s",products[i]);
969 root=HKEY_LOCAL_MACHINE;
971 if (RegOpenKeyExA(root,key,0,mode,&hkey) == ERROR_SUCCESS)
980 Now enumerate the keys.
982 extent=sizeof(key)/sizeof(char);
983 for (j=0; RegEnumKeyA(hkey,j,key,extent) == ERROR_SUCCESS; j++)
991 if (sscanf(key,"%d.%d",&major,&minor) != 2)
993 if ((major > *major_version) || ((major == *major_version) &&
994 (minor > *minor_version)))
996 *product_family=products[i];
997 *major_version=major;
998 *minor_version=minor;
1002 (void) RegCloseKey(hkey);
1005 if (status == FALSE)
1010 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"Ghostscript (%s) "
1011 "version %d.%02d",*product_family,*major_version,*minor_version);
1015 static int NTGhostscriptGetString(const char *name,char *value,
1016 const size_t length)
1026 *product_family = (const char *) NULL;
1042 { HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
1043 { HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" }
1047 Get a string from the installed Ghostscript.
1050 if (product_family == NULL)
1051 (void) NTLocateGhostscript(&product_family,&major_version,&minor_version);
1052 if (product_family == NULL)
1054 (void) FormatLocaleString(key,MaxTextExtent,"SOFTWARE\\%s\\%d.%02d",
1055 product_family,major_version,minor_version);
1056 for (i=0; i < (ssize_t) (sizeof(hkeys)/sizeof(hkeys[0])); i++)
1058 extent=(int) length;
1059 if (NTGetRegistryValue(hkeys[i].hkey,key,name,value,&extent) == 0)
1061 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1062 "registry: \"%s\\%s\\%s\"=\"%s\"",hkeys[i].name,key,name,value);
1065 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1066 "registry: \"%s\\%s\\%s\" (failed)",hkeys[i].name,key,name);
1071 MagickExport int NTGhostscriptDLL(char *path,int length)
1074 dll[MaxTextExtent] = { "" };
1077 if ((*dll == '\0') &&
1078 (NTGhostscriptGetString("GS_DLL",dll,sizeof(dll)) == FALSE))
1080 (void) CopyMagickString(path,dll,length);
1085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1089 % N T G h o s t s c r i p t D L L V e c t o r s %
1093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1095 % NTGhostscriptDLLVectors() returns a GhostInfo structure that includes
1096 % function vectors to invoke Ghostscript DLL functions. A null pointer is
1097 % returned if there is an error when loading the DLL or retrieving the
1100 % The format of the NTGhostscriptDLLVectors method is:
1102 % const GhostInfo *NTGhostscriptDLLVectors(void)
1105 MagickExport const GhostInfo *NTGhostscriptDLLVectors(void)
1107 if (NTGhostscriptLoadDLL() == FALSE)
1108 return((GhostInfo *) NULL);
1109 return(&ghost_info);
1113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1117 % N T G h o s t s c r i p t E X E %
1121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1123 % NTGhostscriptEXE() obtains the path to the latest Ghostscript executable.
1124 % The method returns FALSE if a full path value is not obtained and returns
1125 % a default path of gswin32c.exe.
1127 % The format of the NTGhostscriptEXE method is:
1129 % int NTGhostscriptEXE(char *path,int length)
1131 % A description of each parameter follows:
1133 % o path: return the Ghostscript executable path here.
1135 % o length: length of buffer.
1138 MagickExport int NTGhostscriptEXE(char *path,int length)
1144 program[MaxTextExtent] = { "" };
1146 (void) CopyMagickString(path,"gswin32c.exe",length);
1147 if ((*program == '\0') &&
1148 (NTGhostscriptGetString("GS_DLL",program,sizeof(program)) == FALSE))
1150 p=strrchr(program,'\\');
1151 if (p != (char *) NULL)
1155 (void) ConcatenateMagickString(program,"gswin32c.exe",sizeof(program));
1157 (void) CopyMagickString(path,program,length);
1162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1166 % N T G h o s t s c r i p t F o n t s %
1170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1172 % NTGhostscriptFonts() obtains the path to the Ghostscript fonts. The method
1173 % returns FALSE if it cannot determine the font path.
1175 % The format of the NTGhostscriptFonts method is:
1177 % int NTGhostscriptFonts(char *path, int length)
1179 % A description of each parameter follows:
1181 % o path: return the font path here.
1183 % o length: length of the path buffer.
1186 MagickExport int NTGhostscriptFonts(char *path,int length)
1189 buffer[MaxTextExtent],
1190 filename[MaxTextExtent];
1197 if (NTGhostscriptGetString("GS_LIB",buffer,MaxTextExtent) == FALSE)
1199 for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
1201 (void) CopyMagickString(path,p+1,length+1);
1202 q=strchr(path,DirectoryListSeparator);
1203 if (q != (char *) NULL)
1205 (void) FormatLocaleString(filename,MaxTextExtent,"%s%sfonts.dir",path,
1206 DirectorySeparator);
1207 if (IsPathAccessible(filename) != MagickFalse)
1214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1218 % N T G h o s t s c r i p t L o a d D L L %
1222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1224 % NTGhostscriptLoadDLL() attempts to load the Ghostscript DLL and returns
1225 % TRUE if it succeeds.
1227 % The format of the NTGhostscriptLoadDLL method is:
1229 % int NTGhostscriptLoadDLL(void)
1232 MagickExport int NTGhostscriptLoadDLL(void)
1235 path[MaxTextExtent];
1237 if (ghost_handle != (void *) NULL)
1239 if (NTGhostscriptDLL(path,sizeof(path)) == FALSE)
1241 ghost_handle=lt_dlopen(path);
1242 if (ghost_handle == (void *) NULL)
1244 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1245 ghost_info.exit=(int (MagickDLLCall *)(gs_main_instance*))
1246 lt_dlsym(ghost_handle,"gsapi_exit");
1247 ghost_info.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,int,
1248 char **)) (lt_dlsym(ghost_handle,"gsapi_init_with_args"));
1249 ghost_info.new_instance=(int (MagickDLLCall *)(gs_main_instance **,void *)) (
1250 lt_dlsym(ghost_handle,"gsapi_new_instance"));
1251 ghost_info.run_string=(int (MagickDLLCall *)(gs_main_instance *,const char *,
1252 int,int *)) (lt_dlsym(ghost_handle,"gsapi_run_string"));
1253 ghost_info.delete_instance=(void (MagickDLLCall *) (gs_main_instance *)) (
1254 lt_dlsym(ghost_handle,"gsapi_delete_instance"));
1255 if ((ghost_info.exit == NULL) || (ghost_info.init_with_args == NULL) ||
1256 (ghost_info.new_instance == NULL) || (ghost_info.run_string == NULL) ||
1257 (ghost_info.delete_instance == NULL))
1263 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1267 % N T G h o s t s c r i p t U n L o a d D L L %
1271 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1273 % NTGhostscriptUnLoadDLL() unloads the Ghostscript DLL and returns TRUE if
1276 % The format of the NTGhostscriptUnLoadDLL method is:
1278 % int NTGhostscriptUnLoadDLL(void)
1281 MagickExport int NTGhostscriptUnLoadDLL(void)
1286 if (ghost_handle == (void *) NULL)
1288 status=lt_dlclose(ghost_handle);
1289 ghost_handle=(void *) NULL;
1290 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1299 % N T I n i t i a l i z e L i b r a r y %
1303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1305 % NTInitializeLibrary() initializes the dynamic module loading subsystem.
1307 % The format of the NTInitializeLibrary method is:
1309 % int NTInitializeLibrary(void)
1312 MagickExport int NTInitializeLibrary(void)
1318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1322 + N T M a p M e m o r y %
1326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1328 % Mmap() emulates the Unix method of the same name.
1330 % The format of the NTMapMemory method is:
1332 % MagickExport void *NTMapMemory(char *address,size_t length,int protection,
1333 % int access,int file,MagickOffsetType offset)
1336 MagickExport void *NTMapMemory(char *address,size_t length,int protection,
1337 int flags,int file,MagickOffsetType offset)
1356 file_handle=INVALID_HANDLE_VALUE;
1357 low_length=(DWORD) (length & 0xFFFFFFFFUL);
1358 high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
1359 map_handle=INVALID_HANDLE_VALUE;
1361 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
1362 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
1364 if (protection & PROT_WRITE)
1366 access_mode=FILE_MAP_WRITE;
1367 if (!(flags & MAP_PRIVATE))
1368 protection_mode=PAGE_READWRITE;
1371 access_mode=FILE_MAP_COPY;
1372 protection_mode=PAGE_WRITECOPY;
1376 if (protection & PROT_READ)
1378 access_mode=FILE_MAP_READ;
1379 protection_mode=PAGE_READONLY;
1381 if ((file == -1) && (flags & MAP_ANONYMOUS))
1382 file_handle=INVALID_HANDLE_VALUE;
1384 file_handle=(HANDLE) _get_osfhandle(file);
1385 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
1389 map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
1391 CloseHandle(map_handle);
1393 if (map == (void *) NULL)
1394 return((void *) MAP_FAILED);
1395 return((void *) ((char *) map));
1399 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1403 % N T O p e n D i r e c t o r y %
1407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1409 % NTOpenDirectory() opens the directory named by filename and associates a
1410 % directory stream with it.
1412 % The format of the NTOpenDirectory method is:
1414 % DIR *NTOpenDirectory(const char *path)
1416 % A description of each parameter follows:
1418 % o entry: Specifies a pointer to a DIR structure.
1421 MagickExport DIR *NTOpenDirectory(const char *path)
1424 file_specification[MaxTextExtent];
1432 assert(path != (const char *) NULL);
1433 length=CopyMagickString(file_specification,path,MaxTextExtent);
1434 if (length >= (MaxTextExtent-1))
1435 return((DIR *) NULL);
1436 length=ConcatenateMagickString(file_specification,DirectorySeparator,
1438 if (length >= (MaxTextExtent-1))
1439 return((DIR *) NULL);
1440 entry=(DIR *) AcquireMagickMemory(sizeof(DIR));
1441 if (entry != (DIR *) NULL)
1443 entry->firsttime=TRUE;
1444 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1446 if (entry->hSearch == INVALID_HANDLE_VALUE)
1448 length=ConcatenateMagickString(file_specification,"\\*.*",MaxTextExtent);
1449 if (length >= (MaxTextExtent-1))
1451 entry=(DIR *) RelinquishMagickMemory(entry);
1452 return((DIR *) NULL);
1454 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1455 if (entry->hSearch == INVALID_HANDLE_VALUE)
1457 entry=(DIR *) RelinquishMagickMemory(entry);
1458 return((DIR *) NULL);
1465 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1469 % N T O p e n L i b r a r y %
1473 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1475 % NTOpenLibrary() loads a dynamic module into memory and returns a handle that
1476 % can be used to access the various procedures in the module.
1478 % The format of the NTOpenLibrary method is:
1480 % void *NTOpenLibrary(const char *filename)
1482 % A description of each parameter follows:
1484 % o path: Specifies a pointer to string representing dynamic module that
1489 static const char *GetSearchPath( void )
1491 #if defined(MAGICKCORE_LTDL_DELEGATE)
1492 return(lt_dlgetsearchpath());
1494 return(lt_slsearchpath);
1498 MagickExport void *NTOpenLibrary(const char *filename)
1500 #define MaxPathElements 31
1503 buffer[MaxTextExtent];
1521 mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
1522 handle=(void *) LoadLibraryEx(filename,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1523 if ((handle != (void *) NULL) || (GetSearchPath() == (char *) NULL))
1528 p=(char *) GetSearchPath();
1530 while (index < MaxPathElements)
1532 q=strchr(p,DirectoryListSeparator);
1533 if (q == (char *) NULL)
1535 (void) CopyMagickString(buffer,p,MaxTextExtent);
1536 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
1537 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
1538 handle=(void *) LoadLibraryEx(buffer,NULL,
1539 LOAD_WITH_ALTERED_SEARCH_PATH);
1543 (void) CopyMagickString(buffer,p,i+1);
1544 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
1545 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
1546 handle=(void *) LoadLibraryEx(buffer,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1547 if (handle != (void *) NULL)
1556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1560 % N T R e a d D i r e c t o r y %
1564 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1566 % NTReadDirectory() returns a pointer to a structure representing the
1567 % directory entry at the current position in the directory stream to which
1570 % The format of the NTReadDirectory
1572 % NTReadDirectory(entry)
1574 % A description of each parameter follows:
1576 % o entry: Specifies a pointer to a DIR structure.
1579 MagickExport struct dirent *NTReadDirectory(DIR *entry)
1587 if (entry == (DIR *) NULL)
1588 return((struct dirent *) NULL);
1589 if (!entry->firsttime)
1591 status=FindNextFile(entry->hSearch,&entry->Win32FindData);
1593 return((struct dirent *) NULL);
1595 length=CopyMagickString(entry->file_info.d_name,
1596 entry->Win32FindData.cFileName,sizeof(entry->file_info.d_name));
1597 if (length >= sizeof(entry->file_info.d_name))
1598 return((struct dirent *) NULL);
1599 entry->firsttime=FALSE;
1600 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
1601 return(&entry->file_info);
1605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1609 % N T R e g i s t r y K e y L o o k u p %
1613 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1615 % NTRegistryKeyLookup() returns ImageMagick installation path settings
1616 % stored in the Windows Registry. Path settings are specific to the
1617 % installed ImageMagick version so that multiple Image Magick installations
1620 % Values are stored in the registry under a base path path similar to
1621 % "HKEY_LOCAL_MACHINE/SOFTWARE\ImageMagick\6.7.4\Q:16" or
1622 % "HKEY_CURRENT_USER/SOFTWARE\ImageMagick\6.7.4\Q:16". The provided subkey
1623 % is appended to this base path to form the full key.
1625 % The format of the NTRegistryKeyLookup method is:
1627 % unsigned char *NTRegistryKeyLookup(const char *subkey)
1629 % A description of each parameter follows:
1631 % o subkey: Specifies a string that identifies the registry object.
1632 % Currently supported sub-keys include: "BinPath", "ConfigurePath",
1633 % "LibPath", "CoderModulesPath", "FilterModulesPath", "SharePath".
1636 MagickExport unsigned char *NTRegistryKeyLookup(const char *subkey)
1639 package_key[MaxTextExtent];
1657 (void) FormatLocaleString(package_key,MaxTextExtent,"SOFTWARE\\%s\\%s\\Q:%d",
1658 MagickPackageName,MagickLibVersionText,MAGICKCORE_QUANTUM_DEPTH);
1659 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",package_key);
1660 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1661 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,package_key,0,KEY_READ,®istry_key);
1662 if (status != ERROR_SUCCESS)
1663 status=RegOpenKeyExA(HKEY_CURRENT_USER,package_key,0,KEY_READ,
1665 if (status != ERROR_SUCCESS)
1667 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1668 return((unsigned char *) NULL);
1674 value=(unsigned char *) AcquireQuantumMemory(size,sizeof(*value));
1675 if (value == (unsigned char *) NULL)
1677 RegCloseKey(registry_key);
1678 return((unsigned char *) NULL);
1680 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",subkey);
1681 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1682 if ((status == ERROR_MORE_DATA) && (type == REG_SZ))
1684 value=(unsigned char *) ResizeQuantumMemory(value,size,sizeof(*value));
1685 if (value == (BYTE *) NULL)
1687 RegCloseKey(registry_key);
1688 return((unsigned char *) NULL);
1690 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1692 RegCloseKey(registry_key);
1693 if ((type != REG_SZ) || (status != ERROR_SUCCESS))
1694 value=(unsigned char *) RelinquishMagickMemory(value);
1695 return((unsigned char *) value);
1699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1703 % N T R e p o r t E v e n t %
1707 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1709 % NTReportEvent() reports an event.
1711 % The format of the NTReportEvent method is:
1713 % MagickBooleanType NTReportEvent(const char *event,
1714 % const MagickBooleanType error)
1716 % A description of each parameter follows:
1718 % o event: the event.
1720 % o error: MagickTrue the event is an error.
1723 MagickExport MagickBooleanType NTReportEvent(const char *event,
1724 const MagickBooleanType error)
1735 handle=RegisterEventSource(NULL,MAGICKCORE_PACKAGE_NAME);
1737 return(MagickFalse);
1739 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
1740 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
1741 DeregisterEventSource(handle);
1746 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1750 % N T R e s o u r c e T o B l o b %
1754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1756 % NTResourceToBlob() returns a blob containing the contents of the resource
1757 % in the current executable specified by the id parameter. This currently
1758 % used to retrieve MGK files tha have been embedded into the various command
1761 % The format of the NTResourceToBlob method is:
1763 % unsigned char *NTResourceToBlob(const char *id)
1765 % A description of each parameter follows:
1767 % o id: Specifies a string that identifies the resource.
1770 MagickExport unsigned char *NTResourceToBlob(const char *id)
1773 path[MaxTextExtent];
1791 assert(id != (const char *) NULL);
1792 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
1793 (void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",GetClientPath(),
1794 DirectorySeparator,GetClientName());
1795 if (IsPathAccessible(path) != MagickFalse)
1796 handle=GetModuleHandle(path);
1798 handle=GetModuleHandle(0);
1800 return((unsigned char *) NULL);
1801 resource=FindResource(handle,id,"IMAGEMAGICK");
1803 return((unsigned char *) NULL);
1804 global=LoadResource(handle,resource);
1806 return((unsigned char *) NULL);
1807 length=SizeofResource(handle,resource);
1808 value=(unsigned char *) LockResource(global);
1811 FreeResource(global);
1812 return((unsigned char *) NULL);
1814 blob=(unsigned char *) AcquireQuantumMemory(length+MaxTextExtent,
1816 if (blob != (unsigned char *) NULL)
1818 (void) CopyMagickMemory(blob,value,length);
1821 UnlockResource(global);
1822 FreeResource(global);
1827 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1831 % N T S e e k D i r e c t o r y %
1835 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1837 % NTSeekDirectory() sets the position of the next NTReadDirectory() operation
1838 % on the directory stream.
1840 % The format of the NTSeekDirectory method is:
1842 % void NTSeekDirectory(DIR *entry,ssize_t position)
1844 % A description of each parameter follows:
1846 % o entry: Specifies a pointer to a DIR structure.
1848 % o position: specifies the position associated with the directory
1852 MagickExport void NTSeekDirectory(DIR *entry,ssize_t position)
1855 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1856 assert(entry != (DIR *) NULL);
1860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1864 % N T S e t S e a r c h P a t h %
1868 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1870 % NTSetSearchPath() sets the current locations that the subsystem should
1871 % look at to find dynamically loadable modules.
1873 % The format of the NTSetSearchPath method is:
1875 % int NTSetSearchPath(const char *path)
1877 % A description of each parameter follows:
1879 % o path: Specifies a pointer to string representing the search path
1880 % for DLL's that can be dynamically loaded.
1883 MagickExport int NTSetSearchPath(const char *path)
1885 #if defined(MAGICKCORE_LTDL_DELEGATE)
1886 lt_dlsetsearchpath(path);
1888 if (lt_slsearchpath != (char *) NULL)
1889 lt_slsearchpath=DestroyString(lt_slsearchpath);
1890 if (path != (char *) NULL)
1891 lt_slsearchpath=AcquireString(path);
1897 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1901 + N T S y n c M e m o r y %
1905 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1907 % NTSyncMemory() emulates the Unix method of the same name.
1909 % The format of the NTSyncMemory method is:
1911 % int NTSyncMemory(void *address,size_t length,int flags)
1913 % A description of each parameter follows:
1915 % o address: the address of the binary large object.
1917 % o length: the length of the binary large object.
1919 % o flags: Option flags (ignored for Windows).
1922 MagickExport int NTSyncMemory(void *address,size_t length,int flags)
1925 if (FlushViewOfFile(address,length) == MagickFalse)
1931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1935 % N T S y s t e m C o m m a n d %
1939 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1941 % NTSystemCommand() executes the specified command and waits until it
1942 % terminates. The returned value is the exit status of the command.
1944 % The format of the NTSystemCommand method is:
1946 % int NTSystemCommand(MagickFalse,const char *command)
1948 % A description of each parameter follows:
1950 % o command: This string is the command to execute.
1953 MagickExport int NTSystemCommand(const char *command)
1956 local_command[MaxTextExtent];
1973 if (command == (char *) NULL)
1975 GetStartupInfo(&startup_info);
1976 startup_info.dwFlags=STARTF_USESHOWWINDOW;
1977 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
1978 (void) CopyMagickString(local_command,command,MaxTextExtent);
1979 background_process=command[strlen(command)-1] == '&' ? MagickTrue :
1981 if (background_process)
1982 local_command[strlen(command)-1]='\0';
1983 if (command[strlen(command)-1] == '|')
1984 local_command[strlen(command)-1]='\0';
1986 startup_info.wShowWindow=SW_SHOWDEFAULT;
1987 status=CreateProcess((LPCTSTR) NULL,local_command,
1988 (LPSECURITY_ATTRIBUTES) NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) FALSE,
1989 (DWORD) NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
1993 if (background_process)
1994 return(status == 0);
1995 status=WaitForSingleObject(process_info.hProcess,INFINITE);
1996 if (status != WAIT_OBJECT_0)
1998 status=GetExitCodeProcess(process_info.hProcess,&child_status);
2001 CloseHandle(process_info.hProcess);
2002 CloseHandle(process_info.hThread);
2003 return((int) child_status);
2007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2011 % N T S y s t e m C o n i f i g u r a t i o n %
2015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2017 % NTSystemConfiguration() provides a way for the application to determine
2018 % values for system limits or options at runtime.
2020 % The format of the exit method is:
2022 % ssize_t NTSystemConfiguration(int name)
2024 % A description of each parameter follows:
2026 % o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
2029 MagickExport ssize_t NTSystemConfiguration(int name)
2038 GetSystemInfo(&system_info);
2039 return(system_info.dwPageSize);
2041 case _SC_PHYS_PAGES:
2055 handle=GetModuleHandle("kernel32.dll");
2056 if (handle == (HMODULE) NULL)
2058 GetSystemInfo(&system_info);
2059 module=(LPFNDLLFUNC2) NTGetLibrarySymbol(handle,"GlobalMemoryStatusEx");
2060 if (module == (LPFNDLLFUNC2) NULL)
2065 GlobalMemoryStatus(&status);
2066 return((ssize_t) status.dwTotalPhys/system_info.dwPageSize);
2068 status.dwLength=sizeof(status);
2069 if (module(&status) == 0)
2071 return((ssize_t) status.ullTotalPhys/system_info.dwPageSize);
2082 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2086 % N T T e l l D i r e c t o r y %
2090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2092 % NTTellDirectory() returns the current location associated with the named
2095 % The format of the NTTellDirectory method is:
2097 % ssize_t NTTellDirectory(DIR *entry)
2099 % A description of each parameter follows:
2101 % o entry: Specifies a pointer to a DIR structure.
2104 MagickExport ssize_t NTTellDirectory(DIR *entry)
2106 assert(entry != (DIR *) NULL);
2111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2115 % N T T r u n c a t e F i l e %
2119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2121 % NTTruncateFile() truncates a file to a specified length.
2123 % The format of the NTTruncateFile method is:
2125 % int NTTruncateFile(int file,off_t length)
2127 % A description of each parameter follows:
2131 % o length: the file length.
2134 MagickExport int NTTruncateFile(int file,off_t length)
2144 file_handle=_get_osfhandle(file);
2145 if (file_handle == -1L)
2147 low=(long) (length & 0xffffffffUL);
2148 high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
2149 file_pointer=SetFilePointer((HANDLE) file_handle,low,&high,FILE_BEGIN);
2150 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
2152 if (SetEndOfFile((HANDLE) file_handle) == 0)
2158 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2162 + N T U n m a p M e m o r y %
2166 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2168 % NTUnmapMemory() emulates the Unix munmap method.
2170 % The format of the NTUnmapMemory method is:
2172 % int NTUnmapMemory(void *map,size_t length)
2174 % A description of each parameter follows:
2176 % o map: the address of the binary large object.
2178 % o length: the length of the binary large object.
2181 MagickExport int NTUnmapMemory(void *map,size_t length)
2184 if (UnmapViewOfFile(map) == 0)
2190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2194 % N T U s e r T i m e %
2198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2200 % NTUserTime() returns the total time the process has been scheduled (e.g.
2201 % seconds) since the last call to StartTimer().
2203 % The format of the UserTime method is:
2205 % double NTUserTime(void)
2208 MagickExport double NTUserTime(void)
2238 OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
2239 GetVersionEx(&OsVersionInfo);
2240 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
2241 return(NTElapsedTime());
2242 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
2243 &kernel_time.filetime,&user_time.filetime);
2246 return((double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
2250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2254 % N T W a r n i n g H a n d l e r %
2258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2260 % NTWarningHandler() displays a warning reason.
2262 % The format of the NTWarningHandler method is:
2264 % void NTWarningHandler(const ExceptionType severity,const char *reason,
2265 % const char *description)
2267 % A description of each parameter follows:
2269 % o severity: Specifies the numeric warning category.
2271 % o reason: Specifies the reason to display before terminating the
2274 % o description: Specifies any description to the reason.
2277 MagickExport void NTWarningHandler(const ExceptionType severity,
2278 const char *reason,const char *description)
2281 buffer[2*MaxTextExtent];
2284 if (reason == (char *) NULL)
2286 if (description == (char *) NULL)
2287 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s.\n",GetClientName(),
2290 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s (%s).\n",
2291 GetClientName(),reason,description);
2292 (void) MessageBox(NULL,buffer,"ImageMagick Warning",MB_OK | MB_TASKMODAL |
2293 MB_SETFOREGROUND | MB_ICONINFORMATION);