2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Windows NT Utility Methods for MagickCore %
20 % Copyright 1999-2019 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 % https://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/memory-private.h"
50 #include "MagickCore/nt-base.h"
51 #include "MagickCore/nt-base-private.h"
52 #include "MagickCore/resource_.h"
53 #include "MagickCore/resource-private.h"
54 #include "MagickCore/timer.h"
55 #include "MagickCore/string_.h"
56 #include "MagickCore/string-private.h"
57 #include "MagickCore/utility.h"
58 #include "MagickCore/utility-private.h"
59 #include "MagickCore/version.h"
60 #if defined(MAGICKCORE_LTDL_DELEGATE)
63 #if defined(MAGICKCORE_CIPHER_SUPPORT)
71 #if !defined(MAP_FAILED)
72 #define MAP_FAILED ((void *)(LONG_PTR)-1)
80 We need to make sure only one instance is created for each process and that
81 is why we wrap the new/delete instance methods.
83 From: http://www.ghostscript.com/doc/current/API.htm
84 "The Win32 DLL gsdll32.dll can be used by multiple programs simultaneously,
85 but only once within each process"
87 typedef struct _NTGhostInfo
90 (MagickDLLCall *delete_instance)(gs_main_instance *);
93 (MagickDLLCall *new_instance)(gs_main_instance **,void *);
102 #if !defined(MAGICKCORE_LTDL_DELEGATE)
104 *lt_slsearchpath = (char *) NULL;
114 *ghost_handle = (void *) NULL;
117 *ghost_semaphore = (SemaphoreInfo *) NULL,
118 *winsock_semaphore = (SemaphoreInfo *) NULL;
121 *wsaData = (WSADATA*) NULL;
124 long_paths_enabled = 2;
134 const registry_roots[2] =
136 { HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
137 { HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" }
141 External declarations.
143 #if !defined(MAGICKCORE_WINDOWS_SUPPORT)
144 extern "C" BOOL WINAPI
145 DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved);
148 static void MagickDLLCall NTGhostscriptDeleteInstance(
149 gs_main_instance *instance)
151 LockSemaphoreInfo(ghost_semaphore);
152 nt_ghost_info.delete_instance(instance);
153 nt_ghost_info.has_instance=MagickFalse;
154 UnlockSemaphoreInfo(ghost_semaphore);
157 static int MagickDLLCall NTGhostscriptNewInstance(gs_main_instance **pinstance,
163 LockSemaphoreInfo(ghost_semaphore);
165 if (nt_ghost_info.has_instance == MagickFalse)
167 status=nt_ghost_info.new_instance(pinstance,caller_handle);
169 nt_ghost_info.has_instance=MagickTrue;
171 UnlockSemaphoreInfo(ghost_semaphore);
175 static inline char *create_utf8_string(const wchar_t *wideChar)
183 count=WideCharToMultiByte(CP_UTF8,0,wideChar,-1,NULL,0,NULL,NULL);
185 return((char *) NULL);
186 utf8=(char *) AcquireQuantumMemory(count+1,sizeof(*utf8));
187 if (utf8 == (char *) NULL)
188 return((char *) NULL);
189 count=WideCharToMultiByte(CP_UTF8,0,wideChar,-1,utf8,count,NULL,NULL);
192 utf8=DestroyString(utf8);
193 return((char *) NULL);
200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210 % DllMain() is an entry point to the DLL which is called when processes and
211 % threads are initialized and terminated, or upon calls to the Windows
212 % LoadLibrary and FreeLibrary functions.
214 % The function returns TRUE of it succeeds, or FALSE if initialization fails.
216 % The format of the DllMain method is:
218 % BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
220 % A description of each parameter follows:
222 % o handle: handle to the DLL module
224 % o reason: reason for calling function:
226 % DLL_PROCESS_ATTACH - DLL is being loaded into virtual address
227 % space of current process.
228 % DLL_THREAD_ATTACH - Indicates that the current process is
229 % creating a new thread. Called under the
230 % context of the new thread.
231 % DLL_THREAD_DETACH - Indicates that the thread is exiting.
232 % Called under the context of the exiting
234 % DLL_PROCESS_DETACH - Indicates that the DLL is being unloaded
235 % from the virtual address space of the
238 % o lpvReserved: Used for passing additional info during DLL_PROCESS_ATTACH
239 % and DLL_PROCESS_DETACH.
242 #if defined(_DLL) && defined(ProvideDllMain)
243 BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
247 case DLL_PROCESS_ATTACH:
258 MagickCoreGenesis((const char *) NULL,MagickFalse);
259 wide_path=(wchar_t *) AcquireQuantumMemory(MagickPathExtent,
261 if (wide_path == (wchar_t *) NULL)
263 count=(ssize_t) GetModuleFileNameW(handle,wide_path,MagickPathExtent);
269 module_path=create_utf8_string(wide_path);
270 for ( ; count > 0; count--)
271 if (module_path[count] == '\\')
273 module_path[count+1]='\0';
276 path=(char *) AcquireQuantumMemory(16UL*MagickPathExtent,sizeof(*path));
277 if (path == (char *) NULL)
279 module_path=DestroyString(module_path);
280 wide_path=(wchar_t *) RelinquishMagickMemory(wide_path);
283 count=(ssize_t) GetEnvironmentVariable("PATH",path,16*MagickPathExtent);
284 if ((count != 0) && (strstr(path,module_path) == (char *) NULL))
286 if ((strlen(module_path)+count+1) < (16*MagickPathExtent-1))
291 variable=(char *) AcquireQuantumMemory(16UL*MagickPathExtent,
293 if (variable == (char *) NULL)
295 path=DestroyString(path);
296 module_path=DestroyString(module_path);
297 wide_path=(wchar_t *) RelinquishMagickMemory(wide_path);
300 (void) FormatLocaleString(variable,16*MagickPathExtent,
301 "%s;%s",module_path,path);
302 SetEnvironmentVariable("PATH",variable);
303 variable=DestroyString(variable);
306 path=DestroyString(path);
307 module_path=DestroyString(module_path);
309 wide_path=(wchar_t *) RelinquishMagickMemory(wide_path);
312 case DLL_PROCESS_DETACH:
314 MagickCoreTerminus();
325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 % Exit() calls TerminateProcess for Win95.
337 % The format of the exit method is:
339 % int Exit(int status)
341 % A description of each parameter follows:
343 % o status: an integer value representing the status of the terminating
347 MagickPrivate int Exit(int status)
351 TerminateProcess(GetCurrentProcess(),(unsigned int) status);
357 #if !defined(__MINGW32__)
359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363 % g e t t i m e o f d a y %
367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
369 % The gettimeofday() method get the time of day.
371 % The format of the gettimeofday method is:
373 % int gettimeofday(struct timeval *time_value,struct timezone *time_zone)
375 % A description of each parameter follows:
377 % o time_value: the time value.
379 % o time_zone: the time zone.
382 MagickPrivate int gettimeofday (struct timeval *time_value,
383 struct timezone *time_zone)
385 #define EpochFiletime MagickLLConstant(116444736000000000)
390 if (time_value != (struct timeval *) NULL)
401 GetSystemTimeAsFileTime(&file_time);
402 date_time.LowPart=file_time.dwLowDateTime;
403 date_time.HighPart=file_time.dwHighDateTime;
404 time=date_time.QuadPart;
407 time_value->tv_sec=(ssize_t) (time / 1000000);
408 time_value->tv_usec=(ssize_t) (time % 1000000);
410 if (time_zone != (struct timezone *) NULL)
417 time_zone->tz_minuteswest=_timezone/60;
418 time_zone->tz_dsttime=_daylight;
425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429 % I s W i n d o w s 9 5 %
433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
435 % IsWindows95() returns true if the system is Windows 95.
437 % The format of the IsWindows95 method is:
442 MagickPrivate int IsWindows95()
447 version_info.dwOSVersionInfoSize=sizeof(version_info);
448 if (GetVersionEx(&version_info) &&
449 (version_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS))
455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
459 % N T A r g v T o U T F 8 %
463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
465 % NTArgvToUTF8() converts the wide command line arguments to UTF-8 to ensure
466 % compatibility with Linux.
468 % The format of the NTArgvToUTF8 method is:
470 % char **NTArgvToUTF8(const int argc,wchar_t **argv)
472 % A description of each parameter follows:
474 % o argc: the number of command line arguments.
476 % o argv: the wide-character command line arguments.
479 MagickPrivate char **NTArgvToUTF8(const int argc,wchar_t **argv)
487 utf8=(char **) AcquireQuantumMemory(argc,sizeof(*utf8));
488 if (utf8 == (char **) NULL)
489 ThrowFatalException(ResourceLimitFatalError,"UnableToConvertStringToARGV");
490 for (i=0; i < (ssize_t) argc; i++)
492 utf8[i]=create_utf8_string(argv[i]);
493 if (utf8[i] == (char *) NULL)
495 for (i--; i >= 0; i--)
496 utf8[i]=DestroyString(utf8[i]);
497 ThrowFatalException(ResourceLimitFatalError,
498 "UnableToConvertStringToARGV");
505 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
509 % N T C l o s e D i r e c t o r y %
513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
515 % NTCloseDirectory() closes the named directory stream and frees the DIR
518 % The format of the NTCloseDirectory method is:
520 % int NTCloseDirectory(DIR *entry)
522 % A description of each parameter follows:
524 % o entry: Specifies a pointer to a DIR structure.
527 MagickPrivate int NTCloseDirectory(DIR *entry)
529 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
530 assert(entry != (DIR *) NULL);
531 FindClose(entry->hSearch);
532 entry=(DIR *) RelinquishMagickMemory(entry);
536 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
540 % N T C l o s e L i b r a r y %
544 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
546 % NTCloseLibrary() unloads the module associated with the passed handle.
548 % The format of the NTCloseLibrary method is:
550 % void NTCloseLibrary(void *handle)
552 % A description of each parameter follows:
554 % o handle: Specifies a handle to a previously loaded dynamic module.
557 MagickPrivate int NTCloseLibrary(void *handle)
560 return(FreeLibrary((HINSTANCE) handle));
561 return(!(FreeLibrary((HINSTANCE) handle)));
565 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
569 % N T C o n t r o l H a n d l e r %
573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
575 % NTControlHandler() registers a control handler that is activated when, for
576 % example, a ctrl-c is received.
578 % The format of the NTControlHandler method is:
580 % int NTControlHandler(void)
584 static BOOL ControlHandler(DWORD type)
587 AsynchronousResourceComponentTerminus();
591 MagickPrivate int NTControlHandler(void)
593 return(SetConsoleCtrlHandler((PHANDLER_ROUTINE) ControlHandler,TRUE));
597 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601 % N T E l a p s e d T i m e %
605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
607 % NTElapsedTime() returns the elapsed time (in seconds) since the last call to
610 % The format of the ElapsedTime method is:
612 % double NTElapsedTime(void)
615 MagickPrivate double NTElapsedTime(void)
635 if (frequency.QuadPart == 0)
637 if (QueryPerformanceFrequency(&frequency) == 0)
638 frequency.QuadPart=1;
640 if (frequency.QuadPart > 1)
642 QueryPerformanceCounter(&performance_count);
643 return((double) performance_count.QuadPart/frequency.QuadPart);
645 GetSystemTime(&system_time);
646 SystemTimeToFileTime(&system_time,&elapsed_time.filetime);
647 return((double) 1.0e-7*elapsed_time.filetime64);
651 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
661 % NTErf() computes the error function of x.
663 % The format of the NTErf method is:
665 % double NTCloseDirectory(DIR *entry)
667 % A description of each parameter follows:
669 % o x: Specifies a pointer to a DIR structure.
672 MagickPrivate double NTErf(double x)
698 y=1.0-(((((a5*t+a4)*t)+a3)*t+a2)*t+a1)*t*exp(-x*x);
704 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
708 + N T E r r o r H a n d l e r %
712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
714 % NTErrorHandler() displays an error reason and then terminates the program.
716 % The format of the NTErrorHandler method is:
718 % void NTErrorHandler(const ExceptionType severity,const char *reason,
719 % const char *description)
721 % A description of each parameter follows:
723 % o severity: Specifies the numeric error category.
725 % o reason: Specifies the reason to display before terminating the
728 % o description: Specifies any description to the reason.
731 MagickPrivate void NTErrorHandler(const ExceptionType severity,
732 const char *reason,const char *description)
735 buffer[3*MagickPathExtent],
739 if (reason == (char *) NULL)
741 MagickCoreTerminus();
744 message=GetExceptionMessage(errno);
745 if ((description != (char *) NULL) && errno)
746 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s (%s) [%s].\n",
747 GetClientName(),reason,description,message);
749 if (description != (char *) NULL)
750 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s (%s).\n",
751 GetClientName(),reason,description);
754 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s [%s].\n",
755 GetClientName(),reason,message);
757 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s.\n",
758 GetClientName(),reason);
759 message=DestroyString(message);
760 (void) MessageBox(NULL,buffer,"ImageMagick Exception",MB_OK | MB_TASKMODAL |
761 MB_SETFOREGROUND | MB_ICONEXCLAMATION);
762 MagickCoreTerminus();
767 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
771 % N T E x i t L i b r a r y %
775 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
777 % NTExitLibrary() exits the dynamic module loading subsystem.
779 % The format of the NTExitLibrary method is:
781 % int NTExitLibrary(void)
784 MagickPrivate int NTExitLibrary(void)
790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
794 % N T G a t h e r R a n d o m D a t a %
798 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
800 % NTGatherRandomData() gathers random data and returns it.
802 % The format of the GatherRandomData method is:
804 % MagickBooleanType NTGatherRandomData(const size_t length,
805 % unsigned char *random)
807 % A description of each parameter follows:
809 % length: the length of random data buffer
811 % random: the random data is returned here.
814 MagickPrivate MagickBooleanType NTGatherRandomData(const size_t length,
815 unsigned char *random)
817 #if defined(MAGICKCORE_CIPHER_SUPPORT) && defined(_MSC_VER) && (_MSC_VER > 1200)
824 handle=(HCRYPTPROV) NULL;
825 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
826 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET));
828 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
829 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET));
832 status=CryptGenRandom(handle,(DWORD) length,random);
835 status=CryptReleaseContext(handle,0);
838 status=CryptReleaseContext(handle,0);
849 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
853 % N T G e t E x e c u t i o n P a t h %
857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
859 % NTGetExecutionPath() returns the execution path of a program.
861 % The format of the GetExecutionPath method is:
863 % MagickBooleanType NTGetExecutionPath(char *path,const size_t extent)
865 % A description of each parameter follows:
867 % o path: the pathname of the executable that started the process.
869 % o extent: the maximum extent of the path.
872 MagickPrivate MagickBooleanType NTGetExecutionPath(char *path,
876 wide_path[MagickPathExtent];
878 (void) GetModuleFileNameW((HMODULE) NULL,wide_path,(DWORD) extent);
879 (void) WideCharToMultiByte(CP_UTF8,0,wide_path,-1,path,(int) extent,NULL,
885 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
889 % N T G e t L a s t E r r o r %
893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
895 % NTGetLastError() returns the last error that occurred.
897 % The format of the NTGetLastError method is:
899 % char *NTGetLastError(void)
902 char *NTGetLastError(void)
913 status=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
914 FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),
915 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR) &buffer,0,NULL);
917 reason=AcquireString("An unknown error occurred");
920 reason=AcquireString((const char *) buffer);
927 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
931 % N T G e t L i b r a r y E r r o r %
935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
937 % Lt_dlerror() returns a pointer to a string describing the last error
938 % associated with a lt_dl method. Note that this function is not thread
939 % safe so it should only be used under the protection of a lock.
941 % The format of the NTGetLibraryError method is:
943 % const char *NTGetLibraryError(void)
946 MagickPrivate const char *NTGetLibraryError(void)
949 last_error[MagickPathExtent];
955 error=NTGetLastError();
957 (void) CopyMagickString(last_error,error,MagickPathExtent);
958 error=DestroyString(error);
963 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
967 % N T G e t L i b r a r y S y m b o l %
971 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
973 % NTGetLibrarySymbol() retrieve the procedure address of the method
974 % specified by the passed character string.
976 % The format of the NTGetLibrarySymbol method is:
978 % void *NTGetLibrarySymbol(void *handle,const char *name)
980 % A description of each parameter follows:
982 % o handle: Specifies a handle to the previously loaded dynamic module.
984 % o name: Specifies the procedure entry point to be returned.
987 void *NTGetLibrarySymbol(void *handle,const char *name)
992 lpfnDllFunc1=(LPFNDLLFUNC1) GetProcAddress((HINSTANCE) handle,name);
994 return((void *) NULL);
995 return((void *) lpfnDllFunc1);
999 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1003 % N T G e t M o d u l e P a t h %
1007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1009 % NTGetModulePath() returns the path of the specified module.
1011 % The format of the GetModulePath method is:
1013 % MagickBooleanType NTGetModulePath(const char *module,char *path)
1015 % A description of each parameter follows:
1017 % modith: the module name.
1019 % path: the module path is returned here.
1022 MagickPrivate MagickBooleanType NTGetModulePath(const char *module,char *path)
1025 module_path[MagickPathExtent];
1034 handle=GetModuleHandle(module);
1035 if (handle == (HMODULE) NULL)
1036 return(MagickFalse);
1037 length=GetModuleFileName(handle,module_path,MagickPathExtent);
1039 GetPathComponent(module_path,HeadPath,path);
1044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1048 + N T G e t P a g e S i z e %
1052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1054 % NTGetPageSize() returns the memory page size under Windows.
1056 % The format of the NTPageSize
1061 MagickPrivate ssize_t NTGetPageSize(void)
1066 GetSystemInfo(&system_info);
1067 return((ssize_t) system_info.dwPageSize);
1071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1075 % N T G h o s t s c r i p t D L L %
1079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1081 % NTGhostscriptDLL() returns the path to the most recent Ghostscript version
1082 % DLL. The method returns TRUE on success otherwise FALSE.
1084 % The format of the NTGhostscriptDLL method is:
1086 % int NTGhostscriptDLL(char *path,int length)
1088 % A description of each parameter follows:
1090 % o path: return the Ghostscript DLL path here.
1092 % o length: the buffer length.
1096 static int NTGetRegistryValue(HKEY root,const char *key,DWORD flags,
1097 const char *name,char *value,int *length)
1114 Get a registry value: key = root\\key, named value = name.
1116 if (RegOpenKeyExA(root,key,0,KEY_READ | flags,&hkey) != ERROR_SUCCESS)
1117 return(1); /* no match */
1121 if (p == (BYTE *) NULL)
1122 p=(&byte); /* ERROR_MORE_DATA only if value is NULL */
1123 status=RegQueryValueExA(hkey,(char *) name,0,&type,p,&extent);
1125 if (status == ERROR_SUCCESS)
1128 return(0); /* return the match */
1130 if (status == ERROR_MORE_DATA)
1133 return(-1); /* buffer not large enough */
1135 return(1); /* not found */
1138 static int NTLocateGhostscript(DWORD flags,int *root_index,
1139 const char **product_family,int *major_version,int *minor_version)
1153 "Aladdin Ghostscript"
1157 Find the most recent version of Ghostscript.
1161 *product_family=NULL;
1163 *minor_version=49; /* min version of Ghostscript is 5.50 */
1164 for (i=0; i < (ssize_t) (sizeof(products)/sizeof(products[0])); i++)
1167 key[MagickPathExtent];
1178 (void) FormatLocaleString(key,MagickPathExtent,"SOFTWARE\\%s",products[i]);
1179 for (j=0; j < (ssize_t) (sizeof(registry_roots)/sizeof(registry_roots[0]));
1182 mode=KEY_READ | flags;
1183 if (RegOpenKeyExA(registry_roots[j].hkey,key,0,mode,&hkey) ==
1193 Now enumerate the keys.
1195 extent=sizeof(key)/sizeof(char);
1196 for (k=0; RegEnumKeyA(hkey,k,key,extent) == ERROR_SUCCESS; k++)
1204 if (sscanf(key,"%d.%d",&major,&minor) != 2)
1206 if ((major > *major_version) || ((major == *major_version) &&
1207 (minor > *minor_version)))
1210 *product_family=products[i];
1211 *major_version=major;
1212 *minor_version=minor;
1216 (void) RegCloseKey(hkey);
1220 if (status == MagickFalse)
1225 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"Ghostscript (%s) "
1226 "version %d.%02d",*product_family,*major_version,*minor_version);
1230 static int NTGhostscriptGetString(const char *name,BOOL *is_64_bit,char *value,
1231 const size_t length)
1234 buffer[MagickPathExtent],
1241 *product_family = (const char *) NULL;
1244 is_64_bit_version = FALSE;
1253 Get a string from the installed Ghostscript.
1256 directory=(char *) NULL;
1257 if (LocaleCompare(name,"GS_DLL") == 0)
1259 directory=GetEnvironmentValue("MAGICK_GHOSTSCRIPT_PATH");
1260 if (directory != (char *) NULL)
1262 (void) FormatLocaleString(buffer,MagickPathExtent,"%s%sgsdll32.dll",
1263 directory,DirectorySeparator);
1264 if (IsPathAccessible(buffer) != MagickFalse)
1266 directory=DestroyString(directory);
1267 (void) CopyMagickString(value,buffer,length);
1268 if (is_64_bit != NULL)
1272 (void) FormatLocaleString(buffer,MagickPathExtent,"%s%sgsdll64.dll",
1273 directory,DirectorySeparator);
1274 if (IsPathAccessible(buffer) != MagickFalse)
1276 directory=DestroyString(directory);
1277 (void) CopyMagickString(value,buffer,length);
1278 if (is_64_bit != NULL)
1285 if (product_family == NULL)
1288 #if defined(KEY_WOW64_32KEY)
1290 flags=KEY_WOW64_64KEY;
1292 flags=KEY_WOW64_32KEY;
1294 (void) NTLocateGhostscript(flags,&root_index,&product_family,
1295 &major_version,&minor_version);
1296 if (product_family == NULL)
1298 flags=KEY_WOW64_32KEY;
1300 is_64_bit_version=TRUE;
1302 flags=KEY_WOW64_64KEY;
1306 if (product_family == NULL)
1308 (void) NTLocateGhostscript(flags,&root_index,&product_family,
1309 &major_version,&minor_version);
1310 #if !defined(_WIN64)
1311 is_64_bit_version=TRUE;
1314 if (product_family == NULL)
1316 if (is_64_bit != NULL)
1317 *is_64_bit=is_64_bit_version;
1318 (void) FormatLocaleString(buffer,MagickPathExtent,"SOFTWARE\\%s\\%d.%02d",
1319 product_family,major_version,minor_version);
1320 extent=(int) length;
1321 if (NTGetRegistryValue(registry_roots[root_index].hkey,buffer,flags,name,value,&extent) == 0)
1323 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1324 "registry: \"%s\\%s\\%s\"=\"%s\"",registry_roots[root_index].name,
1331 MagickPrivate int NTGhostscriptDLL(char *path,int length)
1334 dll[MagickPathExtent] = { "" };
1340 if ((*dll == '\0') &&
1341 (NTGhostscriptGetString("GS_DLL",&is_64_bit_version,dll,sizeof(dll)) == FALSE))
1344 if (!is_64_bit_version)
1347 if (is_64_bit_version)
1350 (void) CopyMagickString(path,dll,length);
1355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1359 % N T G h o s t s c r i p t D L L V e c t o r s %
1363 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1365 % NTGhostscriptDLLVectors() returns a GhostInfo structure that includes
1366 % function vectors to invoke Ghostscript DLL functions. A null pointer is
1367 % returned if there is an error when loading the DLL or retrieving the
1370 % The format of the NTGhostscriptDLLVectors method is:
1372 % const GhostInfo *NTGhostscriptDLLVectors(void)
1375 MagickPrivate const GhostInfo *NTGhostscriptDLLVectors(void)
1377 if (NTGhostscriptLoadDLL() == FALSE)
1378 return((GhostInfo *) NULL);
1379 return(&ghost_info);
1383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1387 % N T G h o s t s c r i p t E X E %
1391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1393 % NTGhostscriptEXE() obtains the path to the latest Ghostscript executable.
1394 % The method returns FALSE if a full path value is not obtained and returns
1395 % a default path of gswin32c.exe.
1397 % The format of the NTGhostscriptEXE method is:
1399 % int NTGhostscriptEXE(char *path,int length)
1401 % A description of each parameter follows:
1403 % o path: return the Ghostscript executable path here.
1405 % o length: length of buffer.
1408 MagickPrivate int NTGhostscriptEXE(char *path,int length)
1414 program[MagickPathExtent] = { "" };
1417 is_64_bit_version = FALSE;
1419 (void) CopyMagickString(path,"gswin32c.exe",length);
1420 if (*program == '\0')
1422 if (ghost_semaphore == (SemaphoreInfo *) NULL)
1423 ActivateSemaphoreInfo(&ghost_semaphore);
1424 LockSemaphoreInfo(ghost_semaphore);
1425 if (*program == '\0')
1427 if (NTGhostscriptGetString("GS_DLL",&is_64_bit_version,program,
1428 sizeof(program)) == FALSE)
1430 UnlockSemaphoreInfo(ghost_semaphore);
1433 p=strrchr(program,'\\');
1434 if (p != (char *) NULL)
1438 (void) ConcatenateMagickString(program,is_64_bit_version ?
1439 "gswin64c.exe" : "gswin32c.exe",sizeof(program));
1442 UnlockSemaphoreInfo(ghost_semaphore);
1444 (void) CopyMagickString(path,program,length);
1449 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1453 % N T G h o s t s c r i p t F o n t s %
1457 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1459 % NTGhostscriptFonts() obtains the path to the Ghostscript fonts. The method
1460 % returns FALSE if it cannot determine the font path.
1462 % The format of the NTGhostscriptFonts method is:
1464 % int NTGhostscriptFonts(char *path,int length)
1466 % A description of each parameter follows:
1468 % o path: return the font path here.
1470 % o length: length of the path buffer.
1473 MagickPrivate int NTGhostscriptFonts(char *path,int length)
1476 buffer[MagickPathExtent],
1478 filename[MagickPathExtent];
1485 directory=GetEnvironmentValue("MAGICK_GHOSTSCRIPT_FONT_PATH");
1486 if (directory != (char *) NULL)
1488 (void) CopyMagickString(buffer,directory,MagickPathExtent);
1489 directory=DestroyString(directory);
1493 if (NTGhostscriptGetString("GS_LIB",NULL,buffer,MagickPathExtent) == FALSE)
1496 for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
1498 (void) CopyMagickString(path,p+1,length+1);
1499 q=strchr(path,DirectoryListSeparator);
1500 if (q != (char *) NULL)
1502 (void) FormatLocaleString(filename,MagickPathExtent,"%s%sfonts.dir",path,
1503 DirectorySeparator);
1504 if (IsPathAccessible(filename) != MagickFalse)
1506 (void) FormatLocaleString(filename,MagickPathExtent,"%s%sn019003l.pfb",path,
1507 DirectorySeparator);
1508 if (IsPathAccessible(filename) != MagickFalse)
1516 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1520 % N T G h o s t s c r i p t L o a d D L L %
1524 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1526 % NTGhostscriptLoadDLL() attempts to load the Ghostscript DLL and returns
1527 % TRUE if it succeeds.
1529 % The format of the NTGhostscriptLoadDLL method is:
1531 % int NTGhostscriptLoadDLL(void)
1534 static inline int NTGhostscriptHasValidHandle()
1536 if ((nt_ghost_info.delete_instance == NULL) || (ghost_info.exit == NULL) ||
1537 (ghost_info.init_with_args == NULL) ||
1538 (nt_ghost_info.new_instance == NULL) ||
1539 (ghost_info.run_string == NULL) || (ghost_info.set_stdio == NULL) ||
1540 (ghost_info.revision == NULL))
1547 MagickPrivate int NTGhostscriptLoadDLL(void)
1550 path[MagickPathExtent];
1552 if (ghost_semaphore == (SemaphoreInfo *) NULL)
1553 ActivateSemaphoreInfo(&ghost_semaphore);
1554 LockSemaphoreInfo(ghost_semaphore);
1555 if (ghost_handle != (void *) NULL)
1557 UnlockSemaphoreInfo(ghost_semaphore);
1558 return(NTGhostscriptHasValidHandle());
1560 if (NTGhostscriptDLL(path,sizeof(path)) == FALSE)
1562 UnlockSemaphoreInfo(ghost_semaphore);
1565 ghost_handle=lt_dlopen(path);
1566 if (ghost_handle == (void *) NULL)
1568 UnlockSemaphoreInfo(ghost_semaphore);
1571 (void) memset((void *) &nt_ghost_info,0,sizeof(NTGhostInfo));
1572 nt_ghost_info.delete_instance=(void (MagickDLLCall *)(gs_main_instance *)) (
1573 lt_dlsym(ghost_handle,"gsapi_delete_instance"));
1574 nt_ghost_info.new_instance=(int (MagickDLLCall *)(gs_main_instance **,
1575 void *)) (lt_dlsym(ghost_handle,"gsapi_new_instance"));
1576 nt_ghost_info.has_instance=MagickFalse;
1577 (void) memset((void *) &ghost_info,0,sizeof(GhostInfo));
1578 ghost_info.delete_instance=NTGhostscriptDeleteInstance;
1579 ghost_info.exit=(int (MagickDLLCall *)(gs_main_instance*))
1580 lt_dlsym(ghost_handle,"gsapi_exit");
1581 ghost_info.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,int,
1582 char **)) (lt_dlsym(ghost_handle,"gsapi_init_with_args"));
1583 ghost_info.new_instance=NTGhostscriptNewInstance;
1584 ghost_info.run_string=(int (MagickDLLCall *)(gs_main_instance *,const char *,
1585 int,int *)) (lt_dlsym(ghost_handle,"gsapi_run_string"));
1586 ghost_info.set_stdio=(int (MagickDLLCall *)(gs_main_instance *,int(
1587 MagickDLLCall *)(void *,char *,int),int(MagickDLLCall *)(void *,
1588 const char *,int),int(MagickDLLCall *)(void *,const char *,int)))
1589 (lt_dlsym(ghost_handle,"gsapi_set_stdio"));
1590 ghost_info.revision=(int (MagickDLLCall *)(gsapi_revision_t *,int)) (
1591 lt_dlsym(ghost_handle,"gsapi_revision"));
1592 UnlockSemaphoreInfo(ghost_semaphore);
1593 return(NTGhostscriptHasValidHandle());
1597 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1601 % N T G h o s t s c r i p t U n L o a d D L L %
1605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1607 % NTGhostscriptUnLoadDLL() unloads the Ghostscript DLL and returns TRUE if
1610 % The format of the NTGhostscriptUnLoadDLL method is:
1612 % int NTGhostscriptUnLoadDLL(void)
1615 MagickPrivate void NTGhostscriptUnLoadDLL(void)
1617 if (ghost_semaphore == (SemaphoreInfo *) NULL)
1618 ActivateSemaphoreInfo(&ghost_semaphore);
1619 LockSemaphoreInfo(ghost_semaphore);
1620 if (ghost_handle != (void *) NULL)
1622 (void) lt_dlclose(ghost_handle);
1623 ghost_handle=(void *) NULL;
1624 (void) memset((void *) &ghost_info,0,sizeof(GhostInfo));
1626 UnlockSemaphoreInfo(ghost_semaphore);
1627 RelinquishSemaphoreInfo(&ghost_semaphore);
1631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1635 % N T I n i t i a l i z e L i b r a r y %
1639 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1641 % NTInitializeLibrary() initializes the dynamic module loading subsystem.
1643 % The format of the NTInitializeLibrary method is:
1645 % int NTInitializeLibrary(void)
1648 MagickPrivate int NTInitializeLibrary(void)
1654 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1658 % N T I n i t i a l i z e W i n s o c k %
1662 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1664 % NTInitializeWinsock() initializes Winsock.
1666 % The format of the NTInitializeWinsock method is:
1668 % void NTInitializeWinsock(void)
1671 MagickPrivate void NTInitializeWinsock(MagickBooleanType use_lock)
1675 if (winsock_semaphore == (SemaphoreInfo *) NULL)
1676 ActivateSemaphoreInfo(&winsock_semaphore);
1677 LockSemaphoreInfo(winsock_semaphore);
1679 if (wsaData == (WSADATA *) NULL)
1681 wsaData=(WSADATA *) AcquireMagickMemory(sizeof(WSADATA));
1682 if (WSAStartup(MAKEWORD(2,2),wsaData) != 0)
1683 ThrowFatalException(CacheFatalError,"WSAStartup failed");
1686 UnlockSemaphoreInfo(winsock_semaphore);
1690 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1694 % N T L o n g P a t h s E n a b l e d %
1698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1700 % NTLongPathsEnabled() returns a boolean indicating whether long paths are
1703 % The format of the NTLongPathsEnabled method is:
1705 % MagickBooleanType NTLongPathsEnabled()
1708 MagickExport MagickBooleanType NTLongPathsEnabled()
1710 if (long_paths_enabled == 2)
1723 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1724 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1725 "SYSTEM\\CurrentControlSet\\Control\\FileSystem",0,KEY_READ,
1727 if (status != ERROR_SUCCESS)
1729 RegCloseKey(registry_key);
1730 long_paths_enabled=0;
1731 return(MagickFalse);
1734 status=RegQueryValueExA(registry_key,"LongPathsEnabled",0,&type,NULL,
1736 if ((status != ERROR_SUCCESS) || (type != REG_DWORD))
1738 RegCloseKey(registry_key);
1739 long_paths_enabled=0;
1740 return(MagickFalse);
1742 status=RegQueryValueExA(registry_key,"LongPathsEnabled",0,&type,
1743 (LPBYTE) &value,&size);
1744 RegCloseKey(registry_key);
1745 if (status != ERROR_SUCCESS)
1747 long_paths_enabled=0;
1748 return(MagickFalse);
1750 long_paths_enabled=(size_t) value;
1752 return(long_paths_enabled == 1 ? MagickTrue : MagickFalse);
1756 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1760 + N T M a p M e m o r y %
1764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1766 % Mmap() emulates the Unix method of the same name.
1768 % The format of the NTMapMemory method is:
1770 % MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
1771 % int access,int file,MagickOffsetType offset)
1774 MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
1775 int flags,int file,MagickOffsetType offset)
1794 file_handle=INVALID_HANDLE_VALUE;
1795 low_length=(DWORD) (length & 0xFFFFFFFFUL);
1796 high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
1797 map_handle=INVALID_HANDLE_VALUE;
1799 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
1800 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
1802 if (protection & PROT_WRITE)
1804 access_mode=FILE_MAP_WRITE;
1805 if (!(flags & MAP_PRIVATE))
1806 protection_mode=PAGE_READWRITE;
1809 access_mode=FILE_MAP_COPY;
1810 protection_mode=PAGE_WRITECOPY;
1814 if (protection & PROT_READ)
1816 access_mode=FILE_MAP_READ;
1817 protection_mode=PAGE_READONLY;
1819 if ((file == -1) && (flags & MAP_ANONYMOUS))
1820 file_handle=INVALID_HANDLE_VALUE;
1822 file_handle=(HANDLE) _get_osfhandle(file);
1823 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
1827 map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
1829 CloseHandle(map_handle);
1831 if (map == (void *) NULL)
1832 return((void *) ((char *) MAP_FAILED));
1833 return((void *) ((char *) map));
1837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1841 % N T O p e n D i r e c t o r y %
1845 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1847 % NTOpenDirectory() opens the directory named by filename and associates a
1848 % directory stream with it.
1850 % The format of the NTOpenDirectory method is:
1852 % DIR *NTOpenDirectory(const char *path)
1854 % A description of each parameter follows:
1856 % o entry: Specifies a pointer to a DIR structure.
1859 MagickPrivate DIR *NTOpenDirectory(const char *path)
1868 file_specification[MagickPathExtent];
1870 assert(path != (const char *) NULL);
1871 length=MultiByteToWideChar(CP_UTF8,0,path,-1,file_specification,
1874 return((DIR *) NULL);
1875 if (wcsncat(file_specification,(const wchar_t*) DirectorySeparator,
1876 MagickPathExtent-wcslen(file_specification)-1) == (wchar_t *) NULL)
1877 return((DIR *) NULL);
1878 entry=(DIR *) AcquireCriticalMemory(sizeof(DIR));
1879 entry->firsttime=TRUE;
1880 entry->hSearch=FindFirstFileW(file_specification,&entry->Win32FindData);
1881 if (entry->hSearch == INVALID_HANDLE_VALUE)
1883 if(wcsncat(file_specification,L"*.*",
1884 MagickPathExtent-wcslen(file_specification)-1) == (wchar_t *) NULL)
1886 entry=(DIR *) RelinquishMagickMemory(entry);
1887 return((DIR *) NULL);
1889 entry->hSearch=FindFirstFileW(file_specification,&entry->Win32FindData);
1890 if (entry->hSearch == INVALID_HANDLE_VALUE)
1892 entry=(DIR *) RelinquishMagickMemory(entry);
1893 return((DIR *) NULL);
1900 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1904 % N T O p e n L i b r a r y %
1908 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1910 % NTOpenLibrary() loads a dynamic module into memory and returns a handle that
1911 % can be used to access the various procedures in the module.
1913 % The format of the NTOpenLibrary method is:
1915 % void *NTOpenLibrary(const char *filename)
1917 % A description of each parameter follows:
1919 % o path: Specifies a pointer to string representing dynamic module that
1924 static inline const char *GetSearchPath(void)
1926 #if defined(MAGICKCORE_LTDL_DELEGATE)
1927 return(lt_dlgetsearchpath());
1929 return(lt_slsearchpath);
1933 static UINT ChangeErrorMode(void)
1936 (CALLBACK *GETERRORMODE)(void);
1947 mode=SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
1949 handle=GetModuleHandle("kernel32.dll");
1950 if (handle == (HMODULE) NULL)
1951 return SetErrorMode(mode);
1953 getErrorMode=(GETERRORMODE) NTGetLibrarySymbol(handle,"GetErrorMode");
1954 if (getErrorMode != (GETERRORMODE) NULL)
1955 mode=getErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
1957 return SetErrorMode(mode);
1960 static inline void *NTLoadLibrary(const char *filename)
1966 path[MagickPathExtent];
1968 length=MultiByteToWideChar(CP_UTF8,0,filename,-1,path,MagickPathExtent);
1970 return((void *) NULL);
1971 return (void *) LoadLibraryExW(path,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1974 MagickPrivate void *NTOpenLibrary(const char *filename)
1977 path[MagickPathExtent];
1989 mode=ChangeErrorMode();
1990 handle=NTLoadLibrary(filename);
1991 if (handle == (void *) NULL)
1994 while (p != (const char*) NULL)
1996 q=strchr(p,DirectoryListSeparator);
1997 if (q != (const char*) NULL)
1998 (void) CopyMagickString(path,p,q-p+1);
2000 (void) CopyMagickString(path,p,MagickPathExtent);
2001 (void) ConcatenateMagickString(path,DirectorySeparator,MagickPathExtent);
2002 (void) ConcatenateMagickString(path,filename,MagickPathExtent);
2003 handle=NTLoadLibrary(path);
2004 if (handle != (void *) NULL || q == (const char*) NULL)
2014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2018 % N T R e a d D i r e c t o r y %
2022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2024 % NTReadDirectory() returns a pointer to a structure representing the
2025 % directory entry at the current position in the directory stream to which
2028 % The format of the NTReadDirectory
2030 % NTReadDirectory(entry)
2032 % A description of each parameter follows:
2034 % o entry: Specifies a pointer to a DIR structure.
2037 MagickPrivate struct dirent *NTReadDirectory(DIR *entry)
2045 if (entry == (DIR *) NULL)
2046 return((struct dirent *) NULL);
2047 if (!entry->firsttime)
2049 status=FindNextFileW(entry->hSearch,&entry->Win32FindData);
2051 return((struct dirent *) NULL);
2053 length=WideCharToMultiByte(CP_UTF8,0,entry->Win32FindData.cFileName,-1,
2054 entry->file_info.d_name,sizeof(entry->file_info.d_name),NULL,NULL);
2056 return((struct dirent *) NULL);
2057 entry->firsttime=FALSE;
2058 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
2059 return(&entry->file_info);
2063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2067 % N T R e g i s t r y K e y L o o k u p %
2071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2073 % NTRegistryKeyLookup() returns ImageMagick installation path settings
2074 % stored in the Windows Registry. Path settings are specific to the
2075 % installed ImageMagick version so that multiple Image Magick installations
2078 % Values are stored in the registry under a base path path similar to
2079 % "HKEY_LOCAL_MACHINE/SOFTWARE\ImageMagick\6.7.4\Q:16" or
2080 % "HKEY_CURRENT_USER/SOFTWARE\ImageMagick\6.7.4\Q:16". The provided subkey
2081 % is appended to this base path to form the full key.
2083 % The format of the NTRegistryKeyLookup method is:
2085 % unsigned char *NTRegistryKeyLookup(const char *subkey)
2087 % A description of each parameter follows:
2089 % o subkey: Specifies a string that identifies the registry object.
2090 % Currently supported sub-keys include: "BinPath", "ConfigurePath",
2091 % "LibPath", "CoderModulesPath", "FilterModulesPath", "SharePath".
2094 MagickPrivate unsigned char *NTRegistryKeyLookup(const char *subkey)
2097 package_key[MagickPathExtent];
2115 (void) FormatLocaleString(package_key,MagickPathExtent,
2116 "SOFTWARE\\%s\\%s\\Q:%d",MagickPackageName,MagickLibVersionText,
2117 MAGICKCORE_QUANTUM_DEPTH);
2118 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",package_key);
2119 registry_key=(HKEY) INVALID_HANDLE_VALUE;
2120 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,package_key,0,KEY_READ,®istry_key);
2121 if (status != ERROR_SUCCESS)
2122 status=RegOpenKeyExA(HKEY_CURRENT_USER,package_key,0,KEY_READ,
2124 if (status != ERROR_SUCCESS)
2125 return((unsigned char *) NULL);
2130 value=(unsigned char *) AcquireQuantumMemory(size,sizeof(*value));
2131 if (value == (unsigned char *) NULL)
2133 RegCloseKey(registry_key);
2134 return((unsigned char *) NULL);
2136 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",subkey);
2137 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
2138 if ((status == ERROR_MORE_DATA) && (type == REG_SZ))
2140 value=(unsigned char *) ResizeQuantumMemory(value,size,sizeof(*value));
2141 if (value == (BYTE *) NULL)
2143 RegCloseKey(registry_key);
2144 return((unsigned char *) NULL);
2146 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
2148 RegCloseKey(registry_key);
2149 if ((type != REG_SZ) || (status != ERROR_SUCCESS))
2150 value=(unsigned char *) RelinquishMagickMemory(value);
2151 return((unsigned char *) value);
2155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2159 % N T R e p o r t E v e n t %
2163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2165 % NTReportEvent() reports an event.
2167 % The format of the NTReportEvent method is:
2169 % MagickBooleanType NTReportEvent(const char *event,
2170 % const MagickBooleanType error)
2172 % A description of each parameter follows:
2174 % o event: the event.
2176 % o error: MagickTrue the event is an error.
2179 MagickPrivate MagickBooleanType NTReportEvent(const char *event,
2180 const MagickBooleanType error)
2191 handle=RegisterEventSource(NULL,MAGICKCORE_PACKAGE_NAME);
2193 return(MagickFalse);
2195 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
2196 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
2197 DeregisterEventSource(handle);
2202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2206 % N T R e s o u r c e T o B l o b %
2210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2212 % NTResourceToBlob() returns a blob containing the contents of the resource
2213 % in the current executable specified by the id parameter. This currently
2214 % used to retrieve MGK files tha have been embedded into the various command
2217 % The format of the NTResourceToBlob method is:
2219 % unsigned char *NTResourceToBlob(const char *id)
2221 % A description of each parameter follows:
2223 % o id: Specifies a string that identifies the resource.
2226 MagickPrivate unsigned char *NTResourceToBlob(const char *id)
2229 #ifndef MAGICKCORE_LIBRARY_NAME
2231 path[MagickPathExtent];
2250 assert(id != (const char *) NULL);
2251 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
2252 #ifdef MAGICKCORE_LIBRARY_NAME
2253 handle=GetModuleHandle(MAGICKCORE_LIBRARY_NAME);
2255 (void) FormatLocaleString(path,MagickPathExtent,"%s%s%s",GetClientPath(),
2256 DirectorySeparator,GetClientName());
2257 if (IsPathAccessible(path) != MagickFalse)
2258 handle=GetModuleHandle(path);
2260 handle=GetModuleHandle(0);
2263 return((unsigned char *) NULL);
2264 resource=FindResource(handle,id,"IMAGEMAGICK");
2266 return((unsigned char *) NULL);
2267 global=LoadResource(handle,resource);
2269 return((unsigned char *) NULL);
2270 length=SizeofResource(handle,resource);
2271 value=(unsigned char *) LockResource(global);
2274 FreeResource(global);
2275 return((unsigned char *) NULL);
2277 blob=(unsigned char *) AcquireQuantumMemory(length+MagickPathExtent,
2279 if (blob != (unsigned char *) NULL)
2281 (void) memcpy(blob,value,length);
2284 UnlockResource(global);
2285 FreeResource(global);
2290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2294 % N T S e e k D i r e c t o r y %
2298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2300 % NTSeekDirectory() sets the position of the next NTReadDirectory() operation
2301 % on the directory stream.
2303 % The format of the NTSeekDirectory method is:
2305 % void NTSeekDirectory(DIR *entry,ssize_t position)
2307 % A description of each parameter follows:
2309 % o entry: Specifies a pointer to a DIR structure.
2311 % o position: specifies the position associated with the directory
2315 MagickPrivate void NTSeekDirectory(DIR *entry,ssize_t position)
2317 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2318 assert(entry != (DIR *) NULL);
2324 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2328 % N T S e t S e a r c h P a t h %
2332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2334 % NTSetSearchPath() sets the current locations that the subsystem should
2335 % look at to find dynamically loadable modules.
2337 % The format of the NTSetSearchPath method is:
2339 % int NTSetSearchPath(const char *path)
2341 % A description of each parameter follows:
2343 % o path: Specifies a pointer to string representing the search path
2344 % for DLL's that can be dynamically loaded.
2347 MagickPrivate int NTSetSearchPath(const char *path)
2349 #if defined(MAGICKCORE_LTDL_DELEGATE)
2350 lt_dlsetsearchpath(path);
2352 if (lt_slsearchpath != (char *) NULL)
2353 lt_slsearchpath=DestroyString(lt_slsearchpath);
2354 if (path != (char *) NULL)
2355 lt_slsearchpath=AcquireString(path);
2361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2365 + N T S y n c M e m o r y %
2369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2371 % NTSyncMemory() emulates the Unix method of the same name.
2373 % The format of the NTSyncMemory method is:
2375 % int NTSyncMemory(void *address,size_t length,int flags)
2377 % A description of each parameter follows:
2379 % o address: the address of the binary large object.
2381 % o length: the length of the binary large object.
2383 % o flags: Option flags (ignored for Windows).
2386 MagickPrivate int NTSyncMemory(void *address,size_t length,int flags)
2389 if (FlushViewOfFile(address,length) == MagickFalse)
2395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2399 % N T S y s t e m C o m m a n d %
2403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2405 % NTSystemCommand() executes the specified command and waits until it
2406 % terminates. The returned value is the exit status of the command.
2408 % The format of the NTSystemCommand method is:
2410 % int NTSystemCommand(MagickFalse,const char *command)
2412 % A description of each parameter follows:
2414 % o command: This string is the command to execute.
2416 % o output: an optional buffer to store the output from stderr/stdout.
2419 MagickPrivate int NTSystemCommand(const char *command,char *output)
2421 #define CleanupOutputHandles \
2422 if (read_output != (HANDLE) NULL) \
2424 CloseHandle(read_output); \
2425 read_output=(HANDLE) NULL; \
2426 CloseHandle(write_output); \
2427 write_output=(HANDLE) NULL; \
2430 #define CopyLastError \
2431 if (output != (char *) NULL) \
2433 error=NTGetLastError(); \
2434 if (error != (char *) NULL) \
2436 CopyMagickString(output,error,MagickPathExtent); \
2437 error=DestroyString(error); \
2443 local_command[MagickPathExtent];
2469 if (command == (char *) NULL)
2471 read_output=(HANDLE) NULL;
2472 write_output=(HANDLE) NULL;
2473 GetStartupInfo(&startup_info);
2474 startup_info.dwFlags=STARTF_USESHOWWINDOW;
2475 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
2476 (void) CopyMagickString(local_command,command,MagickPathExtent);
2477 asynchronous=command[strlen(command)-1] == '&' ? MagickTrue : MagickFalse;
2478 if (asynchronous != MagickFalse)
2480 local_command[strlen(command)-1]='\0';
2481 startup_info.wShowWindow=SW_SHOWDEFAULT;
2485 if (command[strlen(command)-1] == '|')
2486 local_command[strlen(command)-1]='\0';
2488 startup_info.wShowWindow=SW_HIDE;
2489 read_output=(HANDLE) NULL;
2490 if (output != (char *) NULL)
2492 sa.nLength=sizeof(SECURITY_ATTRIBUTES);
2493 sa.bInheritHandle=TRUE;
2494 sa.lpSecurityDescriptor=NULL;
2495 if (CreatePipe(&read_output,&write_output,NULL,0))
2497 if (SetHandleInformation(write_output,HANDLE_FLAG_INHERIT,
2498 HANDLE_FLAG_INHERIT))
2500 startup_info.dwFlags|=STARTF_USESTDHANDLES;
2501 startup_info.hStdOutput=write_output;
2502 startup_info.hStdError=write_output;
2505 CleanupOutputHandles;
2508 read_output=(HANDLE) NULL;
2511 status=CreateProcess((LPCTSTR) NULL,local_command,(LPSECURITY_ATTRIBUTES)
2512 NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) TRUE,(DWORD)
2513 NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
2518 CleanupOutputHandles;
2521 if (asynchronous != MagickFalse)
2522 return(status == 0);
2523 status=WaitForSingleObject(process_info.hProcess,INFINITE);
2524 if (status != WAIT_OBJECT_0)
2527 CleanupOutputHandles;
2530 status=GetExitCodeProcess(process_info.hProcess,&child_status);
2534 CleanupOutputHandles;
2537 CloseHandle(process_info.hProcess);
2538 CloseHandle(process_info.hThread);
2539 if (read_output != (HANDLE) NULL)
2540 if (PeekNamedPipe(read_output,(LPVOID) NULL,0,(LPDWORD) NULL,&size,(LPDWORD) NULL))
2541 if ((size > 0) && (ReadFile(read_output,output,MagickPathExtent-1,&bytes_read,NULL)))
2542 output[bytes_read]='\0';
2543 CleanupOutputHandles;
2544 return((int) child_status);
2548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2552 % N T S y s t e m C o n i f i g u r a t i o n %
2556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2558 % NTSystemConfiguration() provides a way for the application to determine
2559 % values for system limits or options at runtime.
2561 % The format of the exit method is:
2563 % ssize_t NTSystemConfiguration(int name)
2565 % A description of each parameter follows:
2567 % o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
2570 MagickPrivate ssize_t NTSystemConfiguration(int name)
2579 GetSystemInfo(&system_info);
2580 return(system_info.dwPageSize);
2582 case _SC_PHYS_PAGES:
2596 handle=GetModuleHandle("kernel32.dll");
2597 if (handle == (HMODULE) NULL)
2599 GetSystemInfo(&system_info);
2600 module=(LPFNDLLFUNC2) NTGetLibrarySymbol(handle,"GlobalMemoryStatusEx");
2601 if (module == (LPFNDLLFUNC2) NULL)
2606 GlobalMemoryStatus(&global_status);
2607 return((ssize_t) global_status.dwTotalPhys/system_info.dwPageSize/4);
2609 status.dwLength=sizeof(status);
2610 if (module(&status) == 0)
2612 return((ssize_t) status.ullTotalPhys/system_info.dwPageSize/4);
2623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2627 % N T T e l l D i r e c t o r y %
2631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2633 % NTTellDirectory() returns the current location associated with the named
2636 % The format of the NTTellDirectory method is:
2638 % ssize_t NTTellDirectory(DIR *entry)
2640 % A description of each parameter follows:
2642 % o entry: Specifies a pointer to a DIR structure.
2645 MagickPrivate ssize_t NTTellDirectory(DIR *entry)
2647 magick_unreferenced(entry);
2648 assert(entry != (DIR *) NULL);
2653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2657 % N T T r u n c a t e F i l e %
2661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2663 % NTTruncateFile() truncates a file to a specified length.
2665 % The format of the NTTruncateFile method is:
2667 % int NTTruncateFile(int file,off_t length)
2669 % A description of each parameter follows:
2673 % o length: the file length.
2676 MagickPrivate int NTTruncateFile(int file,off_t length)
2688 file_handle=(HANDLE) _get_osfhandle(file);
2689 if (file_handle == INVALID_HANDLE_VALUE)
2691 low=(long) (length & 0xffffffffUL);
2692 high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
2693 file_pointer=SetFilePointer(file_handle,low,&high,FILE_BEGIN);
2694 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
2696 if (SetEndOfFile(file_handle) == 0)
2702 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2706 + N T U n m a p M e m o r y %
2710 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2712 % NTUnmapMemory() emulates the Unix munmap method.
2714 % The format of the NTUnmapMemory method is:
2716 % int NTUnmapMemory(void *map,size_t length)
2718 % A description of each parameter follows:
2720 % o map: the address of the binary large object.
2722 % o length: the length of the binary large object.
2725 MagickPrivate int NTUnmapMemory(void *map,size_t length)
2728 if (UnmapViewOfFile(map) == 0)
2734 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2738 % N T U s e r T i m e %
2742 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2744 % NTUserTime() returns the total time the process has been scheduled (e.g.
2745 % seconds) since the last call to StartTimer().
2747 % The format of the UserTime method is:
2749 % double NTUserTime(void)
2752 MagickPrivate double NTUserTime(void)
2782 OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
2783 GetVersionEx(&OsVersionInfo);
2784 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
2785 return(NTElapsedTime());
2786 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
2787 &kernel_time.filetime,&user_time.filetime);
2790 return((double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
2794 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2798 % N T W a r n i n g H a n d l e r %
2802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2804 % NTWarningHandler() displays a warning reason.
2806 % The format of the NTWarningHandler method is:
2808 % void NTWarningHandler(const ExceptionType severity,const char *reason,
2809 % const char *description)
2811 % A description of each parameter follows:
2813 % o severity: Specifies the numeric warning category.
2815 % o reason: Specifies the reason to display before terminating the
2818 % o description: Specifies any description to the reason.
2821 MagickPrivate void NTWarningHandler(const ExceptionType severity,
2822 const char *reason,const char *description)
2825 buffer[2*MagickPathExtent];
2828 if (reason == (char *) NULL)
2830 if (description == (char *) NULL)
2831 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s.\n",GetClientName(),
2834 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s (%s).\n",
2835 GetClientName(),reason,description);
2836 (void) MessageBox(NULL,buffer,"ImageMagick Warning",MB_OK | MB_TASKMODAL |
2837 MB_SETFOREGROUND | MB_ICONINFORMATION);
2841 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2845 % N T W i n d o w s G e n e s i s %
2849 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2851 % NTWindowsGenesis() initializes the MagickCore Windows environment.
2853 % The format of the NTWindowsGenesis method is:
2855 % void NTWindowsGenesis(void)
2859 static LONG WINAPI NTUncaughtException(EXCEPTION_POINTERS *info)
2861 magick_unreferenced(info);
2862 AsynchronousResourceComponentTerminus();
2863 return(EXCEPTION_CONTINUE_SEARCH);
2866 MagickPrivate void NTWindowsGenesis(void)
2871 SetUnhandledExceptionFilter(NTUncaughtException);
2872 mode=GetEnvironmentValue("MAGICK_ERRORMODE");
2873 if (mode != (char *) NULL)
2875 (void) SetErrorMode(StringToInteger(mode));
2876 mode=DestroyString(mode);
2878 #if defined(_DEBUG) && !defined(__BORLANDC__) && !defined(__MINGW32__)
2879 if (IsEventLogging() != MagickFalse)
2884 debug=_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
2885 //debug |= _CRTDBG_CHECK_ALWAYS_DF;
2886 debug |= _CRTDBG_DELAY_FREE_MEM_DF;
2887 debug |= _CRTDBG_LEAK_CHECK_DF;
2888 (void) _CrtSetDbgFlag(debug);
2890 //_ASSERTE(_CrtCheckMemory());
2892 //_CrtSetBreakAlloc(42);
2895 #if defined(MAGICKCORE_INSTALLED_SUPPORT)
2900 path=NTRegistryKeyLookup("LibPath");
2901 if (path != (unsigned char *) NULL)
2907 lib_path[MagickPathExtent];
2909 length=MultiByteToWideChar(CP_UTF8,0,(char *) path,-1,lib_path,
2912 SetDllDirectoryW(lib_path);
2913 path=(unsigned char *) RelinquishMagickMemory(path);
2920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2924 % N T W i n d o w s T e r m i n u s %
2928 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2930 % NTWindowsTerminus() terminates the MagickCore Windows environment.
2932 % The format of the NTWindowsTerminus method is:
2934 % void NTWindowsTerminus(void)
2937 MagickPrivate void NTWindowsTerminus(void)
2939 NTGhostscriptUnLoadDLL();
2940 if (winsock_semaphore == (SemaphoreInfo *) NULL)
2941 ActivateSemaphoreInfo(&winsock_semaphore);
2942 LockSemaphoreInfo(winsock_semaphore);
2943 if (wsaData != (WSADATA *) NULL)
2946 wsaData=(WSADATA *) RelinquishMagickMemory((void *) wsaData);
2948 UnlockSemaphoreInfo(winsock_semaphore);
2949 RelinquishSemaphoreInfo(&winsock_semaphore);