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 AsynchronousDestroyResourceComponent();
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);
880 if (status == MagickFalse)
885 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"Ghostscript (%s) "
886 "version %d.%02d",*product_family,*major_version,*minor_version);
890 static int NTGhostscriptGetString(const char *name,char *value,
901 *product_family = (const char *) NULL;
917 { HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
918 { HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" }
922 Get a string from the installed Ghostscript.
925 if (product_family == NULL)
926 (void) NTLocateGhostscript(&product_family,&major_version,&minor_version);
927 if (product_family == NULL)
929 (void) FormatMagickString(key,MaxTextExtent,"SOFTWARE\\%s\\%d.%02d",
930 product_family,major_version,minor_version);
931 for (i=0; i < (long) (sizeof(hkeys)/sizeof(hkeys[0])); i++)
934 if (NTGetRegistryValue(hkeys[i].hkey,key,name,value,&extent) == 0)
936 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
937 "registry: \"%s\\%s\\%s\"=\"%s\"",hkeys[i].name,key,name,value);
940 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
941 "registry: \"%s\\%s\\%s\" (failed)",hkeys[i].name,key,name);
946 MagickExport int NTGhostscriptDLL(char *path,int length)
949 dll[MaxTextExtent] = { "" };
952 if ((*dll == '\0') &&
953 (NTGhostscriptGetString("GS_DLL",dll,sizeof(dll)) == FALSE))
955 (void) CopyMagickString(path,dll,length);
960 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
964 % N T G h o s t s c r i p t D L L V e c t o r s %
968 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
970 % NTGhostscriptDLLVectors() returns a GhostInfo structure that includes
971 % function vectors to invoke Ghostscript DLL functions. A null pointer is
972 % returned if there is an error when loading the DLL or retrieving the
975 % The format of the NTGhostscriptDLLVectors method is:
977 % const GhostInfo *NTGhostscriptDLLVectors(void)
980 MagickExport const GhostInfo *NTGhostscriptDLLVectors(void)
982 if (NTGhostscriptLoadDLL() == FALSE)
983 return((GhostInfo *) NULL);
988 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
992 % N T G h o s t s c r i p t E X E %
996 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
998 % NTGhostscriptEXE() obtains the path to the latest Ghostscript executable.
999 % The method returns FALSE if a full path value is not obtained and returns
1000 % a default path of gswin32c.exe.
1002 % The format of the NTGhostscriptEXE method is:
1004 % int NTGhostscriptEXE(char *path,int length)
1006 % A description of each parameter follows:
1008 % o path: return the Ghostscript executable path here.
1010 % o length: length of buffer.
1013 MagickExport int NTGhostscriptEXE(char *path,int length)
1019 program[MaxTextExtent] = { "" };
1021 (void) CopyMagickString(path,"gswin32c.exe",length);
1022 if ((*program == '\0') &&
1023 (NTGhostscriptGetString("GS_DLL",program,sizeof(program)) == FALSE))
1025 p=strrchr(program,'\\');
1026 if (p != (char *) NULL)
1030 (void) ConcatenateMagickString(program,"gswin32c.exe",sizeof(program));
1032 (void) CopyMagickString(path,program,length);
1037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1041 % N T G h o s t s c r i p t F o n t s %
1045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1047 % NTGhostscriptFonts() obtains the path to the Ghostscript fonts. The method
1048 % returns FALSE if it cannot determine the font path.
1050 % The format of the NTGhostscriptFonts method is:
1052 % int NTGhostscriptFonts(char *path, int length)
1054 % A description of each parameter follows:
1056 % o path: return the font path here.
1058 % o length: length of the path buffer.
1061 MagickExport int NTGhostscriptFonts(char *path,int length)
1064 buffer[MaxTextExtent],
1065 filename[MaxTextExtent];
1072 if (NTGhostscriptGetString("GS_LIB",buffer,MaxTextExtent) == FALSE)
1074 for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
1076 (void) CopyMagickString(path,p+1,length+1);
1077 q=strchr(path,DirectoryListSeparator);
1078 if (q != (char *) NULL)
1080 (void) FormatMagickString(filename,MaxTextExtent,"%s%sfonts.dir",path,
1081 DirectorySeparator);
1082 if (IsPathAccessible(filename) != MagickFalse)
1089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1093 % N T G h o s t s c r i p t L o a d D L L %
1097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1099 % NTGhostscriptLoadDLL() attempts to load the Ghostscript DLL and returns
1100 % TRUE if it succeeds.
1102 % The format of the NTGhostscriptLoadDLL method is:
1104 % int NTGhostscriptLoadDLL(void)
1107 MagickExport int NTGhostscriptLoadDLL(void)
1110 path[MaxTextExtent];
1112 if (ghost_handle != (void *) NULL)
1114 if (NTGhostscriptDLL(path,sizeof(path)) == FALSE)
1116 ghost_handle=lt_dlopen(path);
1117 if (ghost_handle == (void *) NULL)
1119 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1120 ghost_info.exit=(int (MagickDLLCall *)(gs_main_instance*))
1121 lt_dlsym(ghost_handle,"gsapi_exit");
1122 ghost_info.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,int,
1123 char **)) (lt_dlsym(ghost_handle,"gsapi_init_with_args"));
1124 ghost_info.new_instance=(int (MagickDLLCall *)(gs_main_instance **,void *)) (
1125 lt_dlsym(ghost_handle,"gsapi_new_instance"));
1126 ghost_info.run_string=(int (MagickDLLCall *)(gs_main_instance *,const char *,
1127 int,int *)) (lt_dlsym(ghost_handle,"gsapi_run_string"));
1128 ghost_info.delete_instance=(void (MagickDLLCall *) (gs_main_instance *)) (
1129 lt_dlsym(ghost_handle,"gsapi_delete_instance"));
1130 if ((ghost_info.exit == NULL) || (ghost_info.init_with_args == NULL) ||
1131 (ghost_info.new_instance == NULL) || (ghost_info.run_string == NULL) ||
1132 (ghost_info.delete_instance == NULL))
1138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1142 % N T G h o s t s c r i p t U n L o a d D L L %
1146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1148 % NTGhostscriptUnLoadDLL() unloads the Ghostscript DLL and returns TRUE if
1151 % The format of the NTGhostscriptUnLoadDLL method is:
1153 % int NTGhostscriptUnLoadDLL(void)
1156 MagickExport int NTGhostscriptUnLoadDLL(void)
1161 if (ghost_handle == (void *) NULL)
1163 status=lt_dlclose(ghost_handle);
1164 ghost_handle=(void *) NULL;
1165 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1174 % N T I n i t i a l i z e L i b r a r y %
1178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1180 % NTInitializeLibrary() initializes the dynamic module loading subsystem.
1182 % The format of the NTInitializeLibrary method is:
1184 % int NTInitializeLibrary(void)
1187 MagickExport int NTInitializeLibrary(void)
1193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1197 + N T M a p M e m o r y %
1201 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1203 % Mmap() emulates the Unix method of the same name.
1205 % The format of the NTMapMemory method is:
1207 % MagickExport void *NTMapMemory(char *address,size_t length,int protection,
1208 % int access,int file,MagickOffsetType offset)
1211 MagickExport void *NTMapMemory(char *address,size_t length,int protection,
1212 int flags,int file,MagickOffsetType offset)
1231 file_handle=INVALID_HANDLE_VALUE;
1232 low_length=(DWORD) (length & 0xFFFFFFFFUL);
1233 high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
1234 map_handle=INVALID_HANDLE_VALUE;
1236 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
1237 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
1239 if (protection & PROT_WRITE)
1241 access_mode=FILE_MAP_WRITE;
1242 if (!(flags & MAP_PRIVATE))
1243 protection_mode=PAGE_READWRITE;
1246 access_mode=FILE_MAP_COPY;
1247 protection_mode=PAGE_WRITECOPY;
1251 if (protection & PROT_READ)
1253 access_mode=FILE_MAP_READ;
1254 protection_mode=PAGE_READONLY;
1256 if ((file == -1) && (flags & MAP_ANONYMOUS))
1257 file_handle=INVALID_HANDLE_VALUE;
1259 file_handle=(HANDLE) _get_osfhandle(file);
1260 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
1264 map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
1266 CloseHandle(map_handle);
1268 if (map == (void *) NULL)
1269 return((void *) MAP_FAILED);
1270 return((void *) ((char *) map));
1274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1278 % N T O p e n D i r e c t o r y %
1282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1284 % NTOpenDirectory() opens the directory named by filename and associates a
1285 % directory stream with it.
1287 % The format of the NTOpenDirectory method is:
1289 % DIR *NTOpenDirectory(const char *path)
1291 % A description of each parameter follows:
1293 % o entry: Specifies a pointer to a DIR structure.
1296 MagickExport DIR *NTOpenDirectory(const char *path)
1299 file_specification[MaxTextExtent];
1307 assert(path != (const char *) NULL);
1308 length=CopyMagickString(file_specification,path,MaxTextExtent);
1309 if (length >= MaxTextExtent)
1310 return((DIR *) NULL);
1311 length=ConcatenateMagickString(file_specification,DirectorySeparator,
1313 if (length >= MaxTextExtent)
1314 return((DIR *) NULL);
1315 entry=(DIR *) AcquireMagickMemory(sizeof(DIR));
1316 if (entry != (DIR *) NULL)
1318 entry->firsttime=TRUE;
1319 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1321 if (entry->hSearch == INVALID_HANDLE_VALUE)
1323 length=ConcatenateMagickString(file_specification,"\\*.*",MaxTextExtent);
1324 if (length >= MaxTextExtent)
1326 entry=(DIR *) RelinquishMagickMemory(entry);
1327 return((DIR *) NULL);
1329 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1330 if (entry->hSearch == INVALID_HANDLE_VALUE)
1332 entry=(DIR *) RelinquishMagickMemory(entry);
1333 return((DIR *) NULL);
1340 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1344 % N T O p e n L i b r a r y %
1348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1350 % NTOpenLibrary() loads a dynamic module into memory and returns a handle that
1351 % can be used to access the various procedures in the module.
1353 % The format of the NTOpenLibrary method is:
1355 % void *NTOpenLibrary(const char *filename)
1357 % A description of each parameter follows:
1359 % o path: Specifies a pointer to string representing dynamic module that
1364 static const char *GetSearchPath( void )
1366 #if defined(MAGICKCORE_LTDL_DELEGATE)
1367 return(lt_dlgetsearchpath());
1369 return(lt_slsearchpath);
1373 MagickExport void *NTOpenLibrary(const char *filename)
1375 #define MaxPathElements 31
1378 buffer[MaxTextExtent];
1396 mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
1397 handle=(void *) LoadLibraryEx(filename,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1398 if ((handle != (void *) NULL) || (GetSearchPath() == (char *) NULL))
1403 p=(char *) GetSearchPath();
1405 while (index < MaxPathElements)
1407 q=strchr(p,DirectoryListSeparator);
1408 if (q == (char *) NULL)
1410 (void) CopyMagickString(buffer,p,MaxTextExtent);
1411 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
1412 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
1413 handle=(void *) LoadLibraryEx(buffer,NULL,
1414 LOAD_WITH_ALTERED_SEARCH_PATH);
1418 (void) CopyMagickString(buffer,p,i+1);
1419 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
1420 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
1421 handle=(void *) LoadLibraryEx(buffer,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1422 if (handle != (void *) NULL)
1431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1435 % N T R e a d D i r e c t o r y %
1439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1441 % NTReadDirectory() returns a pointer to a structure representing the
1442 % directory entry at the current position in the directory stream to which
1445 % The format of the NTReadDirectory
1447 % NTReadDirectory(entry)
1449 % A description of each parameter follows:
1451 % o entry: Specifies a pointer to a DIR structure.
1454 MagickExport struct dirent *NTReadDirectory(DIR *entry)
1462 if (entry == (DIR *) NULL)
1463 return((struct dirent *) NULL);
1464 if (!entry->firsttime)
1466 status=FindNextFile(entry->hSearch,&entry->Win32FindData);
1468 return((struct dirent *) NULL);
1470 length=CopyMagickString(entry->file_info.d_name,
1471 entry->Win32FindData.cFileName,sizeof(entry->file_info.d_name));
1472 if (length >= sizeof(entry->file_info.d_name))
1473 return((struct dirent *) NULL);
1474 entry->firsttime=FALSE;
1475 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
1476 return(&entry->file_info);
1480 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1484 % N T R e g i s t r y K e y L o o k u p %
1488 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1490 % NTRegistryKeyLookup() returns ImageMagick installation path settings
1491 % stored in the Windows Registry. Path settings are specific to the
1492 % installed ImageMagick version so that multiple Image Magick installations
1495 % Values are stored in the registry under a base path path similar to
1496 % "HKEY_LOCAL_MACHINE/SOFTWARE\ImageMagick\5.5.7\Q:16". The provided subkey
1497 % is appended to this base path to form the full key.
1499 % The format of the NTRegistryKeyLookup method is:
1501 % unsigned char *NTRegistryKeyLookup(const char *subkey)
1503 % A description of each parameter follows:
1505 % o subkey: Specifies a string that identifies the registry object.
1506 % Currently supported sub-keys include: "BinPath", "ConfigurePath",
1507 % "LibPath", "CoderModulesPath", "FilterModulesPath", "SharePath".
1510 MagickExport unsigned char *NTRegistryKeyLookup(const char *subkey)
1513 package_key[MaxTextExtent];
1531 (void) FormatMagickString(package_key,MaxTextExtent,"SOFTWARE\\%s\\%s\\Q:%d",
1532 MagickPackageName,MagickLibVersionText,MAGICKCORE_QUANTUM_DEPTH);
1533 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",package_key);
1534 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1535 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,package_key,0,KEY_READ,®istry_key);
1536 if (status != ERROR_SUCCESS)
1538 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1539 return((unsigned char *) NULL);
1545 value=(unsigned char *) AcquireQuantumMemory(size,sizeof(*value));
1546 if (value == (unsigned char *) NULL)
1548 RegCloseKey(registry_key);
1549 return((unsigned char *) NULL);
1551 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",subkey);
1552 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1553 if ((status == ERROR_MORE_DATA) && (type == REG_SZ))
1555 value=(unsigned char *) ResizeQuantumMemory(value,size,sizeof(*value));
1556 if (value == (BYTE *) NULL)
1558 RegCloseKey(registry_key);
1559 return((unsigned char *) NULL);
1561 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1563 RegCloseKey(registry_key);
1564 if ((type != REG_SZ) || (status != ERROR_SUCCESS))
1565 value=(unsigned char *) RelinquishMagickMemory(value);
1566 return((unsigned char *) value);
1570 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1574 % N T R e p o r t E v e n t %
1578 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1580 % NTReportEvent() reports an event.
1582 % The format of the NTReportEvent method is:
1584 % MagickBooleanType NTReportEvent(const char *event,
1585 % const MagickBooleanType error)
1587 % A description of each parameter follows:
1589 % o event: the event.
1591 % o error: MagickTrue the event is an error.
1594 MagickExport MagickBooleanType NTReportEvent(const char *event,
1595 const MagickBooleanType error)
1606 handle=RegisterEventSource(NULL,MAGICKCORE_PACKAGE_NAME);
1608 return(MagickFalse);
1610 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
1611 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
1612 DeregisterEventSource(handle);
1617 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1621 % N T R e s o u r c e T o B l o b %
1625 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1627 % NTResourceToBlob() returns a blob containing the contents of the resource
1628 % in the current executable specified by the id parameter. This currently
1629 % used to retrieve MGK files tha have been embedded into the various command
1632 % The format of the NTResourceToBlob method is:
1634 % unsigned char *NTResourceToBlob(const char *id)
1636 % A description of each parameter follows:
1638 % o id: Specifies a string that identifies the resource.
1641 MagickExport unsigned char *NTResourceToBlob(const char *id)
1644 path[MaxTextExtent];
1662 assert(id != (const char *) NULL);
1663 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
1664 (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",GetClientPath(),
1665 DirectorySeparator,GetClientName());
1666 if (IsPathAccessible(path) != MagickFalse)
1667 handle=GetModuleHandle(path);
1669 handle=GetModuleHandle(0);
1671 return((unsigned char *) NULL);
1672 resource=FindResource(handle,id,"IMAGEMAGICK");
1674 return((unsigned char *) NULL);
1675 global=LoadResource(handle,resource);
1677 return((unsigned char *) NULL);
1678 length=SizeofResource(handle,resource);
1679 value=(unsigned char *) LockResource(global);
1682 FreeResource(global);
1683 return((unsigned char *) NULL);
1685 blob=(unsigned char *) AcquireQuantumMemory(length+MaxTextExtent,
1687 if (blob != (unsigned char *) NULL)
1689 (void) CopyMagickMemory(blob,value,length);
1692 UnlockResource(global);
1693 FreeResource(global);
1698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1702 % N T S e e k D i r e c t o r y %
1706 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1708 % NTSeekDirectory() sets the position of the next NTReadDirectory() operation
1709 % on the directory stream.
1711 % The format of the NTSeekDirectory method is:
1713 % void NTSeekDirectory(DIR *entry,long position)
1715 % A description of each parameter follows:
1717 % o entry: Specifies a pointer to a DIR structure.
1719 % o position: specifies the position associated with the directory
1723 MagickExport void NTSeekDirectory(DIR *entry,long position)
1726 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1727 assert(entry != (DIR *) NULL);
1731 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1735 % N T S e t S e a r c h P a t h %
1739 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1741 % NTSetSearchPath() sets the current locations that the subsystem should
1742 % look at to find dynamically loadable modules.
1744 % The format of the NTSetSearchPath method is:
1746 % int NTSetSearchPath(const char *path)
1748 % A description of each parameter follows:
1750 % o path: Specifies a pointer to string representing the search path
1751 % for DLL's that can be dynamically loaded.
1754 MagickExport int NTSetSearchPath(const char *path)
1756 #if defined(MAGICKCORE_LTDL_DELEGATE)
1757 lt_dlsetsearchpath(path);
1759 if (lt_slsearchpath != (char *) NULL)
1760 lt_slsearchpath=DestroyString(lt_slsearchpath);
1761 if (path != (char *) NULL)
1762 lt_slsearchpath=AcquireString(path);
1768 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1772 + N T S y n c M e m o r y %
1776 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1778 % NTSyncMemory() emulates the Unix method of the same name.
1780 % The format of the NTSyncMemory method is:
1782 % int NTSyncMemory(void *address,size_t length,int flags)
1784 % A description of each parameter follows:
1786 % o address: the address of the binary large object.
1788 % o length: the length of the binary large object.
1790 % o flags: Option flags (ignored for Windows).
1793 MagickExport int NTSyncMemory(void *address,size_t length,int flags)
1796 if (FlushViewOfFile(address,length) == MagickFalse)
1802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1806 % N T S y s t e m C o m m a n d %
1810 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1812 % NTSystemCommand() executes the specified command and waits until it
1813 % terminates. The returned value is the exit status of the command.
1815 % The format of the NTSystemCommand method is:
1817 % int NTSystemCommand(const char *command)
1819 % A description of each parameter follows:
1821 % o command: This string is the command to execute.
1824 MagickExport int NTSystemCommand(const char *command)
1827 local_command[MaxTextExtent];
1844 if (command == (char *) NULL)
1846 GetStartupInfo(&startup_info);
1847 startup_info.dwFlags=STARTF_USESHOWWINDOW;
1848 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
1849 (void) CopyMagickString(local_command,command,MaxTextExtent);
1850 background_process=command[strlen(command)-1] == '&' ? MagickTrue :
1852 if (background_process)
1853 local_command[strlen(command)-1]='\0';
1854 if (command[strlen(command)-1] == '|')
1855 local_command[strlen(command)-1]='\0';
1857 startup_info.wShowWindow=SW_SHOWDEFAULT;
1858 status=CreateProcess((LPCTSTR) NULL,local_command,
1859 (LPSECURITY_ATTRIBUTES) NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) FALSE,
1860 (DWORD) NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
1864 if (background_process)
1865 return(status == 0);
1866 status=WaitForSingleObject(process_info.hProcess,INFINITE);
1867 if (status != WAIT_OBJECT_0)
1869 status=GetExitCodeProcess(process_info.hProcess,&child_status);
1872 CloseHandle(process_info.hProcess);
1873 CloseHandle(process_info.hThread);
1874 return((int) child_status);
1878 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1882 % N T S y s t e m C o n i f i g u r a t i o n %
1886 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1888 % NTSystemConfiguration() provides a way for the application to determine
1889 % values for system limits or options at runtime.
1891 % The format of the exit method is:
1893 % long NTSystemConfiguration(int name)
1895 % A description of each parameter follows:
1897 % o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
1900 MagickExport long NTSystemConfiguration(int name)
1909 GetSystemInfo(&system_info);
1910 return(system_info.dwPageSize);
1912 case _SC_PHYS_PAGES:
1926 handle=GetModuleHandle("kernel32.dll");
1927 if (handle == (HMODULE) NULL)
1929 GetSystemInfo(&system_info);
1930 module=(LPFNDLLFUNC2) NTGetLibrarySymbol(handle,"GlobalMemoryStatusEx");
1931 if (module == (LPFNDLLFUNC2) NULL)
1936 GlobalMemoryStatus(&status);
1937 return((long) status.dwTotalPhys/system_info.dwPageSize);
1939 status.dwLength=sizeof(status);
1940 if (module(&status) == 0)
1942 return((long) status.ullTotalPhys/system_info.dwPageSize);
1953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1957 % N T T e l l D i r e c t o r y %
1961 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1963 % NTTellDirectory() returns the current location associated with the named
1966 % The format of the NTTellDirectory method is:
1968 % long NTTellDirectory(DIR *entry)
1970 % A description of each parameter follows:
1972 % o entry: Specifies a pointer to a DIR structure.
1975 MagickExport long NTTellDirectory(DIR *entry)
1977 assert(entry != (DIR *) NULL);
1982 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1986 % N T T r u n c a t e F i l e %
1990 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1992 % NTTruncateFile() truncates a file to a specified length.
1994 % The format of the NTTruncateFile method is:
1996 % int NTTruncateFile(int file,off_t length)
1998 % A description of each parameter follows:
2002 % o length: the file length.
2005 MagickExport int NTTruncateFile(int file,off_t length)
2015 file_handle=_get_osfhandle(file);
2016 if (file_handle == -1L)
2018 low=(long) (length & 0xffffffffUL);
2019 high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
2020 file_pointer=SetFilePointer((HANDLE) file_handle,low,&high,FILE_BEGIN);
2021 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
2023 if (SetEndOfFile((HANDLE) file_handle) == 0)
2029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2033 + N T U n m a p M e m o r y %
2037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2039 % NTUnmapMemory() emulates the Unix munmap method.
2041 % The format of the NTUnmapMemory method is:
2043 % int NTUnmapMemory(void *map,size_t length)
2045 % A description of each parameter follows:
2047 % o map: the address of the binary large object.
2049 % o length: the length of the binary large object.
2052 MagickExport int NTUnmapMemory(void *map,size_t length)
2055 if (UnmapViewOfFile(map) == 0)
2061 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2065 % N T U s e r T i m e %
2069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2071 % NTUserTime() returns the total time the process has been scheduled (e.g.
2072 % seconds) since the last call to StartTimer().
2074 % The format of the UserTime method is:
2076 % double NTUserTime(void)
2079 MagickExport double NTUserTime(void)
2109 OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
2110 GetVersionEx(&OsVersionInfo);
2111 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
2112 return(NTElapsedTime());
2113 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
2114 &kernel_time.filetime,&user_time.filetime);
2117 return((double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
2121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2125 % N T W a r n i n g H a n d l e r %
2129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2131 % NTWarningHandler() displays a warning reason.
2133 % The format of the NTWarningHandler method is:
2135 % void NTWarningHandler(const ExceptionType severity,const char *reason,
2136 % const char *description)
2138 % A description of each parameter follows:
2140 % o severity: Specifies the numeric warning category.
2142 % o reason: Specifies the reason to display before terminating the
2145 % o description: Specifies any description to the reason.
2148 MagickExport void NTWarningHandler(const ExceptionType severity,
2149 const char *reason,const char *description)
2152 buffer[2*MaxTextExtent];
2155 if (reason == (char *) NULL)
2157 if (description == (char *) NULL)
2158 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s.\n",GetClientName(),
2161 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s (%s).\n",
2162 GetClientName(),reason,description);
2163 (void) MessageBox(NULL,buffer,"ImageMagick Warning",MB_OK | MB_TASKMODAL |
2164 MB_SETFOREGROUND | MB_ICONINFORMATION);