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;
80 *ghost_handle = (void *) NULL;
83 External declarations.
85 #if !defined(__WINDOWS__)
86 extern "C" BOOL WINAPI
87 DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved);
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 % DllMain() is an entry point to the DLL which is called when processes and
102 % threads are initialized and terminated, or upon calls to the Windows
103 % LoadLibrary and FreeLibrary functions.
105 % The function returns TRUE of it succeeds, or FALSE if initialization fails.
107 % The format of the DllMain method is:
109 % BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
111 % A description of each parameter follows:
113 % o handle: handle to the DLL module
115 % o reason: reason for calling function:
117 % DLL_PROCESS_ATTACH - DLL is being loaded into virtual address
118 % space of current process.
119 % DLL_THREAD_ATTACH - Indicates that the current process is
120 % creating a new thread. Called under the
121 % context of the new thread.
122 % DLL_THREAD_DETACH - Indicates that the thread is exiting.
123 % Called under the context of the exiting
125 % DLL_PROCESS_DETACH - Indicates that the DLL is being unloaded
126 % from the virtual address space of the
129 % o lpvReserved: Used for passing additional info during DLL_PROCESS_ATTACH
130 % and DLL_PROCESS_DETACH.
133 #if defined(_DLL) && defined( ProvideDllMain )
134 BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
138 case DLL_PROCESS_ATTACH:
146 module_path=(char *) AcquireQuantumMemory(MaxTextExtent,
147 sizeof(*module_path));
148 if (module_path == (char *) NULL)
150 count=(ssize_t) GetModuleFileName(handle,module_path,MaxTextExtent);
156 for ( ; count > 0; count--)
157 if (module_path[count] == '\\')
159 module_path[count+1]='\0';
162 MagickCoreGenesis(module_path,MagickFalse);
163 path=(char *) AcquireQuantumMemory(16UL*MaxTextExtent,sizeof(*path));
164 if (path == (char *) NULL)
166 module_path=DestroyString(module_path);
169 count=(ssize_t) GetEnvironmentVariable("PATH",path,16*MaxTextExtent);
170 if ((count != 0) && (strstr(path,module_path) == (char *) NULL))
172 if ((strlen(module_path)+count+1) < (16*MaxTextExtent-1))
177 variable=(char *) AcquireQuantumMemory(16UL*MaxTextExtent,
179 if (variable == (char *) NULL)
181 path=DestroyString(path);
182 module_path=DestroyString(module_path);
185 (void) FormatMagickString(variable,16*MaxTextExtent,
186 "%s;%s",module_path,path);
187 SetEnvironmentVariable("PATH",variable);
188 variable=DestroyString(variable);
191 path=DestroyString(path);
193 module_path=DestroyString(module_path);
196 case DLL_PROCESS_DETACH:
198 MagickCoreTerminus();
209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219 % Exit() calls TerminateProcess for Win95.
221 % The format of the exit method is:
223 % int Exit(int status)
225 % A description of each parameter follows:
227 % o status: an integer value representing the status of the terminating
231 MagickExport int Exit(int status)
234 TerminateProcess(GetCurrentProcess(),(unsigned int) status);
240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 % 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)
353 AsynchronousResourceComponentTerminus();
357 MagickExport int NTControlHandler(void)
359 return(SetConsoleCtrlHandler((PHANDLER_ROUTINE) ControlHandler,TRUE));
363 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
367 % N T E l a p s e d T i m e %
371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
373 % NTElapsedTime() returns the elapsed time (in seconds) since the last call to
376 % The format of the ElapsedTime method is:
378 % double NTElapsedTime(void)
381 MagickExport double NTElapsedTime(void)
395 GetSystemTime(&system_time);
396 SystemTimeToFileTime(&system_time,&elapsed_time.filetime);
397 return((double) 1.0e-7*elapsed_time.filetime64);
401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
405 + N T E r r o r H a n d l e r %
409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411 % NTErrorHandler() displays an error reason and then terminates the program.
413 % The format of the NTErrorHandler method is:
415 % void NTErrorHandler(const ExceptionType severity,const char *reason,
416 % const char *description)
418 % A description of each parameter follows:
420 % o severity: Specifies the numeric error category.
422 % o reason: Specifies the reason to display before terminating the
425 % o description: Specifies any description to the reason.
428 MagickExport void NTErrorHandler(const ExceptionType severity,
429 const char *reason,const char *description)
432 buffer[3*MaxTextExtent],
436 if (reason == (char *) NULL)
438 MagickCoreTerminus();
441 message=GetExceptionMessage(errno);
442 if ((description != (char *) NULL) && errno)
443 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s (%s) [%s].\n",
444 GetClientName(),reason,description,message);
446 if (description != (char *) NULL)
447 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s (%s).\n",
448 GetClientName(),reason,description);
451 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s [%s].\n",
452 GetClientName(),reason,message);
454 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s.\n",
455 GetClientName(),reason);
456 message=DestroyString(message);
457 (void) MessageBox(NULL,buffer,"ImageMagick Exception",MB_OK | MB_TASKMODAL |
458 MB_SETFOREGROUND | MB_ICONEXCLAMATION);
459 MagickCoreTerminus();
464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
468 % N T E x i t L i b r a r y %
472 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
474 % NTExitLibrary() exits the dynamic module loading subsystem.
476 % The format of the NTExitLibrary method is:
478 % int NTExitLibrary(void)
481 MagickExport int NTExitLibrary(void)
487 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
491 % N T G a t h e r R a n d o m D a t a %
495 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
497 % NTGatherRandomData() gathers random data and returns it.
499 % The format of the GatherRandomData method is:
501 % MagickBooleanType NTGatherRandomData(const size_t length,
502 % unsigned char *random)
504 % A description of each parameter follows:
506 % length: the length of random data buffer
508 % random: the random data is returned here.
511 MagickExport MagickBooleanType NTGatherRandomData(const size_t length,
512 unsigned char *random)
514 #if defined(MAGICKCORE_CIPHER_SUPPORT) && defined(_MSC_VER) && (_MSC_VER > 1200)
521 handle=(HCRYPTPROV) NULL;
522 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
523 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET));
525 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
526 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET));
529 status=CryptGenRandom(handle,(DWORD) length,random);
532 status=CryptReleaseContext(handle,0);
535 status=CryptReleaseContext(handle,0);
546 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
550 % N T G e t E x e c u t i o n P a t h %
554 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
556 % NTGetExecutionPath() returns the execution path of a program.
558 % The format of the GetExecutionPath method is:
560 % MagickBooleanType NTGetExecutionPath(char *path,const size_t extent)
562 % A description of each parameter follows:
564 % o path: the pathname of the executable that started the process.
566 % o extent: the maximum extent of the path.
569 MagickExport MagickBooleanType NTGetExecutionPath(char *path,
572 GetModuleFileName(0,path,(DWORD) extent);
577 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
581 % N T G e t L a s t E r r o r %
585 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
587 % NTGetLastError() returns the last error that occurred.
589 % The format of the NTGetLastError method is:
591 % char *NTGetLastError(void)
594 char *NTGetLastError(void)
605 status=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
606 FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),
607 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR) &buffer,0,NULL);
609 reason=AcquireString("An unknown error occurred");
612 reason=AcquireString((const char *) buffer);
619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
623 % N T G e t L i b r a r y E r r o r %
627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
629 % Lt_dlerror() returns a pointer to a string describing the last error
630 % associated with a lt_dl method. Note that this function is not thread
631 % safe so it should only be used under the protection of a lock.
633 % The format of the NTGetLibraryError method is:
635 % const char *NTGetLibraryError(void)
638 MagickExport const char *NTGetLibraryError(void)
641 last_error[MaxTextExtent];
647 error=NTGetLastError();
649 (void) CopyMagickString(last_error,error,MaxTextExtent);
650 error=DestroyString(error);
655 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
659 % N T G e t L i b r a r y S y m b o l %
663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
665 % NTGetLibrarySymbol() retrieve the procedure address of the method
666 % specified by the passed character string.
668 % The format of the NTGetLibrarySymbol method is:
670 % void *NTGetLibrarySymbol(void *handle,const char *name)
672 % A description of each parameter follows:
674 % o handle: Specifies a handle to the previously loaded dynamic module.
676 % o name: Specifies the procedure entry point to be returned.
679 void *NTGetLibrarySymbol(void *handle,const char *name)
684 lpfnDllFunc1=(LPFNDLLFUNC1) GetProcAddress((HINSTANCE) handle,name);
686 return((void *) NULL);
687 return((void *) lpfnDllFunc1);
691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
695 % N T G e t M o d u l e P a t h %
699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
701 % NTGetModulePath() returns the path of the specified module.
703 % The format of the GetModulePath method is:
705 % MagickBooleanType NTGetModulePath(const char *module,char *path)
707 % A description of each parameter follows:
709 % modith: the module name.
711 % path: the module path is returned here.
714 MagickExport MagickBooleanType NTGetModulePath(const char *module,char *path)
717 module_path[MaxTextExtent];
726 handle=GetModuleHandle(module);
727 if (handle == (HMODULE) NULL)
729 length=GetModuleFileName(handle,module_path,MaxTextExtent);
731 GetPathComponent(module_path,HeadPath,path);
736 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
740 % N T G h o s t s c r i p t D L L %
744 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
746 % NTGhostscriptDLL() returns the path to the most recent Ghostscript version
747 % DLL. The method returns TRUE on success otherwise FALSE.
749 % The format of the NTGhostscriptDLL method is:
751 % int NTGhostscriptDLL(char *path,int length)
753 % A description of each parameter follows:
755 % o path: return the Ghostscript DLL path here.
757 % o length: the buffer length.
761 static int NTGetRegistryValue(HKEY root,const char *key,const char *name,
762 char *value,int *length)
779 Get a registry value: key = root\\key, named value = name.
781 if (RegOpenKeyExA(root,key,0,KEY_READ,&hkey) != ERROR_SUCCESS)
782 return(1); /* no match */
786 if (p == (BYTE *) NULL)
787 p=(&byte); /* ERROR_MORE_DATA only if value is NULL */
788 status=RegQueryValueExA(hkey,(char *) name,0,&type,p,&extent);
790 if (status == ERROR_SUCCESS)
793 return(0); /* return the match */
795 if (status == ERROR_MORE_DATA)
798 return(-1); /* buffer not large enough */
800 return(1); /* not found */
803 static int NTLocateGhostscript(const char **product_family,int *major_version,
818 "Aladdin Ghostscript"
822 Find the most recent version of Ghostscript.
825 *product_family=NULL;
827 *minor_version=49; /* min version of Ghostscript is 5.50 */
828 for (i=0; i < (long) (sizeof(products)/sizeof(products[0])); i++)
840 (void) FormatMagickString(key,MaxTextExtent,"SOFTWARE\\%s",products[i]);
841 root=HKEY_LOCAL_MACHINE;
843 #if defined(KEY_WOW64_32KEY)
844 mode|=KEY_WOW64_32KEY;
846 if (RegOpenKeyExA(root,key,0,mode,&hkey) == ERROR_SUCCESS)
855 Now enumerate the keys.
857 extent=sizeof(key)/sizeof(char);
858 for (j=0; RegEnumKeyA(hkey,j,key,extent) == ERROR_SUCCESS; j++)
866 if (sscanf(key,"%d.%d",&major,&minor) != 2)
868 if ((major > *major_version) || ((major == *major_version) &&
869 (minor > *minor_version)))
871 *product_family=products[i];
872 *major_version=major;
873 *minor_version=minor;
877 (void) RegCloseKey(hkey);
886 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"Ghostscript (%s) "
887 "version %d.%02d",*product_family,*major_version,*minor_version);
891 static int NTGhostscriptGetString(const char *name,char *value,
902 *product_family = (const char *) NULL;
918 { HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
919 { HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" }
923 Get a string from the installed Ghostscript.
926 if (product_family == NULL)
927 (void) NTLocateGhostscript(&product_family,&major_version,&minor_version);
928 if (product_family == NULL)
930 (void) FormatMagickString(key,MaxTextExtent,"SOFTWARE\\%s\\%d.%02d",
931 product_family,major_version,minor_version);
932 for (i=0; i < (long) (sizeof(hkeys)/sizeof(hkeys[0])); i++)
935 if (NTGetRegistryValue(hkeys[i].hkey,key,name,value,&extent) == 0)
937 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
938 "registry: \"%s\\%s\\%s\"=\"%s\"",hkeys[i].name,key,name,value);
941 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
942 "registry: \"%s\\%s\\%s\" (failed)",hkeys[i].name,key,name);
947 MagickExport int NTGhostscriptDLL(char *path,int length)
950 dll[MaxTextExtent] = { "" };
953 if ((*dll == '\0') &&
954 (NTGhostscriptGetString("GS_DLL",dll,sizeof(dll)) == FALSE))
956 (void) CopyMagickString(path,dll,length);
961 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
965 % N T G h o s t s c r i p t D L L V e c t o r s %
969 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
971 % NTGhostscriptDLLVectors() returns a GhostInfo structure that includes
972 % function vectors to invoke Ghostscript DLL functions. A null pointer is
973 % returned if there is an error when loading the DLL or retrieving the
976 % The format of the NTGhostscriptDLLVectors method is:
978 % const GhostInfo *NTGhostscriptDLLVectors(void)
981 MagickExport const GhostInfo *NTGhostscriptDLLVectors(void)
983 if (NTGhostscriptLoadDLL() == FALSE)
984 return((GhostInfo *) NULL);
989 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
993 % N T G h o s t s c r i p t E X E %
997 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
999 % NTGhostscriptEXE() obtains the path to the latest Ghostscript executable.
1000 % The method returns FALSE if a full path value is not obtained and returns
1001 % a default path of gswin32c.exe.
1003 % The format of the NTGhostscriptEXE method is:
1005 % int NTGhostscriptEXE(char *path,int length)
1007 % A description of each parameter follows:
1009 % o path: return the Ghostscript executable path here.
1011 % o length: length of buffer.
1014 MagickExport int NTGhostscriptEXE(char *path,int length)
1020 program[MaxTextExtent] = { "" };
1022 (void) CopyMagickString(path,"gswin32c.exe",length);
1023 if ((*program == '\0') &&
1024 (NTGhostscriptGetString("GS_DLL",program,sizeof(program)) == FALSE))
1026 p=strrchr(program,'\\');
1027 if (p != (char *) NULL)
1031 (void) ConcatenateMagickString(program,"gswin32c.exe",sizeof(program));
1033 (void) CopyMagickString(path,program,length);
1038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1042 % N T G h o s t s c r i p t F o n t s %
1046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1048 % NTGhostscriptFonts() obtains the path to the Ghostscript fonts. The method
1049 % returns FALSE if it cannot determine the font path.
1051 % The format of the NTGhostscriptFonts method is:
1053 % int NTGhostscriptFonts(char *path, int length)
1055 % A description of each parameter follows:
1057 % o path: return the font path here.
1059 % o length: length of the path buffer.
1062 MagickExport int NTGhostscriptFonts(char *path,int length)
1065 buffer[MaxTextExtent],
1066 filename[MaxTextExtent];
1073 if (NTGhostscriptGetString("GS_LIB",buffer,MaxTextExtent) == FALSE)
1075 for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
1077 (void) CopyMagickString(path,p+1,length+1);
1078 q=strchr(path,DirectoryListSeparator);
1079 if (q != (char *) NULL)
1081 (void) FormatMagickString(filename,MaxTextExtent,"%s%sfonts.dir",path,
1082 DirectorySeparator);
1083 if (IsPathAccessible(filename) != MagickFalse)
1090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1094 % N T G h o s t s c r i p t L o a d D L L %
1098 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1100 % NTGhostscriptLoadDLL() attempts to load the Ghostscript DLL and returns
1101 % TRUE if it succeeds.
1103 % The format of the NTGhostscriptLoadDLL method is:
1105 % int NTGhostscriptLoadDLL(void)
1108 MagickExport int NTGhostscriptLoadDLL(void)
1111 path[MaxTextExtent];
1113 if (ghost_handle != (void *) NULL)
1115 if (NTGhostscriptDLL(path,sizeof(path)) == FALSE)
1117 ghost_handle=lt_dlopen(path);
1118 if (ghost_handle == (void *) NULL)
1120 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1121 ghost_info.exit=(int (MagickDLLCall *)(gs_main_instance*))
1122 lt_dlsym(ghost_handle,"gsapi_exit");
1123 ghost_info.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,int,
1124 char **)) (lt_dlsym(ghost_handle,"gsapi_init_with_args"));
1125 ghost_info.new_instance=(int (MagickDLLCall *)(gs_main_instance **,void *)) (
1126 lt_dlsym(ghost_handle,"gsapi_new_instance"));
1127 ghost_info.run_string=(int (MagickDLLCall *)(gs_main_instance *,const char *,
1128 int,int *)) (lt_dlsym(ghost_handle,"gsapi_run_string"));
1129 ghost_info.delete_instance=(void (MagickDLLCall *) (gs_main_instance *)) (
1130 lt_dlsym(ghost_handle,"gsapi_delete_instance"));
1131 if ((ghost_info.exit == NULL) || (ghost_info.init_with_args == NULL) ||
1132 (ghost_info.new_instance == NULL) || (ghost_info.run_string == NULL) ||
1133 (ghost_info.delete_instance == NULL))
1139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1143 % N T G h o s t s c r i p t U n L o a d D L L %
1147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1149 % NTGhostscriptUnLoadDLL() unloads the Ghostscript DLL and returns TRUE if
1152 % The format of the NTGhostscriptUnLoadDLL method is:
1154 % int NTGhostscriptUnLoadDLL(void)
1157 MagickExport int NTGhostscriptUnLoadDLL(void)
1162 if (ghost_handle == (void *) NULL)
1164 status=lt_dlclose(ghost_handle);
1165 ghost_handle=(void *) NULL;
1166 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1175 % N T I n i t i a l i z e L i b r a r y %
1179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1181 % NTInitializeLibrary() initializes the dynamic module loading subsystem.
1183 % The format of the NTInitializeLibrary method is:
1185 % int NTInitializeLibrary(void)
1188 MagickExport int NTInitializeLibrary(void)
1194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1198 + N T M a p M e m o r y %
1202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1204 % Mmap() emulates the Unix method of the same name.
1206 % The format of the NTMapMemory method is:
1208 % MagickExport void *NTMapMemory(char *address,size_t length,int protection,
1209 % int access,int file,MagickOffsetType offset)
1212 MagickExport void *NTMapMemory(char *address,size_t length,int protection,
1213 int flags,int file,MagickOffsetType offset)
1232 file_handle=INVALID_HANDLE_VALUE;
1233 low_length=(DWORD) (length & 0xFFFFFFFFUL);
1234 high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
1235 map_handle=INVALID_HANDLE_VALUE;
1237 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
1238 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
1240 if (protection & PROT_WRITE)
1242 access_mode=FILE_MAP_WRITE;
1243 if (!(flags & MAP_PRIVATE))
1244 protection_mode=PAGE_READWRITE;
1247 access_mode=FILE_MAP_COPY;
1248 protection_mode=PAGE_WRITECOPY;
1252 if (protection & PROT_READ)
1254 access_mode=FILE_MAP_READ;
1255 protection_mode=PAGE_READONLY;
1257 if ((file == -1) && (flags & MAP_ANONYMOUS))
1258 file_handle=INVALID_HANDLE_VALUE;
1260 file_handle=(HANDLE) _get_osfhandle(file);
1261 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
1265 map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
1267 CloseHandle(map_handle);
1269 if (map == (void *) NULL)
1270 return((void *) MAP_FAILED);
1271 return((void *) ((char *) map));
1275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1279 % N T O p e n D i r e c t o r y %
1283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1285 % NTOpenDirectory() opens the directory named by filename and associates a
1286 % directory stream with it.
1288 % The format of the NTOpenDirectory method is:
1290 % DIR *NTOpenDirectory(const char *path)
1292 % A description of each parameter follows:
1294 % o entry: Specifies a pointer to a DIR structure.
1297 MagickExport DIR *NTOpenDirectory(const char *path)
1300 file_specification[MaxTextExtent];
1308 assert(path != (const char *) NULL);
1309 length=CopyMagickString(file_specification,path,MaxTextExtent);
1310 if (length >= MaxTextExtent)
1311 return((DIR *) NULL);
1312 length=ConcatenateMagickString(file_specification,DirectorySeparator,
1314 if (length >= MaxTextExtent)
1315 return((DIR *) NULL);
1316 entry=(DIR *) AcquireMagickMemory(sizeof(DIR));
1317 if (entry != (DIR *) NULL)
1319 entry->firsttime=TRUE;
1320 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1322 if (entry->hSearch == INVALID_HANDLE_VALUE)
1324 length=ConcatenateMagickString(file_specification,"\\*.*",MaxTextExtent);
1325 if (length >= MaxTextExtent)
1327 entry=(DIR *) RelinquishMagickMemory(entry);
1328 return((DIR *) NULL);
1330 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1331 if (entry->hSearch == INVALID_HANDLE_VALUE)
1333 entry=(DIR *) RelinquishMagickMemory(entry);
1334 return((DIR *) NULL);
1341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1345 % N T O p e n L i b r a r y %
1349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1351 % NTOpenLibrary() loads a dynamic module into memory and returns a handle that
1352 % can be used to access the various procedures in the module.
1354 % The format of the NTOpenLibrary method is:
1356 % void *NTOpenLibrary(const char *filename)
1358 % A description of each parameter follows:
1360 % o path: Specifies a pointer to string representing dynamic module that
1365 static const char *GetSearchPath( void )
1367 #if defined(MAGICKCORE_LTDL_DELEGATE)
1368 return(lt_dlgetsearchpath());
1370 return(lt_slsearchpath);
1374 MagickExport void *NTOpenLibrary(const char *filename)
1376 #define MaxPathElements 31
1379 buffer[MaxTextExtent];
1397 mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
1398 handle=(void *) LoadLibraryEx(filename,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1399 if ((handle != (void *) NULL) || (GetSearchPath() == (char *) NULL))
1404 p=(char *) GetSearchPath();
1406 while (index < MaxPathElements)
1408 q=strchr(p,DirectoryListSeparator);
1409 if (q == (char *) NULL)
1411 (void) CopyMagickString(buffer,p,MaxTextExtent);
1412 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
1413 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
1414 handle=(void *) LoadLibraryEx(buffer,NULL,
1415 LOAD_WITH_ALTERED_SEARCH_PATH);
1419 (void) CopyMagickString(buffer,p,i+1);
1420 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
1421 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
1422 handle=(void *) LoadLibraryEx(buffer,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1423 if (handle != (void *) NULL)
1432 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1436 % N T R e a d D i r e c t o r y %
1440 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1442 % NTReadDirectory() returns a pointer to a structure representing the
1443 % directory entry at the current position in the directory stream to which
1446 % The format of the NTReadDirectory
1448 % NTReadDirectory(entry)
1450 % A description of each parameter follows:
1452 % o entry: Specifies a pointer to a DIR structure.
1455 MagickExport struct dirent *NTReadDirectory(DIR *entry)
1463 if (entry == (DIR *) NULL)
1464 return((struct dirent *) NULL);
1465 if (!entry->firsttime)
1467 status=FindNextFile(entry->hSearch,&entry->Win32FindData);
1469 return((struct dirent *) NULL);
1471 length=CopyMagickString(entry->file_info.d_name,
1472 entry->Win32FindData.cFileName,sizeof(entry->file_info.d_name));
1473 if (length >= sizeof(entry->file_info.d_name))
1474 return((struct dirent *) NULL);
1475 entry->firsttime=FALSE;
1476 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
1477 return(&entry->file_info);
1481 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1485 % N T R e g i s t r y K e y L o o k u p %
1489 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1491 % NTRegistryKeyLookup() returns ImageMagick installation path settings
1492 % stored in the Windows Registry. Path settings are specific to the
1493 % installed ImageMagick version so that multiple Image Magick installations
1496 % Values are stored in the registry under a base path path similar to
1497 % "HKEY_LOCAL_MACHINE/SOFTWARE\ImageMagick\5.5.7\Q:16". The provided subkey
1498 % is appended to this base path to form the full key.
1500 % The format of the NTRegistryKeyLookup method is:
1502 % unsigned char *NTRegistryKeyLookup(const char *subkey)
1504 % A description of each parameter follows:
1506 % o subkey: Specifies a string that identifies the registry object.
1507 % Currently supported sub-keys include: "BinPath", "ConfigurePath",
1508 % "LibPath", "CoderModulesPath", "FilterModulesPath", "SharePath".
1511 MagickExport unsigned char *NTRegistryKeyLookup(const char *subkey)
1514 package_key[MaxTextExtent];
1532 (void) FormatMagickString(package_key,MaxTextExtent,"SOFTWARE\\%s\\%s\\Q:%d",
1533 MagickPackageName,MagickLibVersionText,MAGICKCORE_QUANTUM_DEPTH);
1534 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",package_key);
1535 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1536 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,package_key,0,KEY_READ,®istry_key);
1537 if (status != ERROR_SUCCESS)
1539 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1540 return((unsigned char *) NULL);
1546 value=(unsigned char *) AcquireQuantumMemory(size,sizeof(*value));
1547 if (value == (unsigned char *) NULL)
1549 RegCloseKey(registry_key);
1550 return((unsigned char *) NULL);
1552 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",subkey);
1553 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1554 if ((status == ERROR_MORE_DATA) && (type == REG_SZ))
1556 value=(unsigned char *) ResizeQuantumMemory(value,size,sizeof(*value));
1557 if (value == (BYTE *) NULL)
1559 RegCloseKey(registry_key);
1560 return((unsigned char *) NULL);
1562 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1564 RegCloseKey(registry_key);
1565 if ((type != REG_SZ) || (status != ERROR_SUCCESS))
1566 value=(unsigned char *) RelinquishMagickMemory(value);
1567 return((unsigned char *) value);
1571 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1575 % N T R e p o r t E v e n t %
1579 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1581 % NTReportEvent() reports an event.
1583 % The format of the NTReportEvent method is:
1585 % MagickBooleanType NTReportEvent(const char *event,
1586 % const MagickBooleanType error)
1588 % A description of each parameter follows:
1590 % o event: the event.
1592 % o error: MagickTrue the event is an error.
1595 MagickExport MagickBooleanType NTReportEvent(const char *event,
1596 const MagickBooleanType error)
1607 handle=RegisterEventSource(NULL,MAGICKCORE_PACKAGE_NAME);
1609 return(MagickFalse);
1611 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
1612 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
1613 DeregisterEventSource(handle);
1618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1622 % N T R e s o u r c e T o B l o b %
1626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1628 % NTResourceToBlob() returns a blob containing the contents of the resource
1629 % in the current executable specified by the id parameter. This currently
1630 % used to retrieve MGK files tha have been embedded into the various command
1633 % The format of the NTResourceToBlob method is:
1635 % unsigned char *NTResourceToBlob(const char *id)
1637 % A description of each parameter follows:
1639 % o id: Specifies a string that identifies the resource.
1642 MagickExport unsigned char *NTResourceToBlob(const char *id)
1645 path[MaxTextExtent];
1663 assert(id != (const char *) NULL);
1664 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
1665 (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",GetClientPath(),
1666 DirectorySeparator,GetClientName());
1667 if (IsPathAccessible(path) != MagickFalse)
1668 handle=GetModuleHandle(path);
1670 handle=GetModuleHandle(0);
1672 return((unsigned char *) NULL);
1673 resource=FindResource(handle,id,"IMAGEMAGICK");
1675 return((unsigned char *) NULL);
1676 global=LoadResource(handle,resource);
1678 return((unsigned char *) NULL);
1679 length=SizeofResource(handle,resource);
1680 value=(unsigned char *) LockResource(global);
1683 FreeResource(global);
1684 return((unsigned char *) NULL);
1686 blob=(unsigned char *) AcquireQuantumMemory(length+MaxTextExtent,
1688 if (blob != (unsigned char *) NULL)
1690 (void) CopyMagickMemory(blob,value,length);
1693 UnlockResource(global);
1694 FreeResource(global);
1699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1703 % N T S e e k D i r e c t o r y %
1707 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1709 % NTSeekDirectory() sets the position of the next NTReadDirectory() operation
1710 % on the directory stream.
1712 % The format of the NTSeekDirectory method is:
1714 % void NTSeekDirectory(DIR *entry,long position)
1716 % A description of each parameter follows:
1718 % o entry: Specifies a pointer to a DIR structure.
1720 % o position: specifies the position associated with the directory
1724 MagickExport void NTSeekDirectory(DIR *entry,long position)
1727 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1728 assert(entry != (DIR *) NULL);
1732 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1736 % N T S e t S e a r c h P a t h %
1740 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1742 % NTSetSearchPath() sets the current locations that the subsystem should
1743 % look at to find dynamically loadable modules.
1745 % The format of the NTSetSearchPath method is:
1747 % int NTSetSearchPath(const char *path)
1749 % A description of each parameter follows:
1751 % o path: Specifies a pointer to string representing the search path
1752 % for DLL's that can be dynamically loaded.
1755 MagickExport int NTSetSearchPath(const char *path)
1757 #if defined(MAGICKCORE_LTDL_DELEGATE)
1758 lt_dlsetsearchpath(path);
1760 if (lt_slsearchpath != (char *) NULL)
1761 lt_slsearchpath=DestroyString(lt_slsearchpath);
1762 if (path != (char *) NULL)
1763 lt_slsearchpath=AcquireString(path);
1769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1773 + N T S y n c M e m o r y %
1777 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1779 % NTSyncMemory() emulates the Unix method of the same name.
1781 % The format of the NTSyncMemory method is:
1783 % int NTSyncMemory(void *address,size_t length,int flags)
1785 % A description of each parameter follows:
1787 % o address: the address of the binary large object.
1789 % o length: the length of the binary large object.
1791 % o flags: Option flags (ignored for Windows).
1794 MagickExport int NTSyncMemory(void *address,size_t length,int flags)
1797 if (FlushViewOfFile(address,length) == MagickFalse)
1803 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1807 % N T S y s t e m C o m m a n d %
1811 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1813 % NTSystemCommand() executes the specified command and waits until it
1814 % terminates. The returned value is the exit status of the command.
1816 % The format of the NTSystemCommand method is:
1818 % int NTSystemCommand(const char *command)
1820 % A description of each parameter follows:
1822 % o command: This string is the command to execute.
1825 MagickExport int NTSystemCommand(const char *command)
1828 local_command[MaxTextExtent];
1845 if (command == (char *) NULL)
1847 GetStartupInfo(&startup_info);
1848 startup_info.dwFlags=STARTF_USESHOWWINDOW;
1849 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
1850 (void) CopyMagickString(local_command,command,MaxTextExtent);
1851 background_process=command[strlen(command)-1] == '&' ? MagickTrue :
1853 if (background_process)
1854 local_command[strlen(command)-1]='\0';
1855 if (command[strlen(command)-1] == '|')
1856 local_command[strlen(command)-1]='\0';
1858 startup_info.wShowWindow=SW_SHOWDEFAULT;
1859 status=CreateProcess((LPCTSTR) NULL,local_command,
1860 (LPSECURITY_ATTRIBUTES) NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) FALSE,
1861 (DWORD) NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
1865 if (background_process)
1866 return(status == 0);
1867 status=WaitForSingleObject(process_info.hProcess,INFINITE);
1868 if (status != WAIT_OBJECT_0)
1870 status=GetExitCodeProcess(process_info.hProcess,&child_status);
1873 CloseHandle(process_info.hProcess);
1874 CloseHandle(process_info.hThread);
1875 return((int) child_status);
1879 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1883 % N T S y s t e m C o n i f i g u r a t i o n %
1887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1889 % NTSystemConfiguration() provides a way for the application to determine
1890 % values for system limits or options at runtime.
1892 % The format of the exit method is:
1894 % long NTSystemConfiguration(int name)
1896 % A description of each parameter follows:
1898 % o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
1901 MagickExport long NTSystemConfiguration(int name)
1910 GetSystemInfo(&system_info);
1911 return(system_info.dwPageSize);
1913 case _SC_PHYS_PAGES:
1927 handle=GetModuleHandle("kernel32.dll");
1928 if (handle == (HMODULE) NULL)
1930 GetSystemInfo(&system_info);
1931 module=(LPFNDLLFUNC2) NTGetLibrarySymbol(handle,"GlobalMemoryStatusEx");
1932 if (module == (LPFNDLLFUNC2) NULL)
1937 GlobalMemoryStatus(&status);
1938 return((long) status.dwTotalPhys/system_info.dwPageSize);
1940 status.dwLength=sizeof(status);
1941 if (module(&status) == 0)
1943 return((long) status.ullTotalPhys/system_info.dwPageSize);
1954 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1958 % N T T e l l D i r e c t o r y %
1962 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1964 % NTTellDirectory() returns the current location associated with the named
1967 % The format of the NTTellDirectory method is:
1969 % long NTTellDirectory(DIR *entry)
1971 % A description of each parameter follows:
1973 % o entry: Specifies a pointer to a DIR structure.
1976 MagickExport long NTTellDirectory(DIR *entry)
1978 assert(entry != (DIR *) NULL);
1983 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1987 % N T T r u n c a t e F i l e %
1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1993 % NTTruncateFile() truncates a file to a specified length.
1995 % The format of the NTTruncateFile method is:
1997 % int NTTruncateFile(int file,off_t length)
1999 % A description of each parameter follows:
2003 % o length: the file length.
2006 MagickExport int NTTruncateFile(int file,off_t length)
2016 file_handle=_get_osfhandle(file);
2017 if (file_handle == -1L)
2019 low=(long) (length & 0xffffffffUL);
2020 high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
2021 file_pointer=SetFilePointer((HANDLE) file_handle,low,&high,FILE_BEGIN);
2022 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
2024 if (SetEndOfFile((HANDLE) file_handle) == 0)
2030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2034 + N T U n m a p M e m o r y %
2038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2040 % NTUnmapMemory() emulates the Unix munmap method.
2042 % The format of the NTUnmapMemory method is:
2044 % int NTUnmapMemory(void *map,size_t length)
2046 % A description of each parameter follows:
2048 % o map: the address of the binary large object.
2050 % o length: the length of the binary large object.
2053 MagickExport int NTUnmapMemory(void *map,size_t length)
2056 if (UnmapViewOfFile(map) == 0)
2062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2066 % N T U s e r T i m e %
2070 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2072 % NTUserTime() returns the total time the process has been scheduled (e.g.
2073 % seconds) since the last call to StartTimer().
2075 % The format of the UserTime method is:
2077 % double NTUserTime(void)
2080 MagickExport double NTUserTime(void)
2110 OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
2111 GetVersionEx(&OsVersionInfo);
2112 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
2113 return(NTElapsedTime());
2114 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
2115 &kernel_time.filetime,&user_time.filetime);
2118 return((double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
2122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2126 % N T W a r n i n g H a n d l e r %
2130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2132 % NTWarningHandler() displays a warning reason.
2134 % The format of the NTWarningHandler method is:
2136 % void NTWarningHandler(const ExceptionType severity,const char *reason,
2137 % const char *description)
2139 % A description of each parameter follows:
2141 % o severity: Specifies the numeric warning category.
2143 % o reason: Specifies the reason to display before terminating the
2146 % o description: Specifies any description to the reason.
2149 MagickExport void NTWarningHandler(const ExceptionType severity,
2150 const char *reason,const char *description)
2153 buffer[2*MaxTextExtent];
2156 if (reason == (char *) NULL)
2158 if (description == (char *) NULL)
2159 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s.\n",GetClientName(),
2162 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s (%s).\n",
2163 GetClientName(),reason,description);
2164 (void) MessageBox(NULL,buffer,"ImageMagick Warning",MB_OK | MB_TASKMODAL |
2165 MB_SETFOREGROUND | MB_ICONINFORMATION);