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 *gs_dll_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() obtains the path to the latest Ghostscript DLL. The
742 % method returns MagickFalse if a value is not obtained.
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: Pointer to buffer in which to return result.
752 % o length: Length of buffer
756 #define GS_PRODUCT_AFPL "AFPL Ghostscript"
757 #define GS_PRODUCT_ALADDIN "Aladdin Ghostscript"
758 #define GS_PRODUCT_GNU "GNU Ghostscript"
759 #define GS_PRODUCT_GPL "GPL Ghostscript"
760 #define GS_MINIMUM_VERSION 550
763 Get Ghostscript versions for given product.
764 Store results starting at pver + 1 + offset.
765 Returns total number of versions in pver.
767 static int NTGhostscriptProductVersions(int *pver,int offset,
768 const char *gs_productfamily)
785 (void) FormatMagickString(key,MaxTextExtent,"Software\\%s",gs_productfamily);
786 hkeyroot = HKEY_LOCAL_MACHINE;
787 if (RegOpenKeyExA(hkeyroot,key,0,KEY_READ,&hkey) == ERROR_SUCCESS)
790 Now enumerate the keys.
792 cbData = sizeof(key) / sizeof(char);
793 while (RegEnumKeyA(hkey,n,key,cbData) == ERROR_SUCCESS)
798 while (*p && (*p!='.')) {
799 ver = (ver * 10) + (*p - '0')*100;
811 if ((n+offset) < pver[0])
819 /* Query registry to find which versions of Ghostscript are installed.
820 * Return version numbers in an integer array.
821 * On entry, the first element in the array must be the array size
823 * If all is well, TRUE is returned.
824 * On exit, the first element is set to the number of Ghostscript
825 * versions installed, and subsequent elements to the version
826 * numbers of Ghostscript.
827 * e.g. on entry {5, 0, 0, 0, 0}, on exit {3, 550, 600, 596, 0}
828 * Returned version numbers may not be sorted.
830 * If Ghostscript is not installed at all, return FALSE
831 * and set pver[0] to 0.
832 * If the array is not large enough, return FALSE
833 * and set pver[0] to the number of Ghostscript versions installed.
836 static int NTGhostscriptEnumerateVersions(int *pver)
841 assert(pver != (int *) NULL);
842 n=NTGhostscriptProductVersions(pver,0,GS_PRODUCT_AFPL);
843 n=NTGhostscriptProductVersions(pver,n,GS_PRODUCT_ALADDIN);
844 n=NTGhostscriptProductVersions(pver,n,GS_PRODUCT_GNU);
845 n=NTGhostscriptProductVersions(pver,n,GS_PRODUCT_GPL);
849 return(FALSE); /* too small */
854 return(FALSE); /* not installed */
861 Get a named registry value.
862 Key = hkeyroot\\key, named value = name.
863 name, ptr, plen and return values are the same as in gp_getenv();
865 static int NTGetRegistryValue(HKEY hkeyroot,const char *key,const char *name,
882 if (RegOpenKeyExA(hkeyroot,key,0,KEY_READ,&hkey) == ERROR_SUCCESS)
886 if (bptr == (BYTE *)NULL)
887 bptr=(&b); /* Registry API won't return ERROR_MORE_DATA */
889 rc=RegQueryValueExA(hkey,(char *) name,0,&keytype,bptr,&cbData);
891 if (rc == ERROR_SUCCESS)
894 return 0; /* found environment variable and copied it */
895 } else if (rc == ERROR_MORE_DATA) {
896 /* buffer wasn't large enough */
901 return(1); /* not found */
904 static int NTGhostscriptGetProductString(int gs_revision,const char *name,
905 char *ptr,int len,const char *gs_productfamily)
907 /* If using Win32, look in the registry for a value with
908 * the given name. The registry value will be under the key
909 * HKEY_CURRENT_USER\Software\AFPL Ghostscript\N.NN
910 * or if that fails under the key
911 * HKEY_LOCAL_MACHINE\Software\AFPL Ghostscript\N.NN
912 * where "AFPL Ghostscript" is actually gs_productfamily
913 * and N.NN is obtained from gs_revision.
917 dotversion[MaxTextExtent],
924 DWORD version = GetVersion();
926 if (((HIWORD(version) & 0x8000) != 0) && ((HIWORD(version) & 0x4000) == 0))
931 (void) FormatMagickString(dotversion,MaxTextExtent,"%d.%02d",(int)
932 (gs_revision/100),(int) (gs_revision % 100));
933 (void) FormatMagickString(key,MaxTextExtent,"Software\\%s\\%s",
934 gs_productfamily,dotversion);
936 code = NTGetRegistryValue(HKEY_CURRENT_USER, key, name, ptr, &length);
938 return TRUE; /* found it */
940 code = NTGetRegistryValue(HKEY_LOCAL_MACHINE, key, name, ptr, &length);
942 return TRUE; /* found it */
946 static int NTGhostscriptGetString(int gs_revision,const char *name,char *ptr,
949 if (NTGhostscriptGetProductString(gs_revision,name,ptr,len,GS_PRODUCT_AFPL))
951 if (NTGhostscriptGetProductString(gs_revision,name,ptr,len,GS_PRODUCT_ALADDIN))
953 if (NTGhostscriptGetProductString(gs_revision,name,ptr,len,GS_PRODUCT_GNU))
955 if (NTGhostscriptGetProductString(gs_revision,name,ptr,len,GS_PRODUCT_GPL))
960 static int NTGetLatestGhostscript( void )
968 DWORD version = GetVersion();
969 if ( ((HIWORD(version) & 0x8000)!=0) && ((HIWORD(version) & 0x4000)==0) )
970 return FALSE; /* win32s */
973 NTGhostscriptEnumerateVersions(&count);
976 ver=(int *) AcquireQuantumMemory(count+1UL,sizeof(*ver));
977 if (ver == (int *)NULL)
980 if (!NTGhostscriptEnumerateVersions(ver))
982 ver=(int *) RelinquishMagickMemory(ver);
986 for (i=1; i<=ver[0]; i++) {
987 if (ver[i] > version)
990 ver=(int *) RelinquishMagickMemory(ver);
996 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1000 % N T G h o s t s c r i p t D L L %
1004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1006 % NTGhostscriptDLL() obtains the path to the latest Ghostscript DLL. The
1007 % method returns MagickFalse if a value is not obtained.
1009 % The format of the NTGhostscriptDLL method is:
1011 % int NTGhostscriptDLL( char *path, int length)
1013 % A description of each parameter follows:
1015 % o path: Pointer to path buffer to update
1017 % o length: Allocation size of path buffer.
1020 MagickExport int NTGhostscriptDLL(char *path, int length)
1029 version = NTGetLatestGhostscript();
1030 if ((version == FALSE) || (version < GS_MINIMUM_VERSION))
1033 if (!NTGhostscriptGetString(version, "GS_DLL", buf, sizeof(buf)))
1036 (void) CopyMagickString(path,buf,length+1);
1041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1045 % N T G h o s t s c r i p t D L L V e c t o r s %
1049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1051 % NTGhostscriptDLLVectors() returns a GhostscriptVectors structure containing
1052 % function vectors to invoke Ghostscript DLL functions. A null pointer is
1053 % returned if there is an error with loading the DLL or retrieving the
1056 % The format of the NTGhostscriptDLLVectors method is:
1058 % const GhostscriptVectors *NTGhostscriptDLLVectors(void)
1061 MagickExport const GhostscriptVectors *NTGhostscriptDLLVectors( void )
1063 if (NTGhostscriptLoadDLL())
1064 return(&gs_vectors);
1065 return((GhostscriptVectors*) NULL);
1069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1073 % N T G h o s t s c r i p t E X E %
1077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1079 % NTGhostscriptEXE() obtains the path to the latest Ghostscript executable.
1080 % The method returns MagickFalse if a value is not obtained.
1082 % The format of the NTGhostscriptEXE method is:
1084 % int NTGhostscriptEXE(char *path, int length)
1086 % A description of each parameter follows:
1088 % o path: pointer to buffer in which to return result.
1090 % o length: length of buffer.
1093 MagickExport int NTGhostscriptEXE(char *path,int length)
1096 buffer[MaxTexytExtent],
1102 (void) CopyMagickString(path,"gswin32c.exe",length);
1103 version=NTGetLatestGhostscript();
1104 if ((version == FALSE) || (version < GS_MINIMUM_VERSION))
1106 if (NTGhostscriptGetString(version,"GS_DLL",buffer,sizeof(buffer)) == 0)
1108 p=strrchr(buffer, '\\');
1109 if (p == (char *) NULL)
1113 (void) CopyMagickString(p,path,sizeof(buffer)-strlen(buffer));
1114 (void) CopyMagickString(path,buffer,length);
1119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1123 % N T G h o s t s c r i p t F o n t s %
1127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1129 % NTGhostscriptFonts() gets the path to the Ghostscript fonts. The method
1130 % returns MagickFalse if an error occurs otherwise MagickTrue.
1132 % The format of the NTGhostscriptFonts method is:
1134 % int NTGhostscriptFonts(char *path,int length)
1136 % A description of each parameter follows:
1138 % o path: Pointer to buffer in which to return result.
1140 % o length: Length of buffer.
1143 MagickExport int NTGhostscriptFonts(char *path,int length)
1146 buffer[MaxTextExtent],
1147 filename[MaxTextExtent];
1157 version=NTGetLatestGhostscript();
1158 if ((version == FALSE) || (version < GS_MINIMUM_VERSION))
1160 if (!NTGhostscriptGetString(version,"GS_LIB",buffer,MaxTextExtent))
1162 for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
1164 (void) CopyMagickString(path,p+1,length+1);
1165 q=strchr(path,DirectoryListSeparator);
1166 if (q != (char *) NULL)
1168 FormatMagickString(filename,MaxTextExtent,"%s%sfonts.dir",path,
1169 DirectorySeparator);
1170 if (IsPathAccessible(filename) != MagickFalse)
1177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1181 % N T G h o s t s c r i p t L o a d D L L %
1185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1187 % NTGhostscriptLoadDLL() attempts to load the Ghostscript DLL and returns
1188 % MagickTrue if it succeeds.
1190 % The format of the NTGhostscriptLoadDLL method is:
1192 % int NTGhostscriptLoadDLL(void)
1195 MagickExport int NTGhostscriptLoadDLL(void)
1198 module_path[MaxTextExtent];
1200 if (gs_dll_handle != (void *) NULL)
1202 if (NTGhostscriptDLL(module_path,sizeof(module_path)) == MagickFalse)
1203 return(MagickFalse);
1204 gs_dll_handle=NTOpenLibrary(module_path);
1205 if (gs_dll_handle == (void *) NULL)
1206 return(MagickFalse);
1207 (void) ResetMagickMemory((void *) &gs_vectors,0,sizeof(GhostscriptVectors));
1208 gs_vectors.exit=(int (MagickDLLCall *)
1209 (gs_main_instance *)) NTGetLibrarySymbol(gs_dll_handle,"gsapi_exit");
1210 gs_vectors.init_with_args=(int (MagickDLLCall *)
1211 (gs_main_instance *,int,char **))
1212 (NTGetLibrarySymbol(gs_dll_handle,"gsapi_init_with_args"));
1213 gs_vectors.new_instance=(int (MagickDLLCall *) (gs_main_instance **,void *))
1214 (NTGetLibrarySymbol(gs_dll_handle,"gsapi_new_instance"));
1215 gs_vectors.run_string=(int (MagickDLLCall *)
1216 (gs_main_instance *,const char *,int,int *))
1217 (NTGetLibrarySymbol(gs_dll_handle,"gsapi_run_string"));
1218 gs_vectors.delete_instance=(void (MagickDLLCall *)(gs_main_instance *))
1219 (NTGetLibrarySymbol(gs_dll_handle,"gsapi_delete_instance"));
1220 if ((gs_vectors.exit == NULL) ||
1221 (gs_vectors.init_with_args == NULL) ||
1222 (gs_vectors.new_instance == NULL) ||
1223 (gs_vectors.run_string == NULL) ||
1224 (gs_vectors.delete_instance == NULL))
1225 return(MagickFalse);
1230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1234 % N T G h o s t s c r i p t U n L o a d D L L %
1238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1240 % NTGhostscriptUnLoadDLL() unloads the Ghostscript DLL if it is loaded.
1242 % The format of the NTGhostscriptUnLoadDLL method is:
1244 % int NTGhostscriptUnLoadDLL(void)
1247 MagickExport int NTGhostscriptUnLoadDLL(void)
1249 if (gs_dll_handle == (void *) NULL)
1250 return(MagickFalse);
1251 NTCloseLibrary(gs_dll_handle);
1252 gs_dll_handle=(void *) NULL;
1253 (void) ResetMagickMemory((void *) &gs_vectors,0,sizeof(GhostscriptVectors));
1258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1262 % N T I n i t i a l i z e L i b r a r y %
1266 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1268 % NTInitializeLibrary() initializes the dynamic module loading subsystem.
1270 % The format of the NTInitializeLibrary method is:
1272 % int NTInitializeLibrary(void)
1275 MagickExport int NTInitializeLibrary(void)
1281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1285 + N T M a p M e m o r y %
1289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1291 % Mmap() emulates the Unix method of the same name.
1293 % The format of the NTMapMemory method is:
1295 % MagickExport void *NTMapMemory(char *address,size_t length,int protection,
1296 % int access,int file,MagickOffsetType offset)
1299 MagickExport void *NTMapMemory(char *address,size_t length,int protection,
1300 int flags,int file,MagickOffsetType offset)
1318 file_handle=INVALID_HANDLE_VALUE;
1319 low_length=(DWORD) (length & 0xFFFFFFFFUL);
1320 high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
1321 map_handle=INVALID_HANDLE_VALUE;
1323 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
1324 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
1326 if (protection & PROT_WRITE)
1328 access_mode=FILE_MAP_WRITE;
1329 if (!(flags & MAP_PRIVATE))
1330 protection_mode=PAGE_READWRITE;
1333 access_mode=FILE_MAP_COPY;
1334 protection_mode=PAGE_WRITECOPY;
1338 if (protection & PROT_READ)
1340 access_mode=FILE_MAP_READ;
1341 protection_mode=PAGE_READONLY;
1343 if ((file == -1) && (flags & MAP_ANONYMOUS))
1344 file_handle=INVALID_HANDLE_VALUE;
1346 file_handle=(HANDLE) _get_osfhandle(file);
1347 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
1351 map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
1353 CloseHandle(map_handle);
1355 if (map == (void *) NULL)
1356 return((void *) MAP_FAILED);
1357 return((void *) ((char *) map));
1361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1365 % N T O p e n D i r e c t o r y %
1369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1371 % NTOpenDirectory() opens the directory named by filename and associates a
1372 % directory stream with it.
1374 % The format of the NTOpenDirectory method is:
1376 % DIR *NTOpenDirectory(const char *path)
1378 % A description of each parameter follows:
1380 % o entry: Specifies a pointer to a DIR structure.
1383 MagickExport DIR *NTOpenDirectory(const char *path)
1386 file_specification[MaxTextExtent];
1394 assert(path != (const char *) NULL);
1395 length=CopyMagickString(file_specification,path,MaxTextExtent);
1396 if (length >= MaxTextExtent)
1397 return((DIR *) NULL);
1398 length=ConcatenateMagickString(file_specification,DirectorySeparator,
1400 if (length >= MaxTextExtent)
1401 return((DIR *) NULL);
1402 entry=(DIR *) AcquireMagickMemory(sizeof(DIR));
1403 if (entry != (DIR *) NULL)
1405 entry->firsttime=TRUE;
1406 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1408 if (entry->hSearch == INVALID_HANDLE_VALUE)
1410 length=ConcatenateMagickString(file_specification,"\\*.*",MaxTextExtent);
1411 if (length >= MaxTextExtent)
1413 entry=(DIR *) RelinquishMagickMemory(entry);
1414 return((DIR *) NULL);
1416 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1417 if (entry->hSearch == INVALID_HANDLE_VALUE)
1419 entry=(DIR *) RelinquishMagickMemory(entry);
1420 return((DIR *) NULL);
1427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1431 % N T O p e n L i b r a r y %
1435 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1437 % NTOpenLibrary() loads a dynamic module into memory and returns a handle that
1438 % can be used to access the various procedures in the module.
1440 % The format of the NTOpenLibrary method is:
1442 % void *NTOpenLibrary(const char *filename)
1444 % A description of each parameter follows:
1446 % o path: Specifies a pointer to string representing dynamic module that
1451 static const char *GetSearchPath( void )
1453 #if defined(MAGICKCORE_LTDL_DELEGATE)
1454 return(lt_dlgetsearchpath());
1456 return(lt_slsearchpath);
1460 MagickExport void *NTOpenLibrary(const char *filename)
1462 #define MaxPathElements 31
1465 buffer[MaxTextExtent];
1483 mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
1484 handle=(void *) LoadLibraryEx(filename,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1485 if ((handle != (void *) NULL) || (GetSearchPath() == (char *) NULL))
1490 p=(char *) GetSearchPath();
1492 while (index < MaxPathElements)
1494 q=strchr(p,DirectoryListSeparator);
1495 if (q == (char *) NULL)
1497 (void) CopyMagickString(buffer,p,MaxTextExtent);
1498 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
1499 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
1500 handle=(void *) LoadLibraryEx(buffer,NULL,
1501 LOAD_WITH_ALTERED_SEARCH_PATH);
1505 (void) CopyMagickString(buffer,p,i+1);
1506 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
1507 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
1508 handle=(void *) LoadLibraryEx(buffer,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1509 if (handle != (void *) NULL)
1518 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1522 % N T R e a d D i r e c t o r y %
1526 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1528 % NTReadDirectory() returns a pointer to a structure representing the
1529 % directory entry at the current position in the directory stream to which
1532 % The format of the NTReadDirectory
1534 % NTReadDirectory(entry)
1536 % A description of each parameter follows:
1538 % o entry: Specifies a pointer to a DIR structure.
1541 MagickExport struct dirent *NTReadDirectory(DIR *entry)
1549 if (entry == (DIR *) NULL)
1550 return((struct dirent *) NULL);
1551 if (!entry->firsttime)
1553 status=FindNextFile(entry->hSearch,&entry->Win32FindData);
1555 return((struct dirent *) NULL);
1557 length=CopyMagickString(entry->file_info.d_name,
1558 entry->Win32FindData.cFileName,sizeof(entry->file_info.d_name));
1559 if (length >= sizeof(entry->file_info.d_name))
1560 return((struct dirent *) NULL);
1561 entry->firsttime=FALSE;
1562 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
1563 return(&entry->file_info);
1567 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1571 % N T R e g i s t r y K e y L o o k u p %
1575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1577 % NTRegistryKeyLookup() returns ImageMagick installation path settings
1578 % stored in the Windows Registry. Path settings are specific to the
1579 % installed ImageMagick version so that multiple Image Magick installations
1582 % Values are stored in the registry under a base path path similar to
1583 % "HKEY_LOCAL_MACHINE/SOFTWARE\ImageMagick\5.5.7\Q:16". The provided subkey
1584 % is appended to this base path to form the full key.
1586 % The format of the NTRegistryKeyLookup method is:
1588 % unsigned char *NTRegistryKeyLookup(const char *subkey)
1590 % A description of each parameter follows:
1592 % o subkey: Specifies a string that identifies the registry object.
1593 % Currently supported sub-keys include: "BinPath", "ConfigurePath",
1594 % "LibPath", "CoderModulesPath", "FilterModulesPath", "SharePath".
1597 MagickExport unsigned char *NTRegistryKeyLookup(const char *subkey)
1600 package_key[MaxTextExtent];
1618 (void) FormatMagickString(package_key,MaxTextExtent,"SOFTWARE\\%s\\%s\\Q:%d",
1619 MagickPackageName,MagickLibVersionText,MAGICKCORE_QUANTUM_DEPTH);
1620 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",package_key);
1621 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1622 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,package_key,0,KEY_READ,®istry_key);
1623 if (status != ERROR_SUCCESS)
1625 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1626 return((unsigned char *) NULL);
1632 value=(unsigned char *) AcquireQuantumMemory(size,sizeof(*value));
1633 if (value == (unsigned char *) NULL)
1635 RegCloseKey(registry_key);
1636 return((unsigned char *) NULL);
1638 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",subkey);
1639 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1640 if ((status == ERROR_MORE_DATA) && (type == REG_SZ))
1642 value=(unsigned char *) ResizeQuantumMemory(value,size,sizeof(*value));
1643 if (value == (BYTE *) NULL)
1645 RegCloseKey(registry_key);
1646 return((unsigned char *) NULL);
1648 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1650 RegCloseKey(registry_key);
1651 if ((type != REG_SZ) || (status != ERROR_SUCCESS))
1652 value=(unsigned char *) RelinquishMagickMemory(value);
1653 return((unsigned char *) value);
1657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1661 % N T R e p o r t E v e n t %
1665 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1667 % NTReportEvent() reports an event.
1669 % The format of the NTReportEvent method is:
1671 % MagickBooleanType NTReportEvent(const char *event,
1672 % const MagickBooleanType error)
1674 % A description of each parameter follows:
1676 % o event: the event.
1678 % o error: MagickTrue the event is an error.
1681 MagickExport MagickBooleanType NTReportEvent(const char *event,
1682 const MagickBooleanType error)
1693 handle=RegisterEventSource(NULL,MAGICKCORE_PACKAGE_NAME);
1695 return(MagickFalse);
1697 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
1698 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
1699 DeregisterEventSource(handle);
1704 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1708 % N T R e s o u r c e T o B l o b %
1712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1714 % NTResourceToBlob() returns a blob containing the contents of the resource
1715 % in the current executable specified by the id parameter. This currently
1716 % used to retrieve MGK files tha have been embedded into the various command
1719 % The format of the NTResourceToBlob method is:
1721 % unsigned char *NTResourceToBlob(const char *id)
1723 % A description of each parameter follows:
1725 % o id: Specifies a string that identifies the resource.
1728 MagickExport unsigned char *NTResourceToBlob(const char *id)
1731 path[MaxTextExtent];
1749 assert(id != (const char *) NULL);
1750 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
1751 (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",GetClientPath(),
1752 DirectorySeparator,GetClientName());
1753 if (IsPathAccessible(path) != MagickFalse)
1754 handle=GetModuleHandle(path);
1756 handle=GetModuleHandle(0);
1758 return((unsigned char *) NULL);
1759 resource=FindResource(handle,id,"IMAGEMAGICK");
1761 return((unsigned char *) NULL);
1762 global=LoadResource(handle,resource);
1764 return((unsigned char *) NULL);
1765 length=SizeofResource(handle,resource);
1766 value=(unsigned char *) LockResource(global);
1769 FreeResource(global);
1770 return((unsigned char *) NULL);
1772 blob=(unsigned char *) AcquireQuantumMemory(length+MaxTextExtent,
1774 if (blob != (unsigned char *) NULL)
1776 (void) CopyMagickMemory(blob,value,length);
1779 UnlockResource(global);
1780 FreeResource(global);
1785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1789 % N T S e e k D i r e c t o r y %
1793 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1795 % NTSeekDirectory() sets the position of the next NTReadDirectory() operation
1796 % on the directory stream.
1798 % The format of the NTSeekDirectory method is:
1800 % void NTSeekDirectory(DIR *entry,long position)
1802 % A description of each parameter follows:
1804 % o entry: Specifies a pointer to a DIR structure.
1806 % o position: specifies the position associated with the directory
1810 MagickExport void NTSeekDirectory(DIR *entry,long position)
1812 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1813 assert(entry != (DIR *) NULL);
1817 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1821 % N T S e t S e a r c h P a t h %
1825 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1827 % NTSetSearchPath() sets the current locations that the subsystem should
1828 % look at to find dynamically loadable modules.
1830 % The format of the NTSetSearchPath method is:
1832 % int NTSetSearchPath(const char *path)
1834 % A description of each parameter follows:
1836 % o path: Specifies a pointer to string representing the search path
1837 % for DLL's that can be dynamically loaded.
1840 MagickExport int NTSetSearchPath(const char *path)
1842 #if defined(MAGICKCORE_LTDL_DELEGATE)
1843 lt_dlsetsearchpath(path);
1845 if (lt_slsearchpath != (char *) NULL)
1846 lt_slsearchpath=DestroyString(lt_slsearchpath);
1847 if (path != (char *) NULL)
1848 lt_slsearchpath=AcquireString(path);
1854 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1858 + N T S y n c M e m o r y %
1862 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1864 % NTSyncMemory() emulates the Unix method of the same name.
1866 % The format of the NTSyncMemory method is:
1868 % int NTSyncMemory(void *address,size_t length,int flags)
1870 % A description of each parameter follows:
1872 % o address: the address of the binary large object.
1874 % o length: the length of the binary large object.
1876 % o flags: Option flags (ignored for Windows).
1879 MagickExport int NTSyncMemory(void *address,size_t length,int flags)
1881 if (FlushViewOfFile(address,length) == MagickFalse)
1887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1891 % N T S y s t e m C o m m a n d %
1895 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1897 % NTSystemCommand() executes the specified command and waits until it
1898 % terminates. The returned value is the exit status of the command.
1900 % The format of the NTSystemCommand method is:
1902 % int NTSystemCommand(const char *command)
1904 % A description of each parameter follows:
1906 % o command: This string is the command to execute.
1909 MagickExport int NTSystemCommand(const char *command)
1912 local_command[MaxTextExtent];
1929 if (command == (char *) NULL)
1931 GetStartupInfo(&startup_info);
1932 startup_info.dwFlags=STARTF_USESHOWWINDOW;
1933 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
1934 (void) CopyMagickString(local_command,command,MaxTextExtent);
1935 background_process=command[strlen(command)-1] == '&' ? MagickTrue :
1937 if (background_process)
1938 local_command[strlen(command)-1]='\0';
1939 if (command[strlen(command)-1] == '|')
1940 local_command[strlen(command)-1]='\0';
1942 startup_info.wShowWindow=SW_SHOWDEFAULT;
1943 status=CreateProcess((LPCTSTR) NULL,local_command,
1944 (LPSECURITY_ATTRIBUTES) NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) FALSE,
1945 (DWORD) NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
1949 if (background_process)
1950 return(status == 0);
1951 status=WaitForSingleObject(process_info.hProcess,INFINITE);
1952 if (status != WAIT_OBJECT_0)
1954 status=GetExitCodeProcess(process_info.hProcess,&child_status);
1957 CloseHandle(process_info.hProcess);
1958 CloseHandle(process_info.hThread);
1959 return((int) child_status);
1963 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1967 % N T S y s t e m C o n i f i g u r a t i o n %
1971 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1973 % NTSystemConfiguration() provides a way for the application to determine
1974 % values for system limits or options at runtime.
1976 % The format of the exit method is:
1978 % long NTSystemConfiguration(int name)
1980 % A description of each parameter follows:
1982 % o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
1985 MagickExport long NTSystemConfiguration(int name)
1994 GetSystemInfo(&system_info);
1995 return(system_info.dwPageSize);
1997 case _SC_PHYS_PAGES:
2011 handle=GetModuleHandle("kernel32.dll");
2012 if (handle == (HMODULE) NULL)
2014 GetSystemInfo(&system_info);
2015 module=(LPFNDLLFUNC2) NTGetLibrarySymbol(handle,"GlobalMemoryStatusEx");
2016 if (module == (LPFNDLLFUNC2) NULL)
2021 GlobalMemoryStatus(&status);
2022 return((long) status.dwTotalPhys/system_info.dwPageSize);
2024 status.dwLength=sizeof(status);
2025 if (module(&status) == 0)
2027 return((long) status.ullTotalPhys/system_info.dwPageSize);
2038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2042 % N T T e l l D i r e c t o r y %
2046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2048 % NTTellDirectory() returns the current location associated with the named
2051 % The format of the NTTellDirectory method is:
2053 % long NTTellDirectory(DIR *entry)
2055 % A description of each parameter follows:
2057 % o entry: Specifies a pointer to a DIR structure.
2060 MagickExport long NTTellDirectory(DIR *entry)
2062 assert(entry != (DIR *) NULL);
2067 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2071 % N T T r u n c a t e F i l e %
2075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2077 % NTTruncateFile() truncates a file to a specified length.
2079 % The format of the NTTruncateFile method is:
2081 % int NTTruncateFile(int file,off_t length)
2083 % A description of each parameter follows:
2087 % o length: the file length.
2090 MagickExport int NTTruncateFile(int file,off_t length)
2100 file_handle=_get_osfhandle(file);
2101 if (file_handle == -1L)
2103 low=(long) (length & 0xffffffffUL);
2104 high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
2105 file_pointer=SetFilePointer((HANDLE) file_handle,low,&high,FILE_BEGIN);
2106 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
2108 if (SetEndOfFile((HANDLE) file_handle) == 0)
2114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2118 + N T U n m a p M e m o r y %
2122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2124 % NTUnmapMemory() emulates the Unix munmap method.
2126 % The format of the NTUnmapMemory method is:
2128 % int NTUnmapMemory(void *map,size_t length)
2130 % A description of each parameter follows:
2132 % o map: the address of the binary large object.
2134 % o length: the length of the binary large object.
2137 MagickExport int NTUnmapMemory(void *map,size_t length)
2139 if (UnmapViewOfFile(map) == 0)
2145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2149 % N T U s e r T i m e %
2153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2155 % NTUserTime() returns the total time the process has been scheduled (e.g.
2156 % seconds) since the last call to StartTimer().
2158 % The format of the UserTime method is:
2160 % double NTUserTime(void)
2163 MagickExport double NTUserTime(void)
2193 OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
2194 GetVersionEx(&OsVersionInfo);
2195 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
2196 return(NTElapsedTime());
2197 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
2198 &kernel_time.filetime,&user_time.filetime);
2201 return((double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
2205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2209 % N T W a r n i n g H a n d l e r %
2213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2215 % NTWarningHandler() displays a warning reason.
2217 % The format of the NTWarningHandler method is:
2219 % void NTWarningHandler(const ExceptionType warning,const char *reason,
2220 % const char *description)
2222 % A description of each parameter follows:
2224 % o warning: Specifies the numeric warning category.
2226 % o reason: Specifies the reason to display before terminating the
2229 % o description: Specifies any description to the reason.
2232 MagickExport void NTWarningHandler(const ExceptionType warning,
2233 const char *reason,const char *description)
2236 buffer[2*MaxTextExtent];
2238 if (reason == (char *) NULL)
2240 if (description == (char *) NULL)
2241 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s.\n",GetClientName(),
2244 (void) FormatMagickString(buffer,MaxTextExtent,"%s: %s (%s).\n",
2245 GetClientName(),reason,description);
2246 (void) MessageBox(NULL,buffer,"ImageMagick Warning",MB_OK | MB_TASKMODAL |
2247 MB_SETFOREGROUND | MB_ICONINFORMATION);