2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Windows NT Utility Methods for MagickCore %
20 % Copyright 1999-2009 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;
76 static GhostscriptVectors
80 *ghostscript_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 % I s W i n d o w s 9 5 %
248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 % IsWindows95() returns true if the system is Windows 95.
252 % The format of the IsWindows95 method is:
257 MagickExport int IsWindows95()
262 version_info.dwOSVersionInfoSize=sizeof(version_info);
263 if (GetVersionEx(&version_info) &&
264 (version_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS))
270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274 % N T C l o s e D i r e c t o r y %
278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 % NTCloseDirectory() closes the named directory stream and frees the DIR
283 % The format of the NTCloseDirectory method is:
285 % int NTCloseDirectory(DIR *entry)
287 % A description of each parameter follows:
289 % o entry: Specifies a pointer to a DIR structure.
292 MagickExport int NTCloseDirectory(DIR *entry)
294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
295 assert(entry != (DIR *) NULL);
296 FindClose(entry->hSearch);
297 entry=(DIR *) RelinquishMagickMemory(entry);
302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306 % N T C l o s e L i b r a r y %
310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
312 % NTCloseLibrary() unloads the module associated with the passed handle.
314 % The format of the NTCloseLibrary method is:
316 % void NTCloseLibrary(void *handle)
318 % A description of each parameter follows:
320 % o handle: Specifies a handle to a previously loaded dynamic module.
323 MagickExport int NTCloseLibrary(void *handle)
326 return(FreeLibrary((HINSTANCE) handle));
327 return(!(FreeLibrary((HINSTANCE) handle)));
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 % N T C o n t r o l H a n d l e r %
339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341 % NTControlHandler() registers a control handler that is activated when, for
342 % example, a ctrl-c is received.
344 % The format of the NTControlHandler method is:
346 % int NTControlHandler(void)
350 static BOOL ControlHandler(DWORD type)
352 AsynchronousDestroyMagickResources();
356 MagickExport int NTControlHandler(void)
358 return(SetConsoleCtrlHandler((PHANDLER_ROUTINE) ControlHandler,TRUE));
362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
366 % N T E l a p s e d T i m e %
370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
372 % NTElapsedTime() returns the elapsed time (in seconds) since the last call to
375 % The format of the ElapsedTime method is:
377 % double NTElapsedTime(void)
380 MagickExport double NTElapsedTime(void)
394 GetSystemTime(&system_time);
395 SystemTimeToFileTime(&system_time,&elapsed_time.filetime);
396 return((double) 1.0e-7*elapsed_time.filetime64);
400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
404 + N T E r r o r H a n d l e r %
408 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410 % NTErrorHandler() displays an error reason and then terminates the program.
412 % The format of the NTErrorHandler method is:
414 % void NTErrorHandler(const ExceptionType error,const char *reason,
415 % const char *description)
417 % A description of each parameter follows:
419 % o error: Specifies the numeric error category.
421 % o reason: Specifies the reason to display before terminating the
424 % o description: Specifies any description to the reason.
427 MagickExport void NTErrorHandler(const ExceptionType error,const char *reason,
428 const char *description)
431 buffer[3*MaxTextExtent],
434 if (reason == (char *) NULL)
436 MagickCoreTerminus();
439 message=GetExceptionMessage(errno);
440 if ((description != (char *) NULL) && errno)
441 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s (%s) [%s].\n",
442 GetClientName(),reason,description,message);
444 if (description != (char *) NULL)
445 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s (%s).\n",
446 GetClientName(),reason,description);
449 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s [%s].\n",
450 GetClientName(),reason,message);
452 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s.\n",
453 GetClientName(),reason);
454 message=DestroyString(message);
455 (void) MessageBox(NULL,buffer,"ImageMagick Exception",MB_OK | MB_TASKMODAL |
456 MB_SETFOREGROUND | MB_ICONEXCLAMATION);
457 MagickCoreTerminus();
462 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
466 % N T E x i t L i b r a r y %
470 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
472 % NTExitLibrary() exits the dynamic module loading subsystem.
474 % The format of the NTExitLibrary method is:
476 % int NTExitLibrary(void)
479 MagickExport int NTExitLibrary(void)
485 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
489 % N T G a t h e r R a n d o m D a t a %
493 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
495 % NTGatherRandomData() gathers random data and returns it.
497 % The format of the GatherRandomData method is:
499 % MagickBooleanType NTGatherRandomData(const size_t length,
500 % unsigned char *random)
502 % A description of each parameter follows:
504 % length: the length of random data buffer
506 % random: the random data is returned here.
509 MagickExport MagickBooleanType NTGatherRandomData(const size_t length,
510 unsigned char *random)
512 #if defined(MAGICKCORE_CIPHER_SUPPORT) && defined(_MSC_VER) && (_MSC_VER > 1200)
519 handle=(HCRYPTPROV) NULL;
520 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
521 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET));
523 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
524 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET));
527 status=CryptGenRandom(handle,(DWORD) length,random);
530 status=CryptReleaseContext(handle,0);
533 status=CryptReleaseContext(handle,0);
541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
545 % N T G e t E x e c u t i o n P a t h %
549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
551 % NTGetExecutionPath() returns the execution path of a program.
553 % The format of the GetExecutionPath method is:
555 % MagickBooleanType NTGetExecutionPath(char *path,const size_t extent)
557 % A description of each parameter follows:
559 % o path: the pathname of the executable that started the process.
561 % o extent: the maximum extent of the path.
564 MagickExport MagickBooleanType NTGetExecutionPath(char *path,
567 GetModuleFileName(0,path,(DWORD) extent);
572 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
576 % N T G e t L a s t E r r o r %
580 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
582 % NTGetLastError() returns the last error that occurred.
584 % The format of the NTGetLastError method is:
586 % char *NTGetLastError(void)
589 char *NTGetLastError(void)
600 status=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
601 FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),
602 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR) &buffer,0,NULL);
604 reason=AcquireString("An unknown error occurred");
607 reason=AcquireString((const char *) buffer);
614 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
618 % N T G e t L i b r a r y E r r o r %
622 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
624 % Lt_dlerror() returns a pointer to a string describing the last error
625 % associated with a lt_dl method. Note that this function is not thread
626 % safe so it should only be used under the protection of a lock.
628 % The format of the NTGetLibraryError method is:
630 % const char *NTGetLibraryError(void)
633 MagickExport const char *NTGetLibraryError(void)
636 last_error[MaxTextExtent];
642 error=NTGetLastError();
644 (void) CopyMagickString(last_error,error,MaxTextExtent);
645 error=DestroyString(error);
650 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654 % N T G e t L i b r a r y S y m b o l %
658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
660 % NTGetLibrarySymbol() retrieve the procedure address of the method
661 % specified by the passed character string.
663 % The format of the NTGetLibrarySymbol method is:
665 % void *NTGetLibrarySymbol(void *handle,const char *name)
667 % A description of each parameter follows:
669 % o handle: Specifies a handle to the previously loaded dynamic module.
671 % o name: Specifies the procedure entry point to be returned.
674 void *NTGetLibrarySymbol(void *handle,const char *name)
679 lpfnDllFunc1=(LPFNDLLFUNC1) GetProcAddress((HINSTANCE) handle,name);
681 return((void *) NULL);
682 return((void *) lpfnDllFunc1);
686 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
690 % N T G e t M o d u l e P a t h %
694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
696 % NTGetModulePath() returns the path of the specified module.
698 % The format of the GetModulePath method is:
700 % MagickBooleanType NTGetModulePath(const char *module,char *path)
702 % A description of each parameter follows:
704 % modith: the module name.
706 % path: the module path is returned here.
709 MagickExport MagickBooleanType NTGetModulePath(const char *module,char *path)
712 module_path[MaxTextExtent];
721 handle=GetModuleHandle(module);
722 if (handle == (HMODULE) NULL)
724 length=GetModuleFileName(handle,module_path,MaxTextExtent);
726 GetPathComponent(module_path,HeadPath,path);
731 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
735 % N T G h o s t s c r i p t D L L %
739 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
741 % NTGhostscriptDLL() returns the path to the most recent Ghostscript DLL. The
742 % method returns TRUE on success otherwise FALSE.
744 % The format of the NTGhostscriptDLL method is:
746 % int NTGhostscriptDLL(char *path,int length)
748 % A description of each parameter follows:
750 % o path: return the Ghostscript DLL path here.
752 % o length: the buffer length.
756 static int NTGetRegistryValue(HKEY root,const char *key,const char *name,
757 char *value,int *length)
774 Get a registry value: Key = root\\key, named value = name.
776 if (RegOpenKeyExA(root,key,0,KEY_READ,&hkey) != ERROR_SUCCESS)
777 return(1); /* no match */
781 if (p == (BYTE *) NULL)
782 p=(&byte); /* won't return ERROR_MORE_DATA if value is NULL */
783 status=RegQueryValueExA(hkey,(char *) name,0,&type,p,&extent);
785 if (status == ERROR_SUCCESS)
788 return(0); /* return the match */
790 if (status == ERROR_MORE_DATA)
793 return(-1); /* buffer wasn't large enough */
795 return(1); /* not found */
798 static int NTGhostscriptFind(const char **product_family,int *major_version,
813 "Aladdin Ghostscript"
817 Find the most recent version of Ghostscript.
820 *product_family=NULL;
822 *minor_version=49; /* min version of Ghostscript is 5.50 */
823 for (i=0; i < (sizeof(products)/sizeof(products[0])); i++)
832 (void) FormatMagickString(key,MaxTextExtent,"SOFTWARE\\%s",products[i]);
833 root=HKEY_LOCAL_MACHINE;
834 if (RegOpenKeyExA(root,key,0,KEY_READ,&hkey) == ERROR_SUCCESS)
843 Now enumerate the keys.
845 extent=sizeof(key)/sizeof(char);
846 for (j=0; RegEnumKeyA(hkey,j,key,extent) == ERROR_SUCCESS; j++)
854 if (sscanf(key,"%d.%d",&major,&minor) != 2)
856 if ((major > *major_version) || ((major == *major_version) &&
857 (minor > *minor_version)))
859 *product_family=products[i];
860 *major_version=major;
861 *minor_version=minor;
867 if (status == MagickFalse)
872 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"Ghostscript (%s) "
873 "version %d.%02d",*product_family,*major_version,*minor_version);
877 static int NTGhostscriptGetString(const char *name,char *value,
888 *product_family = NULL;
904 { HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
905 { HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" }
909 Get a string from the installed Ghostscript.
912 if (product_family == NULL)
913 (void) NTGhostscriptFind(&product_family,&major_version,&minor_version);
914 if (product_family == NULL)
916 (void) FormatMagickString(key,MaxTextExtent,"SOFTWARE\\%s\\%d.%02d",
917 product_family,major_version,minor_version);
918 for (i=0; i < sizeof(hkeys)/sizeof(hkeys[0]); i++)
921 if (NTGetRegistryValue(hkeys[i].hkey,key,name,value,&extent) == 0)
923 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
924 "registry: \"%s\\%s\\%s\"=\"%s\"",hkeys[i].name,key,name,value);
927 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
928 "registry: \"%s\\%s\\%s\" (failed)",hkeys[i].name,key,name);
933 MagickExport int NTGhostscriptDLL(char *path,int length)
936 dll_path[MaxTextExtent];
939 if (NTGhostscriptGetString("GS_DLL",dll_path,sizeof(dll_path)) == 0)
941 (void) CopyMagickString(path,dll_path,length);
946 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
950 % N T G h o s t s c r i p t D L L V e c t o r s %
954 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
956 % NTGhostscriptDLLVectors() returns a GhostscriptVectors structure that
957 % contain function vectors to invoke Ghostscript DLL functions. A null
958 % pointer is returned if there is an error when loading the DLL or
959 % retrieving the function vectors.
961 % The format of the NTGhostscriptDLLVectors method is:
963 % const GhostscriptVectors *NTGhostscriptDLLVectors(void)
966 MagickExport const GhostscriptVectors *NTGhostscriptDLLVectors(void)
968 if (NTGhostscriptLoadDLL() == FALSE)
969 return((GhostscriptVectors *) NULL);
970 return(&ghostscript_vectors);
974 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
978 % N T G h o s t s c r i p t E X E %
982 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
984 % NTGhostscriptEXE() obtains the path to the latest Ghostscript executable.
985 % The method returns FALSE if a full path value is not obtained and returns
986 % a default path of gswin32c.exe.
988 % The format of the NTGhostscriptEXE method is:
990 % int NTGhostscriptEXE(char *path,int length)
992 % A description of each parameter follows:
994 % o path: return the Ghostscript executable path here.
996 % o length: length of buffer.
999 MagickExport int NTGhostscriptEXE(char *path,int length)
1005 executable[MaxTextExtent] = { "" };
1007 if (*executable != '\0')
1009 (void) CopyMagickString(path,executable,length);
1012 (void) CopyMagickString(path,"gswin32c.exe",length);
1013 if (NTGhostscriptGetString("GS_DLL",executable,sizeof(executable)) == FALSE)
1015 p=strrchr(executable, '\\');
1016 if (p == (char *) NULL)
1020 (void) CopyMagickString(p,path,sizeof(executable)-strlen(executable));
1021 (void) CopyMagickString(path,executable,length);
1026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1030 % N T G h o s t s c r i p t F o n t s %
1034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1036 % NTGhostscriptFonts() obtains the path to the Ghostscript fonts. The method
1037 % returns FALSE if it cannot determine the font path.
1039 % The format of the NTGhostscriptFonts method is:
1041 % int NTGhostscriptFonts(char *path, int length)
1043 % A description of each parameter follows:
1045 % o path: return the font path here.
1047 % o length: length of the path buffer.
1050 MagickExport int NTGhostscriptFonts(char *path,int length)
1053 buffer[MaxTextExtent],
1054 filename[MaxTextExtent];
1061 if (NTGhostscriptGetString("GS_LIB",buffer,MaxTextExtent) == FALSE)
1063 for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
1065 (void) CopyMagickString(path,p+1,length+1);
1066 q=strchr(path,DirectoryListSeparator);
1067 if (q != (char *) NULL)
1069 (void) FormatMagickString(filename,MaxTextExtent,"%s%sfonts.dir",path,
1070 DirectorySeparator);
1071 if (IsPathAccessible(filename) != MagickFalse)
1078 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1082 % N T G h o s t s c r i p t L o a d D L L %
1086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1088 % NTGhostscriptLoadDLL() attempts to load the Ghostscript DLL and returns
1089 % TRUE if it succeeds.
1091 % The format of the NTGhostscriptLoadDLL method is:
1093 % int NTGhostscriptLoadDLL(void)
1097 MagickExport int NTGhostscriptLoadDLL(void)
1100 path[MaxTextExtent];
1102 if (ghostscript_handle != (void *) NULL)
1104 if (NTGhostscriptDLL(path,sizeof(path)) == FALSE)
1106 ghostscript_handle=lt_dlopen(path);
1107 if (ghostscript_handle == (void *) NULL)
1109 (void) ResetMagickMemory((void *) &ghostscript_vectors,0,
1110 sizeof(GhostscriptVectors));
1111 ghostscript_vectors.exit=(int (MagickDLLCall *)(gs_main_instance*))
1112 lt_dlsym(ghostscript_handle,"gsapi_exit");
1113 ghostscript_vectors.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,
1114 int,char **)) (lt_dlsym(ghostscript_handle,"gsapi_init_with_args"));
1115 ghostscript_vectors.new_instance=(int (MagickDLLCall *)(gs_main_instance **,
1116 void *)) (lt_dlsym(ghostscript_handle,"gsapi_new_instance"));
1117 ghostscript_vectors.run_string=(int (MagickDLLCall *)(gs_main_instance *,
1118 const char *,int,int *)) (lt_dlsym(ghostscript_handle,"gsapi_run_string"));
1119 ghostscript_vectors.delete_instance=(void (MagickDLLCall *) (gs_main_instance
1120 *)) (lt_dlsym(ghostscript_handle,"gsapi_delete_instance"));
1121 if ((ghostscript_vectors.exit == NULL) ||
1122 (ghostscript_vectors.init_with_args == NULL) ||
1123 (ghostscript_vectors.new_instance == NULL) ||
1124 (ghostscript_vectors.run_string == NULL) ||
1125 (ghostscript_vectors.delete_instance == NULL))
1131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1135 % N T G h o s t s c r i p t U n L o a d D L L %
1139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1141 % NTGhostscriptUnLoadDLL() unloads the Ghostscript DLL and returns TRUE if
1144 % The format of the NTGhostscriptUnLoadDLL method is:
1146 % int NTGhostscriptUnLoadDLL(void)
1149 MagickExport int NTGhostscriptUnLoadDLL(void)
1154 if (ghostscript_handle == (void *) NULL)
1156 status=lt_dlclose(ghostscript_handle);
1157 ghostscript_handle=(void *) NULL;
1158 (void) ResetMagickMemory((void *) &ghostscript_vectors,0,
1159 sizeof(GhostscriptVectors));
1164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1168 % N T I n i t i a l i z e L i b r a r y %
1172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1174 % NTInitializeLibrary() initializes the dynamic module loading subsystem.
1176 % The format of the NTInitializeLibrary method is:
1178 % int NTInitializeLibrary(void)
1181 MagickExport int NTInitializeLibrary(void)
1187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1191 + N T M a p M e m o r y %
1195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1197 % Mmap() emulates the Unix method of the same name.
1199 % The format of the NTMapMemory method is:
1201 % MagickExport void *NTMapMemory(char *address,size_t length,int protection,
1202 % int access,int file,MagickOffsetType offset)
1205 MagickExport void *NTMapMemory(char *address,size_t length,int protection,
1206 int flags,int file,MagickOffsetType offset)
1224 file_handle=INVALID_HANDLE_VALUE;
1225 low_length=(DWORD) (length & 0xFFFFFFFFUL);
1226 high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
1227 map_handle=INVALID_HANDLE_VALUE;
1229 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
1230 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
1232 if (protection & PROT_WRITE)
1234 access_mode=FILE_MAP_WRITE;
1235 if (!(flags & MAP_PRIVATE))
1236 protection_mode=PAGE_READWRITE;
1239 access_mode=FILE_MAP_COPY;
1240 protection_mode=PAGE_WRITECOPY;
1244 if (protection & PROT_READ)
1246 access_mode=FILE_MAP_READ;
1247 protection_mode=PAGE_READONLY;
1249 if ((file == -1) && (flags & MAP_ANONYMOUS))
1250 file_handle=INVALID_HANDLE_VALUE;
1252 file_handle=(HANDLE) _get_osfhandle(file);
1253 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
1257 map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
1259 CloseHandle(map_handle);
1261 if (map == (void *) NULL)
1262 return((void *) MAP_FAILED);
1263 return((void *) ((char *) map));
1267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1271 % N T O p e n D i r e c t o r y %
1275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1277 % NTOpenDirectory() opens the directory named by filename and associates a
1278 % directory stream with it.
1280 % The format of the NTOpenDirectory method is:
1282 % DIR *NTOpenDirectory(const char *path)
1284 % A description of each parameter follows:
1286 % o entry: Specifies a pointer to a DIR structure.
1289 MagickExport DIR *NTOpenDirectory(const char *path)
1292 file_specification[MaxTextExtent];
1300 assert(path != (const char *) NULL);
1301 length=CopyMagickString(file_specification,path,MaxTextExtent);
1302 if (length >= MaxTextExtent)
1303 return((DIR *) NULL);
1304 length=ConcatenateMagickString(file_specification,DirectorySeparator,
1306 if (length >= MaxTextExtent)
1307 return((DIR *) NULL);
1308 entry=(DIR *) AcquireMagickMemory(sizeof(DIR));
1309 if (entry != (DIR *) NULL)
1311 entry->firsttime=TRUE;
1312 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1314 if (entry->hSearch == INVALID_HANDLE_VALUE)
1316 length=ConcatenateMagickString(file_specification,"\\*.*",MaxTextExtent);
1317 if (length >= MaxTextExtent)
1319 entry=(DIR *) RelinquishMagickMemory(entry);
1320 return((DIR *) NULL);
1322 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1323 if (entry->hSearch == INVALID_HANDLE_VALUE)
1325 entry=(DIR *) RelinquishMagickMemory(entry);
1326 return((DIR *) NULL);
1333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1337 % N T O p e n L i b r a r y %
1341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1343 % NTOpenLibrary() loads a dynamic module into memory and returns a handle that
1344 % can be used to access the various procedures in the module.
1346 % The format of the NTOpenLibrary method is:
1348 % void *NTOpenLibrary(const char *filename)
1350 % A description of each parameter follows:
1352 % o path: Specifies a pointer to string representing dynamic module that
1357 static const char *GetSearchPath( void )
1359 #if defined(MAGICKCORE_LTDL_DELEGATE)
1360 return(lt_dlgetsearchpath());
1362 return(lt_slsearchpath);
1366 MagickExport void *NTOpenLibrary(const char *filename)
1368 #define MaxPathElements 31
1371 buffer[MaxTextExtent];
1389 mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
1390 handle=(void *) LoadLibraryEx(filename,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1391 if ((handle != (void *) NULL) || (GetSearchPath() == (char *) NULL))
1396 p=(char *) GetSearchPath();
1398 while (index < MaxPathElements)
1400 q=strchr(p,DirectoryListSeparator);
1401 if (q == (char *) NULL)
1403 (void) CopyMagickString(buffer,p,MaxTextExtent);
1404 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
1405 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
1406 handle=(void *) LoadLibraryEx(buffer,NULL,
1407 LOAD_WITH_ALTERED_SEARCH_PATH);
1411 (void) CopyMagickString(buffer,p,i+1);
1412 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
1413 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
1414 handle=(void *) LoadLibraryEx(buffer,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1415 if (handle != (void *) NULL)
1424 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1428 % N T R e a d D i r e c t o r y %
1432 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1434 % NTReadDirectory() returns a pointer to a structure representing the
1435 % directory entry at the current position in the directory stream to which
1438 % The format of the NTReadDirectory
1440 % NTReadDirectory(entry)
1442 % A description of each parameter follows:
1444 % o entry: Specifies a pointer to a DIR structure.
1447 MagickExport struct dirent *NTReadDirectory(DIR *entry)
1455 if (entry == (DIR *) NULL)
1456 return((struct dirent *) NULL);
1457 if (!entry->firsttime)
1459 status=FindNextFile(entry->hSearch,&entry->Win32FindData);
1461 return((struct dirent *) NULL);
1463 length=CopyMagickString(entry->file_info.d_name,
1464 entry->Win32FindData.cFileName,sizeof(entry->file_info.d_name));
1465 if (length >= sizeof(entry->file_info.d_name))
1466 return((struct dirent *) NULL);
1467 entry->firsttime=FALSE;
1468 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
1469 return(&entry->file_info);
1473 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1477 % N T R e g i s t r y K e y L o o k u p %
1481 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1483 % NTRegistryKeyLookup() returns ImageMagick installation path settings
1484 % stored in the Windows Registry. Path settings are specific to the
1485 % installed ImageMagick version so that multiple Image Magick installations
1488 % Values are stored in the registry under a base path path similar to
1489 % "HKEY_LOCAL_MACHINE/SOFTWARE\ImageMagick\5.5.7\Q:16". The provided subkey
1490 % is appended to this base path to form the full key.
1492 % The format of the NTRegistryKeyLookup method is:
1494 % unsigned char *NTRegistryKeyLookup(const char *subkey)
1496 % A description of each parameter follows:
1498 % o subkey: Specifies a string that identifies the registry object.
1499 % Currently supported sub-keys include: "BinPath", "ConfigurePath",
1500 % "LibPath", "CoderModulesPath", "FilterModulesPath", "SharePath".
1503 MagickExport unsigned char *NTRegistryKeyLookup(const char *subkey)
1506 package_key[MaxTextExtent];
1524 (void) FormatMagickString(package_key,MaxTextExtent,"SOFTWARE\\%s\\%s\\Q:%d",
1525 MagickPackageName,MagickLibVersionText,MAGICKCORE_QUANTUM_DEPTH);
1526 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",package_key);
1527 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1528 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,package_key,0,KEY_READ,®istry_key);
1529 if (status != ERROR_SUCCESS)
1531 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1532 return((unsigned char *) NULL);
1538 value=(unsigned char *) AcquireQuantumMemory(size,sizeof(*value));
1539 if (value == (unsigned char *) NULL)
1541 RegCloseKey(registry_key);
1542 return((unsigned char *) NULL);
1544 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",subkey);
1545 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1546 if ((status == ERROR_MORE_DATA) && (type == REG_SZ))
1548 value=(unsigned char *) ResizeQuantumMemory(value,size,sizeof(*value));
1549 if (value == (BYTE *) NULL)
1551 RegCloseKey(registry_key);
1552 return((unsigned char *) NULL);
1554 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1556 RegCloseKey(registry_key);
1557 if ((type != REG_SZ) || (status != ERROR_SUCCESS))
1558 value=(unsigned char *) RelinquishMagickMemory(value);
1559 return((unsigned char *) value);
1563 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1567 % N T R e p o r t E v e n t %
1571 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1573 % NTReportEvent() reports an event.
1575 % The format of the NTReportEvent method is:
1577 % MagickBooleanType NTReportEvent(const char *event,
1578 % const MagickBooleanType error)
1580 % A description of each parameter follows:
1582 % o event: the event.
1584 % o error: MagickTrue the event is an error.
1587 MagickExport MagickBooleanType NTReportEvent(const char *event,
1588 const MagickBooleanType error)
1599 handle=RegisterEventSource(NULL,MAGICKCORE_PACKAGE_NAME);
1601 return(MagickFalse);
1603 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
1604 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
1605 DeregisterEventSource(handle);
1610 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1614 % N T R e s o u r c e T o B l o b %
1618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1620 % NTResourceToBlob() returns a blob containing the contents of the resource
1621 % in the current executable specified by the id parameter. This currently
1622 % used to retrieve MGK files tha have been embedded into the various command
1625 % The format of the NTResourceToBlob method is:
1627 % unsigned char *NTResourceToBlob(const char *id)
1629 % A description of each parameter follows:
1631 % o id: Specifies a string that identifies the resource.
1634 MagickExport unsigned char *NTResourceToBlob(const char *id)
1637 path[MaxTextExtent];
1655 assert(id != (const char *) NULL);
1656 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
1657 (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",GetClientPath(),
1658 DirectorySeparator,GetClientName());
1659 if (IsPathAccessible(path) != MagickFalse)
1660 handle=GetModuleHandle(path);
1662 handle=GetModuleHandle(0);
1664 return((unsigned char *) NULL);
1665 resource=FindResource(handle,id,"IMAGEMAGICK");
1667 return((unsigned char *) NULL);
1668 global=LoadResource(handle,resource);
1670 return((unsigned char *) NULL);
1671 length=SizeofResource(handle,resource);
1672 value=(unsigned char *) LockResource(global);
1675 FreeResource(global);
1676 return((unsigned char *) NULL);
1678 blob=(unsigned char *) AcquireQuantumMemory(length+MaxTextExtent,
1680 if (blob != (unsigned char *) NULL)
1682 (void) CopyMagickMemory(blob,value,length);
1685 UnlockResource(global);
1686 FreeResource(global);
1691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1695 % N T S e e k D i r e c t o r y %
1699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1701 % NTSeekDirectory() sets the position of the next NTReadDirectory() operation
1702 % on the directory stream.
1704 % The format of the NTSeekDirectory method is:
1706 % void NTSeekDirectory(DIR *entry,long position)
1708 % A description of each parameter follows:
1710 % o entry: Specifies a pointer to a DIR structure.
1712 % o position: specifies the position associated with the directory
1716 MagickExport void NTSeekDirectory(DIR *entry,long position)
1718 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1719 assert(entry != (DIR *) NULL);
1723 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1727 % N T S e t S e a r c h P a t h %
1731 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1733 % NTSetSearchPath() sets the current locations that the subsystem should
1734 % look at to find dynamically loadable modules.
1736 % The format of the NTSetSearchPath method is:
1738 % int NTSetSearchPath(const char *path)
1740 % A description of each parameter follows:
1742 % o path: Specifies a pointer to string representing the search path
1743 % for DLL's that can be dynamically loaded.
1746 MagickExport int NTSetSearchPath(const char *path)
1748 #if defined(MAGICKCORE_LTDL_DELEGATE)
1749 lt_dlsetsearchpath(path);
1751 if (lt_slsearchpath != (char *) NULL)
1752 lt_slsearchpath=DestroyString(lt_slsearchpath);
1753 if (path != (char *) NULL)
1754 lt_slsearchpath=AcquireString(path);
1760 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1764 + N T S y n c M e m o r y %
1768 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1770 % NTSyncMemory() emulates the Unix method of the same name.
1772 % The format of the NTSyncMemory method is:
1774 % int NTSyncMemory(void *address,size_t length,int flags)
1776 % A description of each parameter follows:
1778 % o address: the address of the binary large object.
1780 % o length: the length of the binary large object.
1782 % o flags: Option flags (ignored for Windows).
1785 MagickExport int NTSyncMemory(void *address,size_t length,int flags)
1787 if (FlushViewOfFile(address,length) == MagickFalse)
1793 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1797 % N T S y s t e m C o m m a n d %
1801 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1803 % NTSystemCommand() executes the specified command and waits until it
1804 % terminates. The returned value is the exit status of the command.
1806 % The format of the NTSystemCommand method is:
1808 % int NTSystemCommand(const char *command)
1810 % A description of each parameter follows:
1812 % o command: This string is the command to execute.
1815 MagickExport int NTSystemCommand(const char *command)
1818 local_command[MaxTextExtent];
1835 if (command == (char *) NULL)
1837 GetStartupInfo(&startup_info);
1838 startup_info.dwFlags=STARTF_USESHOWWINDOW;
1839 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
1840 (void) CopyMagickString(local_command,command,MaxTextExtent);
1841 background_process=command[strlen(command)-1] == '&' ? MagickTrue :
1843 if (background_process)
1844 local_command[strlen(command)-1]='\0';
1845 if (command[strlen(command)-1] == '|')
1846 local_command[strlen(command)-1]='\0';
1848 startup_info.wShowWindow=SW_SHOWDEFAULT;
1849 status=CreateProcess((LPCTSTR) NULL,local_command,
1850 (LPSECURITY_ATTRIBUTES) NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) FALSE,
1851 (DWORD) NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
1855 if (background_process)
1856 return(status == 0);
1857 status=WaitForSingleObject(process_info.hProcess,INFINITE);
1858 if (status != WAIT_OBJECT_0)
1860 status=GetExitCodeProcess(process_info.hProcess,&child_status);
1863 CloseHandle(process_info.hProcess);
1864 CloseHandle(process_info.hThread);
1865 return((int) child_status);
1869 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1873 % N T S y s t e m C o n i f i g u r a t i o n %
1877 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1879 % NTSystemConfiguration() provides a way for the application to determine
1880 % values for system limits or options at runtime.
1882 % The format of the exit method is:
1884 % long NTSystemConfiguration(int name)
1886 % A description of each parameter follows:
1888 % o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
1891 MagickExport long NTSystemConfiguration(int name)
1900 GetSystemInfo(&system_info);
1901 return(system_info.dwPageSize);
1903 case _SC_PHYS_PAGES:
1917 handle=GetModuleHandle("kernel32.dll");
1918 if (handle == (HMODULE) NULL)
1920 GetSystemInfo(&system_info);
1921 module=(LPFNDLLFUNC2) NTGetLibrarySymbol(handle,"GlobalMemoryStatusEx");
1922 if (module == (LPFNDLLFUNC2) NULL)
1927 GlobalMemoryStatus(&status);
1928 return((long) status.dwTotalPhys/system_info.dwPageSize);
1930 status.dwLength=sizeof(status);
1931 if (module(&status) == 0)
1933 return((long) status.ullTotalPhys/system_info.dwPageSize);
1944 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1948 % N T T e l l D i r e c t o r y %
1952 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1954 % NTTellDirectory() returns the current location associated with the named
1957 % The format of the NTTellDirectory method is:
1959 % long NTTellDirectory(DIR *entry)
1961 % A description of each parameter follows:
1963 % o entry: Specifies a pointer to a DIR structure.
1966 MagickExport long NTTellDirectory(DIR *entry)
1968 assert(entry != (DIR *) NULL);
1973 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1977 % N T T r u n c a t e F i l e %
1981 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1983 % NTTruncateFile() truncates a file to a specified length.
1985 % The format of the NTTruncateFile method is:
1987 % int NTTruncateFile(int file,off_t length)
1989 % A description of each parameter follows:
1993 % o length: the file length.
1996 MagickExport int NTTruncateFile(int file,off_t length)
2006 file_handle=_get_osfhandle(file);
2007 if (file_handle == -1L)
2009 low=(long) (length & 0xffffffffUL);
2010 high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
2011 file_pointer=SetFilePointer((HANDLE) file_handle,low,&high,FILE_BEGIN);
2012 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
2014 if (SetEndOfFile((HANDLE) file_handle) == 0)
2020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2024 + N T U n m a p M e m o r y %
2028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2030 % NTUnmapMemory() emulates the Unix munmap method.
2032 % The format of the NTUnmapMemory method is:
2034 % int NTUnmapMemory(void *map,size_t length)
2036 % A description of each parameter follows:
2038 % o map: the address of the binary large object.
2040 % o length: the length of the binary large object.
2043 MagickExport int NTUnmapMemory(void *map,size_t length)
2045 if (UnmapViewOfFile(map) == 0)
2051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2055 % N T U s e r T i m e %
2059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2061 % NTUserTime() returns the total time the process has been scheduled (e.g.
2062 % seconds) since the last call to StartTimer().
2064 % The format of the UserTime method is:
2066 % double NTUserTime(void)
2069 MagickExport double NTUserTime(void)
2099 OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
2100 GetVersionEx(&OsVersionInfo);
2101 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
2102 return(NTElapsedTime());
2103 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
2104 &kernel_time.filetime,&user_time.filetime);
2107 return((double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
2111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2115 % N T W a r n i n g H a n d l e r %
2119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2121 % NTWarningHandler() displays a warning reason.
2123 % The format of the NTWarningHandler method is:
2125 % void NTWarningHandler(const ExceptionType warning,const char *reason,
2126 % const char *description)
2128 % A description of each parameter follows:
2130 % o warning: Specifies the numeric warning category.
2132 % o reason: Specifies the reason to display before terminating the
2135 % o description: Specifies any description to the reason.
2138 MagickExport void NTWarningHandler(const ExceptionType warning,
2139 const char *reason,const char *description)
2142 buffer[2*MaxTextExtent];
2144 if (reason == (char *) NULL)
2146 if (description == (char *) NULL)
2147 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s.\n",GetClientName(),
2150 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s (%s).\n",
2151 GetClientName(),reason,description);
2152 (void) MessageBox(NULL,buffer,"ImageMagick Warning",MB_OK | MB_TASKMODAL |
2153 MB_SETFOREGROUND | MB_ICONINFORMATION);