2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Windows NT Utility Methods for MagickCore %
20 % Copyright 1999-2010 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 "magick/studio.h"
42 #if defined(__WINDOWS__)
43 #include "magick/client.h"
44 #include "magick/log.h"
45 #include "magick/magick.h"
46 #include "magick/memory_.h"
47 #include "magick/resource_.h"
48 #include "magick/timer.h"
49 #include "magick/string_.h"
50 #include "magick/utility.h"
51 #include "magick/version.h"
52 #if defined(MAGICKCORE_LTDL_DELEGATE)
55 #include "magick/nt-base.h"
56 #if defined(MAGICKCORE_CIPHER_SUPPORT)
64 #if !defined(MAP_FAILED)
65 #define MAP_FAILED ((void *) -1)
71 #if !defined(MAGICKCORE_LTDL_DELEGATE)
73 *lt_slsearchpath = (char *) NULL;
80 *ghost_handle = (void *) NULL;
83 External declarations.
85 #if !defined(__WINDOWS__)
86 extern "C" BOOL WINAPI
87 DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved);
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 % DllMain() is an entry point to the DLL which is called when processes and
102 % threads are initialized and terminated, or upon calls to the Windows
103 % LoadLibrary and FreeLibrary functions.
105 % The function returns TRUE of it succeeds, or FALSE if initialization fails.
107 % The format of the DllMain method is:
109 % BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
111 % A description of each parameter follows:
113 % o handle: handle to the DLL module
115 % o reason: reason for calling function:
117 % DLL_PROCESS_ATTACH - DLL is being loaded into virtual address
118 % space of current process.
119 % DLL_THREAD_ATTACH - Indicates that the current process is
120 % creating a new thread. Called under the
121 % context of the new thread.
122 % DLL_THREAD_DETACH - Indicates that the thread is exiting.
123 % Called under the context of the exiting
125 % DLL_PROCESS_DETACH - Indicates that the DLL is being unloaded
126 % from the virtual address space of the
129 % o lpvReserved: Used for passing additional info during DLL_PROCESS_ATTACH
130 % and DLL_PROCESS_DETACH.
133 #if defined(_DLL) && defined( ProvideDllMain )
134 BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
138 case DLL_PROCESS_ATTACH:
146 module_path=(char *) AcquireQuantumMemory(MaxTextExtent,
147 sizeof(*module_path));
148 if (module_path == (char *) NULL)
150 count=(ssize_t) GetModuleFileName(handle,module_path,MaxTextExtent);
156 for ( ; count > 0; count--)
157 if (module_path[count] == '\\')
159 module_path[count+1]='\0';
162 MagickCoreGenesis(module_path,MagickFalse);
163 path=(char *) AcquireQuantumMemory(16UL*MaxTextExtent,sizeof(*path));
164 if (path == (char *) NULL)
166 module_path=DestroyString(module_path);
169 count=(ssize_t) GetEnvironmentVariable("PATH",path,16*MaxTextExtent);
170 if ((count != 0) && (strstr(path,module_path) == (char *) NULL))
172 if ((strlen(module_path)+count+1) < (16*MaxTextExtent-1))
177 variable=(char *) AcquireQuantumMemory(16UL*MaxTextExtent,
179 if (variable == (char *) NULL)
181 path=DestroyString(path);
182 module_path=DestroyString(module_path);
185 (void) FormatMagickString(variable,16*MaxTextExtent,
186 "%s;%s",module_path,path);
187 SetEnvironmentVariable("PATH",variable);
188 variable=DestroyString(variable);
191 path=DestroyString(path);
193 module_path=DestroyString(module_path);
196 case DLL_PROCESS_DETACH:
198 MagickCoreTerminus();
209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219 % Exit() calls TerminateProcess for Win95.
221 % The format of the exit method is:
223 % int Exit(int status)
225 % A description of each parameter follows:
227 % o status: an integer value representing the status of the terminating
231 MagickExport int Exit(int status)
234 TerminateProcess(GetCurrentProcess(),(unsigned int) status);
240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 % g e t t i m e o f d a y %
248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 % The gettimeofday() method get the time of day.
252 % The format of the gettimeofday method is:
254 % int gettimeofday(struct timeval *time_value,struct timezone *time_zone)
256 % A description of each parameter follows:
258 % o time_value: the time value.
260 % o time_zone: the time zone.
263 #if !defined(__MINGW32__)
264 MagickExport int gettimeofday (struct timeval *time_value,
265 struct timezone *time_zone)
267 #define EpochFiletime MagickLLConstant(116444736000000000)
272 if (time_value != (struct timeval *) NULL)
283 GetSystemTimeAsFileTime(&file_time);
284 date_time.LowPart=file_time.dwLowDateTime;
285 date_time.HighPart=file_time.dwHighDateTime;
286 time=date_time.QuadPart;
289 time_value->tv_sec=(long) (time / 1000000);
290 time_value->tv_usec=(long) (time % 1000000);
292 if (time_zone != (struct timezone *) NULL)
299 time_zone->tz_minuteswest=_timezone/60;
300 time_zone->tz_dsttime=_daylight;
307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 % I s W i n d o w s 9 5 %
315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
317 % IsWindows95() returns true if the system is Windows 95.
319 % The format of the IsWindows95 method is:
324 MagickExport int IsWindows95()
329 version_info.dwOSVersionInfoSize=sizeof(version_info);
330 if (GetVersionEx(&version_info) &&
331 (version_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS))
337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341 % N T C l o s e D i r e c t o r y %
345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347 % NTCloseDirectory() closes the named directory stream and frees the DIR
350 % The format of the NTCloseDirectory method is:
352 % int NTCloseDirectory(DIR *entry)
354 % A description of each parameter follows:
356 % o entry: Specifies a pointer to a DIR structure.
359 MagickExport int NTCloseDirectory(DIR *entry)
361 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
362 assert(entry != (DIR *) NULL);
363 FindClose(entry->hSearch);
364 entry=(DIR *) RelinquishMagickMemory(entry);
369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
373 % N T C l o s e L i b r a r y %
377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 % NTCloseLibrary() unloads the module associated with the passed handle.
381 % The format of the NTCloseLibrary method is:
383 % void NTCloseLibrary(void *handle)
385 % A description of each parameter follows:
387 % o handle: Specifies a handle to a previously loaded dynamic module.
390 MagickExport int NTCloseLibrary(void *handle)
393 return(FreeLibrary((HINSTANCE) handle));
394 return(!(FreeLibrary((HINSTANCE) handle)));
398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402 % N T C o n t r o l H a n d l e r %
406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
408 % NTControlHandler() registers a control handler that is activated when, for
409 % example, a ctrl-c is received.
411 % The format of the NTControlHandler method is:
413 % int NTControlHandler(void)
417 static BOOL ControlHandler(DWORD type)
420 AsynchronousResourceComponentTerminus();
424 MagickExport int NTControlHandler(void)
426 return(SetConsoleCtrlHandler((PHANDLER_ROUTINE) ControlHandler,TRUE));
430 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
434 % N T E l a p s e d T i m e %
438 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
440 % NTElapsedTime() returns the elapsed time (in seconds) since the last call to
443 % The format of the ElapsedTime method is:
445 % double NTElapsedTime(void)
448 MagickExport double NTElapsedTime(void)
462 GetSystemTime(&system_time);
463 SystemTimeToFileTime(&system_time,&elapsed_time.filetime);
464 return((double) 1.0e-7*elapsed_time.filetime64);
468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
472 + N T E r r o r H a n d l e r %
476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
478 % NTErrorHandler() displays an error reason and then terminates the program.
480 % The format of the NTErrorHandler method is:
482 % void NTErrorHandler(const ExceptionType severity,const char *reason,
483 % const char *description)
485 % A description of each parameter follows:
487 % o severity: Specifies the numeric error category.
489 % o reason: Specifies the reason to display before terminating the
492 % o description: Specifies any description to the reason.
495 MagickExport void NTErrorHandler(const ExceptionType severity,
496 const char *reason,const char *description)
499 buffer[3*MaxTextExtent],
503 if (reason == (char *) NULL)
505 MagickCoreTerminus();
508 message=GetExceptionMessage(errno);
509 if ((description != (char *) NULL) && errno)
510 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s (%s) [%s].\n",
511 GetClientName(),reason,description,message);
513 if (description != (char *) NULL)
514 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s (%s).\n",
515 GetClientName(),reason,description);
518 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s [%s].\n",
519 GetClientName(),reason,message);
521 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s.\n",
522 GetClientName(),reason);
523 message=DestroyString(message);
524 (void) MessageBox(NULL,buffer,"ImageMagick Exception",MB_OK | MB_TASKMODAL |
525 MB_SETFOREGROUND | MB_ICONEXCLAMATION);
526 MagickCoreTerminus();
531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
535 % N T E x i t L i b r a r y %
539 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
541 % NTExitLibrary() exits the dynamic module loading subsystem.
543 % The format of the NTExitLibrary method is:
545 % int NTExitLibrary(void)
548 MagickExport int NTExitLibrary(void)
554 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
558 % N T G a t h e r R a n d o m D a t a %
562 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
564 % NTGatherRandomData() gathers random data and returns it.
566 % The format of the GatherRandomData method is:
568 % MagickBooleanType NTGatherRandomData(const size_t length,
569 % unsigned char *random)
571 % A description of each parameter follows:
573 % length: the length of random data buffer
575 % random: the random data is returned here.
578 MagickExport MagickBooleanType NTGatherRandomData(const size_t length,
579 unsigned char *random)
581 #if defined(MAGICKCORE_CIPHER_SUPPORT) && defined(_MSC_VER) && (_MSC_VER > 1200)
588 handle=(HCRYPTPROV) NULL;
589 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
590 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET));
592 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
593 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET));
596 status=CryptGenRandom(handle,(DWORD) length,random);
599 status=CryptReleaseContext(handle,0);
602 status=CryptReleaseContext(handle,0);
613 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
617 % N T G e t E x e c u t i o n P a t h %
621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
623 % NTGetExecutionPath() returns the execution path of a program.
625 % The format of the GetExecutionPath method is:
627 % MagickBooleanType NTGetExecutionPath(char *path,const size_t extent)
629 % A description of each parameter follows:
631 % o path: the pathname of the executable that started the process.
633 % o extent: the maximum extent of the path.
636 MagickExport MagickBooleanType NTGetExecutionPath(char *path,
639 GetModuleFileName(0,path,(DWORD) extent);
644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
648 % N T G e t L a s t E r r o r %
652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654 % NTGetLastError() returns the last error that occurred.
656 % The format of the NTGetLastError method is:
658 % char *NTGetLastError(void)
661 char *NTGetLastError(void)
672 status=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
673 FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),
674 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR) &buffer,0,NULL);
676 reason=AcquireString("An unknown error occurred");
679 reason=AcquireString((const char *) buffer);
686 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
690 % N T G e t L i b r a r y E r r o r %
694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
696 % Lt_dlerror() returns a pointer to a string describing the last error
697 % associated with a lt_dl method. Note that this function is not thread
698 % safe so it should only be used under the protection of a lock.
700 % The format of the NTGetLibraryError method is:
702 % const char *NTGetLibraryError(void)
705 MagickExport const char *NTGetLibraryError(void)
708 last_error[MaxTextExtent];
714 error=NTGetLastError();
716 (void) CopyMagickString(last_error,error,MaxTextExtent);
717 error=DestroyString(error);
722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
726 % N T G e t L i b r a r y S y m b o l %
730 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
732 % NTGetLibrarySymbol() retrieve the procedure address of the method
733 % specified by the passed character string.
735 % The format of the NTGetLibrarySymbol method is:
737 % void *NTGetLibrarySymbol(void *handle,const char *name)
739 % A description of each parameter follows:
741 % o handle: Specifies a handle to the previously loaded dynamic module.
743 % o name: Specifies the procedure entry point to be returned.
746 void *NTGetLibrarySymbol(void *handle,const char *name)
751 lpfnDllFunc1=(LPFNDLLFUNC1) GetProcAddress((HINSTANCE) handle,name);
753 return((void *) NULL);
754 return((void *) lpfnDllFunc1);
758 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
762 % N T G e t M o d u l e P a t h %
766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
768 % NTGetModulePath() returns the path of the specified module.
770 % The format of the GetModulePath method is:
772 % MagickBooleanType NTGetModulePath(const char *module,char *path)
774 % A description of each parameter follows:
776 % modith: the module name.
778 % path: the module path is returned here.
781 MagickExport MagickBooleanType NTGetModulePath(const char *module,char *path)
784 module_path[MaxTextExtent];
793 handle=GetModuleHandle(module);
794 if (handle == (HMODULE) NULL)
796 length=GetModuleFileName(handle,module_path,MaxTextExtent);
798 GetPathComponent(module_path,HeadPath,path);
803 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
807 % N T G h o s t s c r i p t D L L %
811 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
813 % NTGhostscriptDLL() returns the path to the most recent Ghostscript version
814 % DLL. The method returns TRUE on success otherwise FALSE.
816 % The format of the NTGhostscriptDLL method is:
818 % int NTGhostscriptDLL(char *path,int length)
820 % A description of each parameter follows:
822 % o path: return the Ghostscript DLL path here.
824 % o length: the buffer length.
828 static int NTGetRegistryValue(HKEY root,const char *key,const char *name,
829 char *value,int *length)
846 Get a registry value: key = root\\key, named value = name.
848 if (RegOpenKeyExA(root,key,0,KEY_READ,&hkey) != ERROR_SUCCESS)
849 return(1); /* no match */
853 if (p == (BYTE *) NULL)
854 p=(&byte); /* ERROR_MORE_DATA only if value is NULL */
855 status=RegQueryValueExA(hkey,(char *) name,0,&type,p,&extent);
857 if (status == ERROR_SUCCESS)
860 return(0); /* return the match */
862 if (status == ERROR_MORE_DATA)
865 return(-1); /* buffer not large enough */
867 return(1); /* not found */
870 static int NTLocateGhostscript(const char **product_family,int *major_version,
885 "Aladdin Ghostscript"
889 Find the most recent version of Ghostscript.
892 *product_family=NULL;
894 *minor_version=49; /* min version of Ghostscript is 5.50 */
895 for (i=0; i < (long) (sizeof(products)/sizeof(products[0])); i++)
907 (void) FormatMagickString(key,MaxTextExtent,"SOFTWARE\\%s",products[i]);
908 root=HKEY_LOCAL_MACHINE;
910 #if defined(KEY_WOW64_32KEY)
911 mode|=KEY_WOW64_32KEY;
913 if (RegOpenKeyExA(root,key,0,mode,&hkey) == ERROR_SUCCESS)
922 Now enumerate the keys.
924 extent=sizeof(key)/sizeof(char);
925 for (j=0; RegEnumKeyA(hkey,j,key,extent) == ERROR_SUCCESS; j++)
933 if (sscanf(key,"%d.%d",&major,&minor) != 2)
935 if ((major > *major_version) || ((major == *major_version) &&
936 (minor > *minor_version)))
938 *product_family=products[i];
939 *major_version=major;
940 *minor_version=minor;
944 (void) RegCloseKey(hkey);
953 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"Ghostscript (%s) "
954 "version %d.%02d",*product_family,*major_version,*minor_version);
958 static int NTGhostscriptGetString(const char *name,char *value,
969 *product_family = (const char *) NULL;
985 { HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
986 { HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" }
990 Get a string from the installed Ghostscript.
993 if (product_family == NULL)
994 (void) NTLocateGhostscript(&product_family,&major_version,&minor_version);
995 if (product_family == NULL)
997 (void) FormatMagickString(key,MaxTextExtent,"SOFTWARE\\%s\\%d.%02d",
998 product_family,major_version,minor_version);
999 for (i=0; i < (long) (sizeof(hkeys)/sizeof(hkeys[0])); i++)
1001 extent=(int) length;
1002 if (NTGetRegistryValue(hkeys[i].hkey,key,name,value,&extent) == 0)
1004 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1005 "registry: \"%s\\%s\\%s\"=\"%s\"",hkeys[i].name,key,name,value);
1008 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1009 "registry: \"%s\\%s\\%s\" (failed)",hkeys[i].name,key,name);
1014 MagickExport int NTGhostscriptDLL(char *path,int length)
1017 dll[MaxTextExtent] = { "" };
1020 if ((*dll == '\0') &&
1021 (NTGhostscriptGetString("GS_DLL",dll,sizeof(dll)) == FALSE))
1023 (void) CopyMagickString(path,dll,length);
1028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1032 % N T G h o s t s c r i p t D L L V e c t o r s %
1036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1038 % NTGhostscriptDLLVectors() returns a GhostInfo structure that includes
1039 % function vectors to invoke Ghostscript DLL functions. A null pointer is
1040 % returned if there is an error when loading the DLL or retrieving the
1043 % The format of the NTGhostscriptDLLVectors method is:
1045 % const GhostInfo *NTGhostscriptDLLVectors(void)
1048 MagickExport const GhostInfo *NTGhostscriptDLLVectors(void)
1050 if (NTGhostscriptLoadDLL() == FALSE)
1051 return((GhostInfo *) NULL);
1052 return(&ghost_info);
1056 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1060 % N T G h o s t s c r i p t E X E %
1064 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1066 % NTGhostscriptEXE() obtains the path to the latest Ghostscript executable.
1067 % The method returns FALSE if a full path value is not obtained and returns
1068 % a default path of gswin32c.exe.
1070 % The format of the NTGhostscriptEXE method is:
1072 % int NTGhostscriptEXE(char *path,int length)
1074 % A description of each parameter follows:
1076 % o path: return the Ghostscript executable path here.
1078 % o length: length of buffer.
1081 MagickExport int NTGhostscriptEXE(char *path,int length)
1087 program[MaxTextExtent] = { "" };
1089 (void) CopyMagickString(path,"gswin32c.exe",length);
1090 if ((*program == '\0') &&
1091 (NTGhostscriptGetString("GS_DLL",program,sizeof(program)) == FALSE))
1093 p=strrchr(program,'\\');
1094 if (p != (char *) NULL)
1098 (void) ConcatenateMagickString(program,"gswin32c.exe",sizeof(program));
1100 (void) CopyMagickString(path,program,length);
1105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1109 % N T G h o s t s c r i p t F o n t s %
1113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1115 % NTGhostscriptFonts() obtains the path to the Ghostscript fonts. The method
1116 % returns FALSE if it cannot determine the font path.
1118 % The format of the NTGhostscriptFonts method is:
1120 % int NTGhostscriptFonts(char *path, int length)
1122 % A description of each parameter follows:
1124 % o path: return the font path here.
1126 % o length: length of the path buffer.
1129 MagickExport int NTGhostscriptFonts(char *path,int length)
1132 buffer[MaxTextExtent],
1133 filename[MaxTextExtent];
1140 if (NTGhostscriptGetString("GS_LIB",buffer,MaxTextExtent) == FALSE)
1142 for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
1144 (void) CopyMagickString(path,p+1,length+1);
1145 q=strchr(path,DirectoryListSeparator);
1146 if (q != (char *) NULL)
1148 (void) FormatMagickString(filename,MaxTextExtent,"%s%sfonts.dir",path,
1149 DirectorySeparator);
1150 if (IsPathAccessible(filename) != MagickFalse)
1157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1161 % N T G h o s t s c r i p t L o a d D L L %
1165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1167 % NTGhostscriptLoadDLL() attempts to load the Ghostscript DLL and returns
1168 % TRUE if it succeeds.
1170 % The format of the NTGhostscriptLoadDLL method is:
1172 % int NTGhostscriptLoadDLL(void)
1175 MagickExport int NTGhostscriptLoadDLL(void)
1178 path[MaxTextExtent];
1180 if (ghost_handle != (void *) NULL)
1182 if (NTGhostscriptDLL(path,sizeof(path)) == FALSE)
1184 ghost_handle=lt_dlopen(path);
1185 if (ghost_handle == (void *) NULL)
1187 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1188 ghost_info.exit=(int (MagickDLLCall *)(gs_main_instance*))
1189 lt_dlsym(ghost_handle,"gsapi_exit");
1190 ghost_info.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,int,
1191 char **)) (lt_dlsym(ghost_handle,"gsapi_init_with_args"));
1192 ghost_info.new_instance=(int (MagickDLLCall *)(gs_main_instance **,void *)) (
1193 lt_dlsym(ghost_handle,"gsapi_new_instance"));
1194 ghost_info.run_string=(int (MagickDLLCall *)(gs_main_instance *,const char *,
1195 int,int *)) (lt_dlsym(ghost_handle,"gsapi_run_string"));
1196 ghost_info.delete_instance=(void (MagickDLLCall *) (gs_main_instance *)) (
1197 lt_dlsym(ghost_handle,"gsapi_delete_instance"));
1198 if ((ghost_info.exit == NULL) || (ghost_info.init_with_args == NULL) ||
1199 (ghost_info.new_instance == NULL) || (ghost_info.run_string == NULL) ||
1200 (ghost_info.delete_instance == NULL))
1206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1210 % N T G h o s t s c r i p t U n L o a d D L L %
1214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1216 % NTGhostscriptUnLoadDLL() unloads the Ghostscript DLL and returns TRUE if
1219 % The format of the NTGhostscriptUnLoadDLL method is:
1221 % int NTGhostscriptUnLoadDLL(void)
1224 MagickExport int NTGhostscriptUnLoadDLL(void)
1229 if (ghost_handle == (void *) NULL)
1231 status=lt_dlclose(ghost_handle);
1232 ghost_handle=(void *) NULL;
1233 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1242 % N T I n i t i a l i z e L i b r a r y %
1246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1248 % NTInitializeLibrary() initializes the dynamic module loading subsystem.
1250 % The format of the NTInitializeLibrary method is:
1252 % int NTInitializeLibrary(void)
1255 MagickExport int NTInitializeLibrary(void)
1261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1265 + N T M a p M e m o r y %
1269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1271 % Mmap() emulates the Unix method of the same name.
1273 % The format of the NTMapMemory method is:
1275 % MagickExport void *NTMapMemory(char *address,size_t length,int protection,
1276 % int access,int file,MagickOffsetType offset)
1279 MagickExport void *NTMapMemory(char *address,size_t length,int protection,
1280 int flags,int file,MagickOffsetType offset)
1299 file_handle=INVALID_HANDLE_VALUE;
1300 low_length=(DWORD) (length & 0xFFFFFFFFUL);
1301 high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
1302 map_handle=INVALID_HANDLE_VALUE;
1304 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
1305 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
1307 if (protection & PROT_WRITE)
1309 access_mode=FILE_MAP_WRITE;
1310 if (!(flags & MAP_PRIVATE))
1311 protection_mode=PAGE_READWRITE;
1314 access_mode=FILE_MAP_COPY;
1315 protection_mode=PAGE_WRITECOPY;
1319 if (protection & PROT_READ)
1321 access_mode=FILE_MAP_READ;
1322 protection_mode=PAGE_READONLY;
1324 if ((file == -1) && (flags & MAP_ANONYMOUS))
1325 file_handle=INVALID_HANDLE_VALUE;
1327 file_handle=(HANDLE) _get_osfhandle(file);
1328 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
1332 map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
1334 CloseHandle(map_handle);
1336 if (map == (void *) NULL)
1337 return((void *) MAP_FAILED);
1338 return((void *) ((char *) map));
1342 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1346 % N T O p e n D i r e c t o r y %
1350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1352 % NTOpenDirectory() opens the directory named by filename and associates a
1353 % directory stream with it.
1355 % The format of the NTOpenDirectory method is:
1357 % DIR *NTOpenDirectory(const char *path)
1359 % A description of each parameter follows:
1361 % o entry: Specifies a pointer to a DIR structure.
1364 MagickExport DIR *NTOpenDirectory(const char *path)
1367 file_specification[MaxTextExtent];
1375 assert(path != (const char *) NULL);
1376 length=CopyMagickString(file_specification,path,MaxTextExtent);
1377 if (length >= MaxTextExtent)
1378 return((DIR *) NULL);
1379 length=ConcatenateMagickString(file_specification,DirectorySeparator,
1381 if (length >= MaxTextExtent)
1382 return((DIR *) NULL);
1383 entry=(DIR *) AcquireAlignedMemory(1,sizeof(DIR));
1384 if (entry != (DIR *) NULL)
1386 entry->firsttime=TRUE;
1387 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1389 if (entry->hSearch == INVALID_HANDLE_VALUE)
1391 length=ConcatenateMagickString(file_specification,"\\*.*",MaxTextExtent);
1392 if (length >= MaxTextExtent)
1394 entry=(DIR *) RelinquishMagickMemory(entry);
1395 return((DIR *) NULL);
1397 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1398 if (entry->hSearch == INVALID_HANDLE_VALUE)
1400 entry=(DIR *) RelinquishMagickMemory(entry);
1401 return((DIR *) NULL);
1408 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1412 % N T O p e n L i b r a r y %
1416 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1418 % NTOpenLibrary() loads a dynamic module into memory and returns a handle that
1419 % can be used to access the various procedures in the module.
1421 % The format of the NTOpenLibrary method is:
1423 % void *NTOpenLibrary(const char *filename)
1425 % A description of each parameter follows:
1427 % o path: Specifies a pointer to string representing dynamic module that
1432 static const char *GetSearchPath( void )
1434 #if defined(MAGICKCORE_LTDL_DELEGATE)
1435 return(lt_dlgetsearchpath());
1437 return(lt_slsearchpath);
1441 MagickExport void *NTOpenLibrary(const char *filename)
1443 #define MaxPathElements 31
1446 buffer[MaxTextExtent];
1464 mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
1465 handle=(void *) LoadLibraryEx(filename,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1466 if ((handle != (void *) NULL) || (GetSearchPath() == (char *) NULL))
1471 p=(char *) GetSearchPath();
1473 while (index < MaxPathElements)
1475 q=strchr(p,DirectoryListSeparator);
1476 if (q == (char *) NULL)
1478 (void) CopyMagickString(buffer,p,MaxTextExtent);
1479 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
1480 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
1481 handle=(void *) LoadLibraryEx(buffer,NULL,
1482 LOAD_WITH_ALTERED_SEARCH_PATH);
1486 (void) CopyMagickString(buffer,p,i+1);
1487 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
1488 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
1489 handle=(void *) LoadLibraryEx(buffer,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1490 if (handle != (void *) NULL)
1499 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1503 % N T R e a d D i r e c t o r y %
1507 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1509 % NTReadDirectory() returns a pointer to a structure representing the
1510 % directory entry at the current position in the directory stream to which
1513 % The format of the NTReadDirectory
1515 % NTReadDirectory(entry)
1517 % A description of each parameter follows:
1519 % o entry: Specifies a pointer to a DIR structure.
1522 MagickExport struct dirent *NTReadDirectory(DIR *entry)
1530 if (entry == (DIR *) NULL)
1531 return((struct dirent *) NULL);
1532 if (!entry->firsttime)
1534 status=FindNextFile(entry->hSearch,&entry->Win32FindData);
1536 return((struct dirent *) NULL);
1538 length=CopyMagickString(entry->file_info.d_name,
1539 entry->Win32FindData.cFileName,sizeof(entry->file_info.d_name));
1540 if (length >= sizeof(entry->file_info.d_name))
1541 return((struct dirent *) NULL);
1542 entry->firsttime=FALSE;
1543 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
1544 return(&entry->file_info);
1548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1552 % N T R e g i s t r y K e y L o o k u p %
1556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1558 % NTRegistryKeyLookup() returns ImageMagick installation path settings
1559 % stored in the Windows Registry. Path settings are specific to the
1560 % installed ImageMagick version so that multiple Image Magick installations
1563 % Values are stored in the registry under a base path path similar to
1564 % "HKEY_LOCAL_MACHINE/SOFTWARE\ImageMagick\5.5.7\Q:16". The provided subkey
1565 % is appended to this base path to form the full key.
1567 % The format of the NTRegistryKeyLookup method is:
1569 % unsigned char *NTRegistryKeyLookup(const char *subkey)
1571 % A description of each parameter follows:
1573 % o subkey: Specifies a string that identifies the registry object.
1574 % Currently supported sub-keys include: "BinPath", "ConfigurePath",
1575 % "LibPath", "CoderModulesPath", "FilterModulesPath", "SharePath".
1578 MagickExport unsigned char *NTRegistryKeyLookup(const char *subkey)
1581 package_key[MaxTextExtent];
1599 (void) FormatMagickString(package_key,MaxTextExtent,"SOFTWARE\\%s\\%s\\Q:%d",
1600 MagickPackageName,MagickLibVersionText,MAGICKCORE_QUANTUM_DEPTH);
1601 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",package_key);
1602 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1603 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,package_key,0,KEY_READ,®istry_key);
1604 if (status != ERROR_SUCCESS)
1606 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1607 return((unsigned char *) NULL);
1613 value=(unsigned char *) AcquireQuantumMemory(size,sizeof(*value));
1614 if (value == (unsigned char *) NULL)
1616 RegCloseKey(registry_key);
1617 return((unsigned char *) NULL);
1619 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",subkey);
1620 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1621 if ((status == ERROR_MORE_DATA) && (type == REG_SZ))
1623 value=(unsigned char *) ResizeQuantumMemory(value,size,sizeof(*value));
1624 if (value == (BYTE *) NULL)
1626 RegCloseKey(registry_key);
1627 return((unsigned char *) NULL);
1629 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1631 RegCloseKey(registry_key);
1632 if ((type != REG_SZ) || (status != ERROR_SUCCESS))
1633 value=(unsigned char *) RelinquishMagickMemory(value);
1634 return((unsigned char *) value);
1638 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1642 % N T R e p o r t E v e n t %
1646 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1648 % NTReportEvent() reports an event.
1650 % The format of the NTReportEvent method is:
1652 % MagickBooleanType NTReportEvent(const char *event,
1653 % const MagickBooleanType error)
1655 % A description of each parameter follows:
1657 % o event: the event.
1659 % o error: MagickTrue the event is an error.
1662 MagickExport MagickBooleanType NTReportEvent(const char *event,
1663 const MagickBooleanType error)
1674 handle=RegisterEventSource(NULL,MAGICKCORE_PACKAGE_NAME);
1676 return(MagickFalse);
1678 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
1679 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
1680 DeregisterEventSource(handle);
1685 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1689 % N T R e s o u r c e T o B l o b %
1693 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1695 % NTResourceToBlob() returns a blob containing the contents of the resource
1696 % in the current executable specified by the id parameter. This currently
1697 % used to retrieve MGK files tha have been embedded into the various command
1700 % The format of the NTResourceToBlob method is:
1702 % unsigned char *NTResourceToBlob(const char *id)
1704 % A description of each parameter follows:
1706 % o id: Specifies a string that identifies the resource.
1709 MagickExport unsigned char *NTResourceToBlob(const char *id)
1712 path[MaxTextExtent];
1730 assert(id != (const char *) NULL);
1731 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
1732 (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",GetClientPath(),
1733 DirectorySeparator,GetClientName());
1734 if (IsPathAccessible(path) != MagickFalse)
1735 handle=GetModuleHandle(path);
1737 handle=GetModuleHandle(0);
1739 return((unsigned char *) NULL);
1740 resource=FindResource(handle,id,"IMAGEMAGICK");
1742 return((unsigned char *) NULL);
1743 global=LoadResource(handle,resource);
1745 return((unsigned char *) NULL);
1746 length=SizeofResource(handle,resource);
1747 value=(unsigned char *) LockResource(global);
1750 FreeResource(global);
1751 return((unsigned char *) NULL);
1753 blob=(unsigned char *) AcquireQuantumMemory(length+MaxTextExtent,
1755 if (blob != (unsigned char *) NULL)
1757 (void) CopyMagickMemory(blob,value,length);
1760 UnlockResource(global);
1761 FreeResource(global);
1766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1770 % N T S e e k D i r e c t o r y %
1774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1776 % NTSeekDirectory() sets the position of the next NTReadDirectory() operation
1777 % on the directory stream.
1779 % The format of the NTSeekDirectory method is:
1781 % void NTSeekDirectory(DIR *entry,long position)
1783 % A description of each parameter follows:
1785 % o entry: Specifies a pointer to a DIR structure.
1787 % o position: specifies the position associated with the directory
1791 MagickExport void NTSeekDirectory(DIR *entry,long position)
1794 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1795 assert(entry != (DIR *) NULL);
1799 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1803 % N T S e t S e a r c h P a t h %
1807 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1809 % NTSetSearchPath() sets the current locations that the subsystem should
1810 % look at to find dynamically loadable modules.
1812 % The format of the NTSetSearchPath method is:
1814 % int NTSetSearchPath(const char *path)
1816 % A description of each parameter follows:
1818 % o path: Specifies a pointer to string representing the search path
1819 % for DLL's that can be dynamically loaded.
1822 MagickExport int NTSetSearchPath(const char *path)
1824 #if defined(MAGICKCORE_LTDL_DELEGATE)
1825 lt_dlsetsearchpath(path);
1827 if (lt_slsearchpath != (char *) NULL)
1828 lt_slsearchpath=DestroyString(lt_slsearchpath);
1829 if (path != (char *) NULL)
1830 lt_slsearchpath=AcquireString(path);
1836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1840 + N T S y n c M e m o r y %
1844 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1846 % NTSyncMemory() emulates the Unix method of the same name.
1848 % The format of the NTSyncMemory method is:
1850 % int NTSyncMemory(void *address,size_t length,int flags)
1852 % A description of each parameter follows:
1854 % o address: the address of the binary large object.
1856 % o length: the length of the binary large object.
1858 % o flags: Option flags (ignored for Windows).
1861 MagickExport int NTSyncMemory(void *address,size_t length,int flags)
1864 if (FlushViewOfFile(address,length) == MagickFalse)
1870 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1874 % N T S y s t e m C o m m a n d %
1878 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1880 % NTSystemCommand() executes the specified command and waits until it
1881 % terminates. The returned value is the exit status of the command.
1883 % The format of the NTSystemCommand method is:
1885 % int NTSystemCommand(MagickFalse,const char *command)
1887 % A description of each parameter follows:
1889 % o command: This string is the command to execute.
1892 MagickExport int NTSystemCommand(const char *command)
1895 local_command[MaxTextExtent];
1912 if (command == (char *) NULL)
1914 GetStartupInfo(&startup_info);
1915 startup_info.dwFlags=STARTF_USESHOWWINDOW;
1916 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
1917 (void) CopyMagickString(local_command,command,MaxTextExtent);
1918 background_process=command[strlen(command)-1] == '&' ? MagickTrue :
1920 if (background_process)
1921 local_command[strlen(command)-1]='\0';
1922 if (command[strlen(command)-1] == '|')
1923 local_command[strlen(command)-1]='\0';
1925 startup_info.wShowWindow=SW_SHOWDEFAULT;
1926 status=CreateProcess((LPCTSTR) NULL,local_command,
1927 (LPSECURITY_ATTRIBUTES) NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) FALSE,
1928 (DWORD) NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
1932 if (background_process)
1933 return(status == 0);
1934 status=WaitForSingleObject(process_info.hProcess,INFINITE);
1935 if (status != WAIT_OBJECT_0)
1937 status=GetExitCodeProcess(process_info.hProcess,&child_status);
1940 CloseHandle(process_info.hProcess);
1941 CloseHandle(process_info.hThread);
1942 return((int) child_status);
1946 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1950 % N T S y s t e m C o n i f i g u r a t i o n %
1954 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1956 % NTSystemConfiguration() provides a way for the application to determine
1957 % values for system limits or options at runtime.
1959 % The format of the exit method is:
1961 % long NTSystemConfiguration(int name)
1963 % A description of each parameter follows:
1965 % o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
1968 MagickExport long NTSystemConfiguration(int name)
1977 GetSystemInfo(&system_info);
1978 return(system_info.dwPageSize);
1980 case _SC_PHYS_PAGES:
1994 handle=GetModuleHandle("kernel32.dll");
1995 if (handle == (HMODULE) NULL)
1997 GetSystemInfo(&system_info);
1998 module=(LPFNDLLFUNC2) NTGetLibrarySymbol(handle,"GlobalMemoryStatusEx");
1999 if (module == (LPFNDLLFUNC2) NULL)
2004 GlobalMemoryStatus(&status);
2005 return((long) status.dwTotalPhys/system_info.dwPageSize);
2007 status.dwLength=sizeof(status);
2008 if (module(&status) == 0)
2010 return((long) status.ullTotalPhys/system_info.dwPageSize);
2021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2025 % N T T e l l D i r e c t o r y %
2029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2031 % NTTellDirectory() returns the current location associated with the named
2034 % The format of the NTTellDirectory method is:
2036 % long NTTellDirectory(DIR *entry)
2038 % A description of each parameter follows:
2040 % o entry: Specifies a pointer to a DIR structure.
2043 MagickExport long NTTellDirectory(DIR *entry)
2045 assert(entry != (DIR *) NULL);
2050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2054 % N T T r u n c a t e F i l e %
2058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2060 % NTTruncateFile() truncates a file to a specified length.
2062 % The format of the NTTruncateFile method is:
2064 % int NTTruncateFile(int file,off_t length)
2066 % A description of each parameter follows:
2070 % o length: the file length.
2073 MagickExport int NTTruncateFile(int file,off_t length)
2083 file_handle=_get_osfhandle(file);
2084 if (file_handle == -1L)
2086 low=(long) (length & 0xffffffffUL);
2087 high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
2088 file_pointer=SetFilePointer((HANDLE) file_handle,low,&high,FILE_BEGIN);
2089 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
2091 if (SetEndOfFile((HANDLE) file_handle) == 0)
2097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2101 + N T U n m a p M e m o r y %
2105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2107 % NTUnmapMemory() emulates the Unix munmap method.
2109 % The format of the NTUnmapMemory method is:
2111 % int NTUnmapMemory(void *map,size_t length)
2113 % A description of each parameter follows:
2115 % o map: the address of the binary large object.
2117 % o length: the length of the binary large object.
2120 MagickExport int NTUnmapMemory(void *map,size_t length)
2123 if (UnmapViewOfFile(map) == 0)
2129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2133 % N T U s e r T i m e %
2137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2139 % NTUserTime() returns the total time the process has been scheduled (e.g.
2140 % seconds) since the last call to StartTimer().
2142 % The format of the UserTime method is:
2144 % double NTUserTime(void)
2147 MagickExport double NTUserTime(void)
2177 OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
2178 GetVersionEx(&OsVersionInfo);
2179 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
2180 return(NTElapsedTime());
2181 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
2182 &kernel_time.filetime,&user_time.filetime);
2185 return((double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
2189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2193 % N T W a r n i n g H a n d l e r %
2197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2199 % NTWarningHandler() displays a warning reason.
2201 % The format of the NTWarningHandler method is:
2203 % void NTWarningHandler(const ExceptionType severity,const char *reason,
2204 % const char *description)
2206 % A description of each parameter follows:
2208 % o severity: Specifies the numeric warning category.
2210 % o reason: Specifies the reason to display before terminating the
2213 % o description: Specifies any description to the reason.
2216 MagickExport void NTWarningHandler(const ExceptionType severity,
2217 const char *reason,const char *description)
2220 buffer[2*MaxTextExtent];
2223 if (reason == (char *) NULL)
2225 if (description == (char *) NULL)
2226 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s.\n",GetClientName(),
2229 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s (%s).\n",
2230 GetClientName(),reason,description);
2231 (void) MessageBox(NULL,buffer,"ImageMagick Warning",MB_OK | MB_TASKMODAL |
2232 MB_SETFOREGROUND | MB_ICONINFORMATION);