2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Windows NT Utility Methods for MagickCore %
20 % Copyright 1999-2011 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 "MagickCore/studio.h"
42 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
43 #include "MagickCore/client.h"
44 #include "MagickCore/cache.h"
45 #include "MagickCore/color.h"
46 #include "MagickCore/colorspace.h"
47 #include "MagickCore/colorspace-private.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/image.h"
50 #include "MagickCore/locale_.h"
51 #include "MagickCore/log.h"
52 #include "MagickCore/magick.h"
53 #include "MagickCore/memory_.h"
54 #include "MagickCore/monitor.h"
55 #include "MagickCore/monitor-private.h"
56 #include "MagickCore/pixel-accessor.h"
57 #include "MagickCore/resource_.h"
58 #include "MagickCore/resource-private.h"
59 #include "MagickCore/timer.h"
60 #include "MagickCore/type.h"
61 #include "MagickCore/string_.h"
62 #include "MagickCore/token.h"
63 #include "MagickCore/utility.h"
64 #include "MagickCore/version.h"
65 #if defined(MAGICKCORE_LTDL_DELEGATE)
68 #include "MagickCore/nt-base.h"
69 #include "MagickCore/nt-base-private.h"
70 #if defined(MAGICKCORE_CIPHER_SUPPORT)
78 #if !defined(MAP_FAILED)
79 #define MAP_FAILED ((void *) -1)
85 #if !defined(MAGICKCORE_LTDL_DELEGATE)
87 *lt_slsearchpath = (char *) NULL;
94 *ghost_handle = (void *) NULL;
97 External declarations.
99 #if !defined(MAGICKCORE_WINDOWS_SUPPORT)
100 extern "C" BOOL WINAPI
101 DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved);
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 % C r o p I m a g e T o H B i t m a p %
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 % CropImageToHBITMAP() extracts a specified region of the image and returns
116 % it as a Windows HBITMAP. While the same functionality can be accomplished by
117 % invoking CropImage() followed by ImageToHBITMAP(), this method is more
118 % efficient since it copies pixels directly to the HBITMAP.
120 % The format of the CropImageToHBITMAP method is:
122 % HBITMAP CropImageToHBITMAP(Image* image,const RectangleInfo *geometry,
123 % ExceptionInfo *exception)
125 % A description of each parameter follows:
127 % o image: the image.
129 % o geometry: Define the region of the image to crop with members
130 % x, y, width, and height.
132 % o exception: return any errors or warnings in this structure.
135 MagickExport void *CropImageToHBITMAP(Image *image,
136 const RectangleInfo *geometry,ExceptionInfo *exception)
138 #define CropImageTag "Crop/Image"
155 register const Quantum
170 assert(image != (const Image *) NULL);
171 assert(image->signature == MagickSignature);
172 if (image->debug != MagickFalse)
173 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
174 assert(geometry != (const RectangleInfo *) NULL);
175 assert(exception != (ExceptionInfo *) NULL);
176 assert(exception->signature == MagickSignature);
177 if (((geometry->x+(ssize_t) geometry->width) < 0) ||
178 ((geometry->y+(ssize_t) geometry->height) < 0) ||
179 (geometry->x >= (ssize_t) image->columns) ||
180 (geometry->y >= (ssize_t) image->rows))
181 ThrowImageException(OptionError,"GeometryDoesNotContainImage");
183 if ((page.x+(ssize_t) page.width) > (ssize_t) image->columns)
184 page.width=image->columns-page.x;
185 if ((page.y+(ssize_t) page.height) > (ssize_t) image->rows)
186 page.height=image->rows-page.y;
198 if ((page.width == 0) || (page.height == 0))
199 ThrowImageException(OptionError,"GeometryDimensionsAreZero");
201 Initialize crop image attributes.
204 bitmap.bmWidth = (LONG) page.width;
205 bitmap.bmHeight = (LONG) page.height;
206 bitmap.bmWidthBytes = bitmap.bmWidth * 4;
208 bitmap.bmBitsPixel = 32;
209 bitmap.bmBits = NULL;
211 bitmap_bitsH=(HANDLE) GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,page.width*
212 page.height*bitmap.bmBitsPixel);
213 if (bitmap_bitsH == NULL)
215 bitmap_bits=(RGBQUAD *) GlobalLock((HGLOBAL) bitmap_bitsH);
216 if ( bitmap.bmBits == NULL )
217 bitmap.bmBits = bitmap_bits;
218 if (IsRGBColorspace(image->colorspace) == MagickFalse)
219 TransformImageColorspace(image,RGBColorspace,exception);
224 for (y=0; y < (ssize_t) page.height; y++)
226 p=GetVirtualPixels(image,page.x,page.y+y,page.width,1,exception);
227 if (p == (const Quantum *) NULL)
230 #if MAGICKCORE_QUANTUM_DEPTH == 8
231 /* Form of PixelInfo is identical to RGBQUAD when MAGICKCORE_QUANTUM_DEPTH==8 */
232 CopyMagickMemory((void*)q,(const void*)p,page.width*sizeof(PixelInfo));
235 #else /* 16 or 32 bit Quantum */
240 /* Transfer pixels, scaling to Quantum */
241 for( x=(ssize_t) page.width ; x> 0 ; x-- )
243 q->rgbRed = ScaleQuantumToChar(GetPixelRed(image,p));
244 q->rgbGreen = ScaleQuantumToChar(GetPixelGreen(image,p));
245 q->rgbBlue = ScaleQuantumToChar(GetPixelBlue(image,p));
252 proceed=SetImageProgress(image,CropImageTag,y,page.height);
253 if (proceed == MagickFalse)
256 if (y < (ssize_t) page.height)
258 GlobalUnlock((HGLOBAL) bitmap_bitsH);
259 GlobalFree((HGLOBAL) bitmap_bitsH);
260 return((void *) NULL);
262 bitmap.bmBits=bitmap_bits;
263 bitmapH=CreateBitmapIndirect(&bitmap);
264 GlobalUnlock((HGLOBAL) bitmap_bitsH);
265 GlobalFree((HGLOBAL) bitmap_bitsH);
266 return((void *) bitmapH);
270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 % DllMain() is an entry point to the DLL which is called when processes and
281 % threads are initialized and terminated, or upon calls to the Windows
282 % LoadLibrary and FreeLibrary functions.
284 % The function returns TRUE of it succeeds, or FALSE if initialization fails.
286 % The format of the DllMain method is:
288 % BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
290 % A description of each parameter follows:
292 % o handle: handle to the DLL module
294 % o reason: reason for calling function:
296 % DLL_PROCESS_ATTACH - DLL is being loaded into virtual address
297 % space of current process.
298 % DLL_THREAD_ATTACH - Indicates that the current process is
299 % creating a new thread. Called under the
300 % context of the new thread.
301 % DLL_THREAD_DETACH - Indicates that the thread is exiting.
302 % Called under the context of the exiting
304 % DLL_PROCESS_DETACH - Indicates that the DLL is being unloaded
305 % from the virtual address space of the
308 % o lpvReserved: Used for passing additional info during DLL_PROCESS_ATTACH
309 % and DLL_PROCESS_DETACH.
312 #if defined(_DLL) && defined( ProvideDllMain )
313 BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
317 case DLL_PROCESS_ATTACH:
325 module_path=(char *) AcquireQuantumMemory(MaxTextExtent,
326 sizeof(*module_path));
327 if (module_path == (char *) NULL)
329 count=(ssize_t) GetModuleFileName(handle,module_path,MaxTextExtent);
335 for ( ; count > 0; count--)
336 if (module_path[count] == '\\')
338 module_path[count+1]='\0';
341 MagickCoreGenesis(module_path,MagickFalse);
342 path=(char *) AcquireQuantumMemory(16UL*MaxTextExtent,sizeof(*path));
343 if (path == (char *) NULL)
345 module_path=DestroyString(module_path);
348 count=(ssize_t) GetEnvironmentVariable("PATH",path,16*MaxTextExtent);
349 if ((count != 0) && (strstr(path,module_path) == (char *) NULL))
351 if ((strlen(module_path)+count+1) < (16*MaxTextExtent-1))
356 variable=(char *) AcquireQuantumMemory(16UL*MaxTextExtent,
358 if (variable == (char *) NULL)
360 path=DestroyString(path);
361 module_path=DestroyString(module_path);
364 (void) FormatLocaleString(variable,16*MaxTextExtent,
365 "%s;%s",module_path,path);
366 SetEnvironmentVariable("PATH",variable);
367 variable=DestroyString(variable);
370 path=DestroyString(path);
372 module_path=DestroyString(module_path);
375 case DLL_PROCESS_DETACH:
377 MagickCoreTerminus();
388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
398 % Exit() calls TerminateProcess for Win95.
400 % The format of the exit method is:
402 % int Exit(int status)
404 % A description of each parameter follows:
406 % o status: an integer value representing the status of the terminating
410 MagickPrivate int Exit(int status)
413 TerminateProcess(GetCurrentProcess(),(unsigned int) status);
418 #if !defined(__MINGW32__)
420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
424 % g e t t i m e o f d a y %
428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
430 % The gettimeofday() method get the time of day.
432 % The format of the gettimeofday method is:
434 % int gettimeofday(struct timeval *time_value,struct timezone *time_zone)
436 % A description of each parameter follows:
438 % o time_value: the time value.
440 % o time_zone: the time zone.
443 MagickPrivate int gettimeofday (struct timeval *time_value,
444 struct timezone *time_zone)
446 #define EpochFiletime MagickLLConstant(116444736000000000)
451 if (time_value != (struct timeval *) NULL)
462 GetSystemTimeAsFileTime(&file_time);
463 date_time.LowPart=file_time.dwLowDateTime;
464 date_time.HighPart=file_time.dwHighDateTime;
465 time=date_time.QuadPart;
468 time_value->tv_sec=(ssize_t) (time / 1000000);
469 time_value->tv_usec=(ssize_t) (time % 1000000);
471 if (time_zone != (struct timezone *) NULL)
478 time_zone->tz_minuteswest=_timezone/60;
479 time_zone->tz_dsttime=_daylight;
486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
490 % I m a g e T o H B i t m a p %
494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
496 % ImageToHBITMAP() creates a Windows HBITMAP from an image.
498 % The format of the ImageToHBITMAP method is:
500 % HBITMAP ImageToHBITMAP(Image *image)
502 % A description of each parameter follows:
504 % o image: the image to convert.
507 MagickExport void *ImageToHBITMAP(Image *image)
524 register const Quantum
539 (void) ResetMagickMemory(&bitmap,0,sizeof(bitmap));
541 bitmap.bmWidth=(LONG) image->columns;
542 bitmap.bmHeight=(LONG) image->rows;
543 bitmap.bmWidthBytes=4*bitmap.bmWidth;
545 bitmap.bmBitsPixel=32;
547 length=bitmap.bmWidthBytes*bitmap.bmHeight;
548 bitmap_bitsH=(HANDLE) GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,length);
549 if (bitmap_bitsH == NULL)
554 message=GetExceptionMessage(errno);
555 (void) ThrowMagickException(&image->exception,GetMagickModule(),
556 ResourceLimitError,"MemoryAllocationFailed","`%s'",message);
557 message=DestroyString(message);
560 bitmap_bits=(RGBQUAD *) GlobalLock((HGLOBAL) bitmap_bitsH);
562 if (bitmap.bmBits == NULL)
563 bitmap.bmBits=bitmap_bits;
564 (void) TransformImageColorspace(image,RGBColorspace,exception);
565 exception=(&image->exception);
566 for (y=0; y < (ssize_t) image->rows; y++)
568 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
569 if (p == (const Quantum *) NULL)
571 for (x=0; x < (ssize_t) image->columns; x++)
573 q->rgbRed=ScaleQuantumToChar(GetPixelRed(image,p));
574 q->rgbGreen=ScaleQuantumToChar(GetPixelGreen(image,p));
575 q->rgbBlue=ScaleQuantumToChar(GetPixelBlue(image,p));
577 p+=GetPixelChannels(image);
581 bitmap.bmBits=bitmap_bits;
582 bitmapH=CreateBitmapIndirect(&bitmap);
588 message=GetExceptionMessage(errno);
589 (void) ThrowMagickException(&image->exception,GetMagickModule(),
590 ResourceLimitError,"MemoryAllocationFailed","`%s'",message);
591 message=DestroyString(message);
593 GlobalUnlock((HGLOBAL) bitmap_bitsH);
594 GlobalFree((HGLOBAL) bitmap_bitsH);
595 return((void *) bitmapH);
599 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
603 % I s W i n d o w s 9 5 %
607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
609 % IsWindows95() returns true if the system is Windows 95.
611 % The format of the IsWindows95 method is:
616 MagickPrivate int IsWindows95(void)
621 version_info.dwOSVersionInfoSize=sizeof(version_info);
622 if (GetVersionEx(&version_info) &&
623 (version_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS))
629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
633 % N T A r g v T o U T F 8 %
637 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
639 % NTArgvToUTF8() converts the wide command line arguments to UTF-8 to ensure
640 % compatibility with Linux.
642 % The format of the NTArgvToUTF8 method is:
644 % char **NTArgvToUTF8(const int argc,wchar_t **argv)
646 % A description of each parameter follows:
648 % o argc: the number of command line arguments.
650 % o argv: the wide-character command line arguments.
653 MagickExport char **NTArgvToUTF8(const int argc,wchar_t **argv)
661 utf8=(char **) AcquireQuantumMemory(argc,sizeof(*utf8));
662 if (utf8 == (char **) NULL)
663 ThrowFatalException(ResourceLimitFatalError,"UnableToConvertStringToARGV");
664 for (i=0; i < (ssize_t) argc; i++)
669 count=WideCharToMultiByte(CP_UTF8,0,argv[i],-1,NULL,0,NULL,NULL);
672 utf8[i]=(char *) AcquireQuantumMemory(count+1,sizeof(**utf8));
673 if (utf8[i] == (char *) NULL)
675 for (i--; i >= 0; i--)
676 utf8[i]=DestroyString(utf8[i]);
677 utf8=(char **) RelinquishMagickMemory(utf8);
678 ThrowFatalException(ResourceLimitFatalError,
679 "UnableToConvertStringToARGV");
681 count=WideCharToMultiByte(CP_UTF8,0,argv[i],-1,utf8[i],count,NULL,NULL);
688 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
692 % N T C l o s e D i r e c t o r y %
696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
698 % NTCloseDirectory() closes the named directory stream and frees the DIR
701 % The format of the NTCloseDirectory method is:
703 % int NTCloseDirectory(DIR *entry)
705 % A description of each parameter follows:
707 % o entry: Specifies a pointer to a DIR structure.
710 MagickPrivate int NTCloseDirectory(DIR *entry)
712 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
713 assert(entry != (DIR *) NULL);
714 FindClose(entry->hSearch);
715 entry=(DIR *) RelinquishMagickMemory(entry);
720 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
724 % N T C l o s e L i b r a r y %
728 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
730 % NTCloseLibrary() unloads the module associated with the passed handle.
732 % The format of the NTCloseLibrary method is:
734 % void NTCloseLibrary(void *handle)
736 % A description of each parameter follows:
738 % o handle: Specifies a handle to a previously loaded dynamic module.
741 MagickPrivate int NTCloseLibrary(void *handle)
744 return(FreeLibrary((HINSTANCE) handle));
745 return(!(FreeLibrary((HINSTANCE) handle)));
749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
753 % N T C o n t r o l H a n d l e r %
757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
759 % NTControlHandler() registers a control handler that is activated when, for
760 % example, a ctrl-c is received.
762 % The format of the NTControlHandler method is:
764 % int NTControlHandler(void)
768 static BOOL ControlHandler(DWORD type)
771 AsynchronousResourceComponentTerminus();
775 MagickPrivate int NTControlHandler(void)
777 return(SetConsoleCtrlHandler((PHANDLER_ROUTINE) ControlHandler,TRUE));
781 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
785 % N T E l a p s e d T i m e %
789 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
791 % NTElapsedTime() returns the elapsed time (in seconds) since the last call to
794 % The format of the ElapsedTime method is:
796 % double NTElapsedTime(void)
799 MagickPrivate double NTElapsedTime(void)
813 GetSystemTime(&system_time);
814 SystemTimeToFileTime(&system_time,&elapsed_time.filetime);
815 return((double) 1.0e-7*elapsed_time.filetime64);
819 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
823 + N T E r r o r H a n d l e r %
827 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
829 % NTErrorHandler() displays an error reason and then terminates the program.
831 % The format of the NTErrorHandler method is:
833 % void NTErrorHandler(const ExceptionType severity,const char *reason,
834 % const char *description)
836 % A description of each parameter follows:
838 % o severity: Specifies the numeric error category.
840 % o reason: Specifies the reason to display before terminating the
843 % o description: Specifies any description to the reason.
846 MagickExport void NTErrorHandler(const ExceptionType severity,
847 const char *reason,const char *description)
850 buffer[3*MaxTextExtent],
854 if (reason == (char *) NULL)
856 MagickCoreTerminus();
859 message=GetExceptionMessage(errno);
860 if ((description != (char *) NULL) && errno)
861 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s (%s) [%s].\n",
862 GetClientName(),reason,description,message);
864 if (description != (char *) NULL)
865 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s (%s).\n",
866 GetClientName(),reason,description);
869 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s [%s].\n",
870 GetClientName(),reason,message);
872 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s.\n",
873 GetClientName(),reason);
874 message=DestroyString(message);
875 (void) MessageBox(NULL,buffer,"ImageMagick Exception",MB_OK | MB_TASKMODAL |
876 MB_SETFOREGROUND | MB_ICONEXCLAMATION);
877 MagickCoreTerminus();
882 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
886 % N T E x i t L i b r a r y %
890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
892 % NTExitLibrary() exits the dynamic module loading subsystem.
894 % The format of the NTExitLibrary method is:
896 % int NTExitLibrary(void)
899 MagickPrivate int NTExitLibrary(void)
905 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
909 % N T G a t h e r R a n d o m D a t a %
913 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
915 % NTGatherRandomData() gathers random data and returns it.
917 % The format of the GatherRandomData method is:
919 % MagickBooleanType NTGatherRandomData(const size_t length,
920 % unsigned char *random)
922 % A description of each parameter follows:
924 % length: the length of random data buffer
926 % random: the random data is returned here.
929 MagickPrivate MagickBooleanType NTGatherRandomData(const size_t length,
930 unsigned char *random)
932 #if defined(MAGICKCORE_CIPHER_SUPPORT) && defined(_MSC_VER) && (_MSC_VER > 1200)
939 handle=(HCRYPTPROV) NULL;
940 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
941 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET));
943 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
944 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET));
947 status=CryptGenRandom(handle,(DWORD) length,random);
950 status=CryptReleaseContext(handle,0);
953 status=CryptReleaseContext(handle,0);
964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
968 % N T G e t E x e c u t i o n P a t h %
972 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
974 % NTGetExecutionPath() returns the execution path of a program.
976 % The format of the GetExecutionPath method is:
978 % MagickBooleanType NTGetExecutionPath(char *path,const size_t extent)
980 % A description of each parameter follows:
982 % o path: the pathname of the executable that started the process.
984 % o extent: the maximum extent of the path.
987 MagickPrivate MagickBooleanType NTGetExecutionPath(char *path,
990 GetModuleFileName(0,path,(DWORD) extent);
995 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
999 % N T G e t L a s t E r r o r %
1003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1005 % NTGetLastError() returns the last error that occurred.
1007 % The format of the NTGetLastError method is:
1009 % char *NTGetLastError(void)
1012 MagickPrivate char *NTGetLastError(void)
1023 status=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
1024 FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),
1025 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR) &buffer,0,NULL);
1027 reason=AcquireString("An unknown error occurred");
1030 reason=AcquireString((const char *) buffer);
1037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1041 % N T G e t L i b r a r y E r r o r %
1045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1047 % Lt_dlerror() returns a pointer to a string describing the last error
1048 % associated with a lt_dl method. Note that this function is not thread
1049 % safe so it should only be used under the protection of a lock.
1051 % The format of the NTGetLibraryError method is:
1053 % const char *NTGetLibraryError(void)
1056 MagickPrivate const char *NTGetLibraryError(void)
1059 last_error[MaxTextExtent];
1065 error=NTGetLastError();
1067 (void) CopyMagickString(last_error,error,MaxTextExtent);
1068 error=DestroyString(error);
1073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1077 % N T G e t L i b r a r y S y m b o l %
1081 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1083 % NTGetLibrarySymbol() retrieve the procedure address of the method
1084 % specified by the passed character string.
1086 % The format of the NTGetLibrarySymbol method is:
1088 % void *NTGetLibrarySymbol(void *handle,const char *name)
1090 % A description of each parameter follows:
1092 % o handle: Specifies a handle to the previously loaded dynamic module.
1094 % o name: Specifies the procedure entry point to be returned.
1097 void *NTGetLibrarySymbol(void *handle,const char *name)
1102 lpfnDllFunc1=(LPFNDLLFUNC1) GetProcAddress((HINSTANCE) handle,name);
1104 return((void *) NULL);
1105 return((void *) lpfnDllFunc1);
1109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1113 % N T G e t M o d u l e P a t h %
1117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1119 % NTGetModulePath() returns the path of the specified module.
1121 % The format of the GetModulePath method is:
1123 % MagickBooleanType NTGetModulePath(const char *module,char *path)
1125 % A description of each parameter follows:
1127 % modith: the module name.
1129 % path: the module path is returned here.
1132 MagickPrivate MagickBooleanType NTGetModulePath(const char *module,char *path)
1135 module_path[MaxTextExtent];
1144 handle=GetModuleHandle(module);
1145 if (handle == (HMODULE) NULL)
1146 return(MagickFalse);
1147 length=GetModuleFileName(handle,module_path,MaxTextExtent);
1149 GetPathComponent(module_path,HeadPath,path);
1154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1158 + N T G e t T y pe L i s t %
1162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1164 % NTLoadTypeLists() loads a Windows TrueType fonts.
1166 % The format of the NTLoadTypeLists method is:
1168 % MagickBooleanType NTLoadTypeLists(SplayTreeInfo *type_list)
1170 % A description of each parameter follows:
1172 % o type_list: A linked list of fonts.
1175 MagickPrivate MagickBooleanType NTLoadTypeLists(SplayTreeInfo *type_list,
1176 ExceptionInfo *exception)
1179 reg_key = (HKEY) INVALID_HANDLE_VALUE;
1189 buffer[MaxTextExtent],
1190 system_root[MaxTextExtent],
1191 font_root[MaxTextExtent];
1201 Try to find the right Windows*\CurrentVersion key, the SystemRoot and
1204 res = RegOpenKeyExA (HKEY_LOCAL_MACHINE,
1205 "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, ®_key);
1206 if (res == ERROR_SUCCESS) {
1207 system_root_length=sizeof(system_root)-1;
1208 res = RegQueryValueExA(reg_key,"SystemRoot",NULL, &type,
1209 (BYTE*) system_root, &system_root_length);
1211 if (res != ERROR_SUCCESS) {
1212 res = RegOpenKeyExA (HKEY_LOCAL_MACHINE,
1213 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 0, KEY_READ, ®_key);
1214 if (res == ERROR_SUCCESS) {
1215 system_root_length=sizeof(system_root)-1;
1216 res = RegQueryValueExA(reg_key,"SystemRoot",NULL, &type,
1217 (BYTE*)system_root, &system_root_length);
1220 if (res == ERROR_SUCCESS)
1221 res = RegOpenKeyExA (reg_key, "Fonts",0, KEY_READ, ®_key);
1222 if (res != ERROR_SUCCESS)
1223 return(MagickFalse);
1225 (void) CopyMagickString(buffer,system_root,MaxTextExtent);
1226 (void) ConcatenateMagickString(buffer,"\\fonts\\arial.ttf",MaxTextExtent);
1227 if (IsPathAccessible(buffer) != MagickFalse)
1229 (void) CopyMagickString(font_root,system_root,MaxTextExtent);
1230 (void) ConcatenateMagickString(font_root,"\\fonts\\",MaxTextExtent);
1234 (void) CopyMagickString(font_root,system_root,MaxTextExtent);
1235 (void) ConcatenateMagickString(font_root,"\\",MaxTextExtent);
1249 value_data[MaxTextExtent],
1250 value_name[MaxTextExtent];
1252 res = ERROR_SUCCESS;
1254 while (res != ERROR_NO_MORE_ITEMS)
1258 token[MaxTextExtent],
1262 value_name_length = sizeof(value_name) - 1;
1263 value_data_size = sizeof(value_data) - 1;
1264 res = RegEnumValueA ( reg_key, registry_index, value_name,
1265 &value_name_length, 0, &type, (BYTE*)value_data, &value_data_size);
1267 if (res != ERROR_SUCCESS)
1269 if ( (pos = strstr(value_name, " (TrueType)")) == (char*) NULL )
1271 *pos='\0'; /* Remove (TrueType) from string */
1273 type_info=(TypeInfo *) AcquireMagickMemory(sizeof(*type_info));
1274 if (type_info == (TypeInfo *) NULL)
1275 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1276 (void) ResetMagickMemory(type_info,0,sizeof(TypeInfo));
1278 type_info->path=ConstantString("Windows Fonts");
1279 type_info->signature=MagickSignature;
1282 (void) CopyMagickString(buffer,value_name,MaxTextExtent);
1283 for(pos = buffer; *pos != 0 ; pos++)
1286 type_info->name=ConstantString(buffer);
1289 type_info->description=ConstantString(value_name);
1292 type_info->format=ConstantString("truetype");
1295 if (strchr(value_data,'\\') != (char *) NULL)
1296 (void) CopyMagickString(buffer,value_data,MaxTextExtent);
1299 (void) CopyMagickString(buffer,font_root,MaxTextExtent);
1300 (void) ConcatenateMagickString(buffer,value_data,MaxTextExtent);
1303 LocaleLower(buffer);
1304 type_info->glyphs=ConstantString(buffer);
1306 type_info->stretch=NormalStretch;
1307 type_info->style=NormalStyle;
1308 type_info->weight=400;
1310 /* Some fonts are known to require special encodings */
1311 if ( (LocaleCompare(type_info->name, "Symbol") == 0 ) ||
1312 (LocaleCompare(type_info->name, "Wingdings") == 0 ) ||
1313 (LocaleCompare(type_info->name, "Wingdings-2") == 0 ) ||
1314 (LocaleCompare(type_info->name, "Wingdings-3") == 0 ) )
1315 type_info->encoding=ConstantString("AppleRoman");
1317 family_extent=value_name;
1319 for (q=value_name; *q != '\0'; )
1321 GetMagickToken(q,(const char **) &q,token);
1325 if (LocaleCompare(token,"Italic") == 0)
1327 type_info->style=ItalicStyle;
1330 else if (LocaleCompare(token,"Oblique") == 0)
1332 type_info->style=ObliqueStyle;
1335 else if (LocaleCompare(token,"Bold") == 0)
1337 type_info->weight=700;
1340 else if (LocaleCompare(token,"Thin") == 0)
1342 type_info->weight=100;
1345 else if ( (LocaleCompare(token,"ExtraLight") == 0) ||
1346 (LocaleCompare(token,"UltraLight") == 0) )
1348 type_info->weight=200;
1351 else if (LocaleCompare(token,"Light") == 0)
1353 type_info->weight=300;
1356 else if ( (LocaleCompare(token,"Normal") == 0) ||
1357 (LocaleCompare(token,"Regular") == 0) )
1359 type_info->weight=400;
1362 else if (LocaleCompare(token,"Medium") == 0)
1364 type_info->weight=500;
1367 else if ( (LocaleCompare(token,"SemiBold") == 0) ||
1368 (LocaleCompare(token,"DemiBold") == 0) )
1370 type_info->weight=600;
1373 else if ( (LocaleCompare(token,"ExtraBold") == 0) ||
1374 (LocaleCompare(token,"UltraBold") == 0) )
1376 type_info->weight=800;
1379 else if ( (LocaleCompare(token,"Heavy") == 0) ||
1380 (LocaleCompare(token,"Black") == 0) )
1382 type_info->weight=900;
1385 else if (LocaleCompare(token,"Condensed") == 0)
1387 type_info->stretch = CondensedStretch;
1390 else if (LocaleCompare(token,"Expanded") == 0)
1392 type_info->stretch = ExpandedStretch;
1395 else if (LocaleCompare(token,"ExtraCondensed") == 0)
1397 type_info->stretch = ExtraCondensedStretch;
1400 else if (LocaleCompare(token,"ExtraExpanded") == 0)
1402 type_info->stretch = ExtraExpandedStretch;
1405 else if (LocaleCompare(token,"SemiCondensed") == 0)
1407 type_info->stretch = SemiCondensedStretch;
1410 else if (LocaleCompare(token,"SemiExpanded") == 0)
1412 type_info->stretch = SemiExpandedStretch;
1415 else if (LocaleCompare(token,"UltraCondensed") == 0)
1417 type_info->stretch = UltraCondensedStretch;
1420 else if (LocaleCompare(token,"UltraExpanded") == 0)
1422 type_info->stretch = UltraExpandedStretch;
1431 (void) CopyMagickString(buffer,value_name,family_extent-value_name+1);
1432 StripString(buffer);
1433 type_info->family=ConstantString(buffer);
1436 status=AddValueToSplayTree(type_list,ConstantString(type_info->name),
1438 if (status == MagickFalse)
1439 (void) ThrowMagickException(exception,GetMagickModule(),
1440 ResourceLimitError,"MemoryAllocationFailed","`%s'",type_info->name);
1443 RegCloseKey ( reg_key );
1448 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1452 % N T G h o s t s c r i p t D L L %
1456 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1458 % NTGhostscriptDLL() returns the path to the most recent Ghostscript version
1459 % DLL. The method returns TRUE on success otherwise FALSE.
1461 % The format of the NTGhostscriptDLL method is:
1463 % int NTGhostscriptDLL(char *path,int length)
1465 % A description of each parameter follows:
1467 % o path: return the Ghostscript DLL path here.
1469 % o length: the buffer length.
1473 static int NTGetRegistryValue(HKEY root,const char *key,const char *name,
1474 char *value,int *length)
1491 Get a registry value: key = root\\key, named value = name.
1493 if (RegOpenKeyExA(root,key,0,KEY_READ,&hkey) != ERROR_SUCCESS)
1494 return(1); /* no match */
1498 if (p == (BYTE *) NULL)
1499 p=(&byte); /* ERROR_MORE_DATA only if value is NULL */
1500 status=RegQueryValueExA(hkey,(char *) name,0,&type,p,&extent);
1502 if (status == ERROR_SUCCESS)
1505 return(0); /* return the match */
1507 if (status == ERROR_MORE_DATA)
1510 return(-1); /* buffer not large enough */
1512 return(1); /* not found */
1515 static int NTLocateGhostscript(const char **product_family,int *major_version,
1530 "Aladdin Ghostscript"
1534 Find the most recent version of Ghostscript.
1537 *product_family=NULL;
1539 *minor_version=49; /* min version of Ghostscript is 5.50 */
1540 for (i=0; i < (ssize_t) (sizeof(products)/sizeof(products[0])); i++)
1552 (void) FormatLocaleString(key,MaxTextExtent,"SOFTWARE\\%s",products[i]);
1553 root=HKEY_LOCAL_MACHINE;
1555 if (RegOpenKeyExA(root,key,0,mode,&hkey) == ERROR_SUCCESS)
1564 Now enumerate the keys.
1566 extent=sizeof(key)/sizeof(char);
1567 for (j=0; RegEnumKeyA(hkey,j,key,extent) == ERROR_SUCCESS; j++)
1575 if (sscanf(key,"%d.%d",&major,&minor) != 2)
1577 if ((major > *major_version) || ((major == *major_version) &&
1578 (minor > *minor_version)))
1580 *product_family=products[i];
1581 *major_version=major;
1582 *minor_version=minor;
1586 (void) RegCloseKey(hkey);
1589 if (status == FALSE)
1594 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"Ghostscript (%s) "
1595 "version %d.%02d",*product_family,*major_version,*minor_version);
1599 static int NTGhostscriptGetString(const char *name,char *value,
1600 const size_t length)
1610 *product_family = (const char *) NULL;
1626 { HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
1627 { HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" }
1631 Get a string from the installed Ghostscript.
1634 if (product_family == NULL)
1635 (void) NTLocateGhostscript(&product_family,&major_version,&minor_version);
1636 if (product_family == NULL)
1638 (void) FormatLocaleString(key,MaxTextExtent,"SOFTWARE\\%s\\%d.%02d",
1639 product_family,major_version,minor_version);
1640 for (i=0; i < (ssize_t) (sizeof(hkeys)/sizeof(hkeys[0])); i++)
1642 extent=(int) length;
1643 if (NTGetRegistryValue(hkeys[i].hkey,key,name,value,&extent) == 0)
1645 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1646 "registry: \"%s\\%s\\%s\"=\"%s\"",hkeys[i].name,key,name,value);
1649 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1650 "registry: \"%s\\%s\\%s\" (failed)",hkeys[i].name,key,name);
1655 MagickPrivate int NTGhostscriptDLL(char *path,int length)
1658 dll[MaxTextExtent] = { "" };
1661 if ((*dll == '\0') &&
1662 (NTGhostscriptGetString("GS_DLL",dll,sizeof(dll)) == FALSE))
1664 (void) CopyMagickString(path,dll,length);
1669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1673 % N T G h o s t s c r i p t D L L V e c t o r s %
1677 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1679 % NTGhostscriptDLLVectors() returns a GhostInfo structure that includes
1680 % function vectors to invoke Ghostscript DLL functions. A null pointer is
1681 % returned if there is an error when loading the DLL or retrieving the
1684 % The format of the NTGhostscriptDLLVectors method is:
1686 % const GhostInfo *NTGhostscriptDLLVectors(void)
1689 MagickExport const GhostInfo *NTGhostscriptDLLVectors(void)
1691 if (NTGhostscriptLoadDLL() == FALSE)
1692 return((GhostInfo *) NULL);
1693 return(&ghost_info);
1697 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1701 % N T G h o s t s c r i p t E X E %
1705 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1707 % NTGhostscriptEXE() obtains the path to the latest Ghostscript executable.
1708 % The method returns FALSE if a full path value is not obtained and returns
1709 % a default path of gswin32c.exe.
1711 % The format of the NTGhostscriptEXE method is:
1713 % int NTGhostscriptEXE(char *path,int length)
1715 % A description of each parameter follows:
1717 % o path: return the Ghostscript executable path here.
1719 % o length: length of buffer.
1722 MagickPrivate int NTGhostscriptEXE(char *path,int length)
1728 program[MaxTextExtent] = { "" };
1730 (void) CopyMagickString(path,"gswin32c.exe",length);
1731 if ((*program == '\0') &&
1732 (NTGhostscriptGetString("GS_DLL",program,sizeof(program)) == FALSE))
1734 p=strrchr(program,'\\');
1735 if (p != (char *) NULL)
1739 (void) ConcatenateMagickString(program,"gswin32c.exe",sizeof(program));
1741 (void) CopyMagickString(path,program,length);
1746 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1750 % N T G h o s t s c r i p t F o n t s %
1754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1756 % NTGhostscriptFonts() obtains the path to the Ghostscript fonts. The method
1757 % returns FALSE if it cannot determine the font path.
1759 % The format of the NTGhostscriptFonts method is:
1761 % int NTGhostscriptFonts(char *path, int length)
1763 % A description of each parameter follows:
1765 % o path: return the font path here.
1767 % o length: length of the path buffer.
1770 MagickPrivate int NTGhostscriptFonts(char *path,int length)
1773 buffer[MaxTextExtent],
1774 filename[MaxTextExtent];
1781 if (NTGhostscriptGetString("GS_LIB",buffer,MaxTextExtent) == FALSE)
1783 for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
1785 (void) CopyMagickString(path,p+1,length+1);
1786 q=strchr(path,DirectoryListSeparator);
1787 if (q != (char *) NULL)
1789 (void) FormatLocaleString(filename,MaxTextExtent,"%s%sfonts.dir",path,
1790 DirectorySeparator);
1791 if (IsPathAccessible(filename) != MagickFalse)
1798 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1802 % N T G h o s t s c r i p t L o a d D L L %
1806 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1808 % NTGhostscriptLoadDLL() attempts to load the Ghostscript DLL and returns
1809 % TRUE if it succeeds.
1811 % The format of the NTGhostscriptLoadDLL method is:
1813 % int NTGhostscriptLoadDLL(void)
1816 MagickPrivate int NTGhostscriptLoadDLL(void)
1819 path[MaxTextExtent];
1821 if (ghost_handle != (void *) NULL)
1823 if (NTGhostscriptDLL(path,sizeof(path)) == FALSE)
1825 ghost_handle=lt_dlopen(path);
1826 if (ghost_handle == (void *) NULL)
1828 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1829 ghost_info.exit=(int (MagickDLLCall *)(gs_main_instance*))
1830 lt_dlsym(ghost_handle,"gsapi_exit");
1831 ghost_info.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,int,
1832 char **)) (lt_dlsym(ghost_handle,"gsapi_init_with_args"));
1833 ghost_info.new_instance=(int (MagickDLLCall *)(gs_main_instance **,void *)) (
1834 lt_dlsym(ghost_handle,"gsapi_new_instance"));
1835 ghost_info.run_string=(int (MagickDLLCall *)(gs_main_instance *,const char *,
1836 int,int *)) (lt_dlsym(ghost_handle,"gsapi_run_string"));
1837 ghost_info.delete_instance=(void (MagickDLLCall *) (gs_main_instance *)) (
1838 lt_dlsym(ghost_handle,"gsapi_delete_instance"));
1839 if ((ghost_info.exit == NULL) || (ghost_info.init_with_args == NULL) ||
1840 (ghost_info.new_instance == NULL) || (ghost_info.run_string == NULL) ||
1841 (ghost_info.delete_instance == NULL))
1847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1851 % N T G h o s t s c r i p t U n L o a d D L L %
1855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1857 % NTGhostscriptUnLoadDLL() unloads the Ghostscript DLL and returns TRUE if
1860 % The format of the NTGhostscriptUnLoadDLL method is:
1862 % int NTGhostscriptUnLoadDLL(void)
1865 MagickExport int NTGhostscriptUnLoadDLL(void)
1870 if (ghost_handle == (void *) NULL)
1872 status=lt_dlclose(ghost_handle);
1873 ghost_handle=(void *) NULL;
1874 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1879 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1883 % N T I n i t i a l i z e L i b r a r y %
1887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1889 % NTInitializeLibrary() initializes the dynamic module loading subsystem.
1891 % The format of the NTInitializeLibrary method is:
1893 % int NTInitializeLibrary(void)
1896 MagickPrivate int NTInitializeLibrary(void)
1902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1906 % N T I s M a g i c k C o n f l i c t %
1910 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1912 % NTIsMagickConflict() returns true if the image format conflicts with a
1913 % logical drive (.e.g. X:).
1915 % The format of the IsMagickConflict method is:
1917 % MagickBooleanType IsMagickConflict(const char *magick)
1919 % A description of each parameter follows:
1921 % o magick: Specifies the image format.
1924 MagickPrivate MagickBooleanType NTIsMagickConflict(const char *magick)
1929 assert(magick != (char *) NULL);
1930 if (strlen(magick) > 1)
1931 return(MagickFalse);
1932 status=(GetLogicalDrives() & (1 << ((toupper((int) (*magick)))-'A'))) != 0 ?
1933 MagickTrue : MagickFalse;
1938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1942 + N T M a p M e m o r y %
1946 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1948 % Mmap() emulates the Unix method of the same name.
1950 % The format of the NTMapMemory method is:
1952 % MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
1953 % int access,int file,MagickOffsetType offset)
1956 MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
1957 int flags,int file,MagickOffsetType offset)
1976 file_handle=INVALID_HANDLE_VALUE;
1977 low_length=(DWORD) (length & 0xFFFFFFFFUL);
1978 high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
1979 map_handle=INVALID_HANDLE_VALUE;
1981 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
1982 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
1984 if (protection & PROT_WRITE)
1986 access_mode=FILE_MAP_WRITE;
1987 if (!(flags & MAP_PRIVATE))
1988 protection_mode=PAGE_READWRITE;
1991 access_mode=FILE_MAP_COPY;
1992 protection_mode=PAGE_WRITECOPY;
1996 if (protection & PROT_READ)
1998 access_mode=FILE_MAP_READ;
1999 protection_mode=PAGE_READONLY;
2001 if ((file == -1) && (flags & MAP_ANONYMOUS))
2002 file_handle=INVALID_HANDLE_VALUE;
2004 file_handle=(HANDLE) _get_osfhandle(file);
2005 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
2009 map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
2011 CloseHandle(map_handle);
2013 if (map == (void *) NULL)
2014 return((void *) MAP_FAILED);
2015 return((void *) ((char *) map));
2019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2023 % N T O p e n D i r e c t o r y %
2027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2029 % NTOpenDirectory() opens the directory named by filename and associates a
2030 % directory stream with it.
2032 % The format of the NTOpenDirectory method is:
2034 % DIR *NTOpenDirectory(const char *path)
2036 % A description of each parameter follows:
2038 % o entry: Specifies a pointer to a DIR structure.
2041 MagickPrivate DIR *NTOpenDirectory(const char *path)
2044 file_specification[MaxTextExtent];
2052 assert(path != (const char *) NULL);
2053 length=CopyMagickString(file_specification,path,MaxTextExtent);
2054 if (length >= (MaxTextExtent-1))
2055 return((DIR *) NULL);
2056 length=ConcatenateMagickString(file_specification,DirectorySeparator,
2058 if (length >= (MaxTextExtent-1))
2059 return((DIR *) NULL);
2060 entry=(DIR *) AcquireMagickMemory(sizeof(DIR));
2061 if (entry != (DIR *) NULL)
2063 entry->firsttime=TRUE;
2064 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
2066 if (entry->hSearch == INVALID_HANDLE_VALUE)
2068 length=ConcatenateMagickString(file_specification,"\\*.*",MaxTextExtent);
2069 if (length >= (MaxTextExtent-1))
2071 entry=(DIR *) RelinquishMagickMemory(entry);
2072 return((DIR *) NULL);
2074 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
2075 if (entry->hSearch == INVALID_HANDLE_VALUE)
2077 entry=(DIR *) RelinquishMagickMemory(entry);
2078 return((DIR *) NULL);
2085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2089 % N T O p e n L i b r a r y %
2093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2095 % NTOpenLibrary() loads a dynamic module into memory and returns a handle that
2096 % can be used to access the various procedures in the module.
2098 % The format of the NTOpenLibrary method is:
2100 % void *NTOpenLibrary(const char *filename)
2102 % A description of each parameter follows:
2104 % o path: Specifies a pointer to string representing dynamic module that
2109 static const char *GetSearchPath( void )
2111 #if defined(MAGICKCORE_LTDL_DELEGATE)
2112 return(lt_dlgetsearchpath());
2114 return(lt_slsearchpath);
2118 MagickPrivate void *NTOpenLibrary(const char *filename)
2120 #define MaxPathElements 31
2123 buffer[MaxTextExtent];
2141 mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
2142 handle=(void *) LoadLibraryEx(filename,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
2143 if ((handle != (void *) NULL) || (GetSearchPath() == (char *) NULL))
2148 p=(char *) GetSearchPath();
2150 while (index < MaxPathElements)
2152 q=strchr(p,DirectoryListSeparator);
2153 if (q == (char *) NULL)
2155 (void) CopyMagickString(buffer,p,MaxTextExtent);
2156 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
2157 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
2158 handle=(void *) LoadLibraryEx(buffer,NULL,
2159 LOAD_WITH_ALTERED_SEARCH_PATH);
2163 (void) CopyMagickString(buffer,p,i+1);
2164 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
2165 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
2166 handle=(void *) LoadLibraryEx(buffer,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
2167 if (handle != (void *) NULL)
2176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2180 % N T R e a d D i r e c t o r y %
2184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2186 % NTReadDirectory() returns a pointer to a structure representing the
2187 % directory entry at the current position in the directory stream to which
2190 % The format of the NTReadDirectory
2192 % NTReadDirectory(entry)
2194 % A description of each parameter follows:
2196 % o entry: Specifies a pointer to a DIR structure.
2199 MagickPrivate struct dirent *NTReadDirectory(DIR *entry)
2207 if (entry == (DIR *) NULL)
2208 return((struct dirent *) NULL);
2209 if (!entry->firsttime)
2211 status=FindNextFile(entry->hSearch,&entry->Win32FindData);
2213 return((struct dirent *) NULL);
2215 length=CopyMagickString(entry->file_info.d_name,
2216 entry->Win32FindData.cFileName,sizeof(entry->file_info.d_name));
2217 if (length >= sizeof(entry->file_info.d_name))
2218 return((struct dirent *) NULL);
2219 entry->firsttime=FALSE;
2220 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
2221 return(&entry->file_info);
2225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2229 % N T R e g i s t r y K e y L o o k u p %
2233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2235 % NTRegistryKeyLookup() returns ImageMagick installation path settings
2236 % stored in the Windows Registry. Path settings are specific to the
2237 % installed ImageMagick version so that multiple Image Magick installations
2240 % Values are stored in the registry under a base path path similar to
2241 % "HKEY_LOCAL_MACHINE/SOFTWARE\ImageMagick\5.5.7\Q:16". The provided subkey
2242 % is appended to this base path to form the full key.
2244 % The format of the NTRegistryKeyLookup method is:
2246 % unsigned char *NTRegistryKeyLookup(const char *subkey)
2248 % A description of each parameter follows:
2250 % o subkey: Specifies a string that identifies the registry object.
2251 % Currently supported sub-keys include: "BinPath", "ConfigurePath",
2252 % "LibPath", "CoderModulesPath", "FilterModulesPath", "SharePath".
2255 MagickPrivate unsigned char *NTRegistryKeyLookup(const char *subkey)
2258 package_key[MaxTextExtent];
2276 (void) FormatLocaleString(package_key,MaxTextExtent,"SOFTWARE\\%s\\%s\\Q:%d",
2277 MagickPackageName,MagickLibVersionText,MAGICKCORE_QUANTUM_DEPTH);
2278 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",package_key);
2279 registry_key=(HKEY) INVALID_HANDLE_VALUE;
2280 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,package_key,0,KEY_READ,®istry_key);
2281 if (status != ERROR_SUCCESS)
2283 registry_key=(HKEY) INVALID_HANDLE_VALUE;
2284 return((unsigned char *) NULL);
2290 value=(unsigned char *) AcquireQuantumMemory(size,sizeof(*value));
2291 if (value == (unsigned char *) NULL)
2293 RegCloseKey(registry_key);
2294 return((unsigned char *) NULL);
2296 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",subkey);
2297 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
2298 if ((status == ERROR_MORE_DATA) && (type == REG_SZ))
2300 value=(unsigned char *) ResizeQuantumMemory(value,size,sizeof(*value));
2301 if (value == (BYTE *) NULL)
2303 RegCloseKey(registry_key);
2304 return((unsigned char *) NULL);
2306 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
2308 RegCloseKey(registry_key);
2309 if ((type != REG_SZ) || (status != ERROR_SUCCESS))
2310 value=(unsigned char *) RelinquishMagickMemory(value);
2311 return((unsigned char *) value);
2315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2319 % N T R e p o r t E v e n t %
2323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2325 % NTReportEvent() reports an event.
2327 % The format of the NTReportEvent method is:
2329 % MagickBooleanType NTReportEvent(const char *event,
2330 % const MagickBooleanType error)
2332 % A description of each parameter follows:
2334 % o event: the event.
2336 % o error: MagickTrue the event is an error.
2339 MagickPrivate MagickBooleanType NTReportEvent(const char *event,
2340 const MagickBooleanType error)
2351 handle=RegisterEventSource(NULL,MAGICKCORE_PACKAGE_NAME);
2353 return(MagickFalse);
2355 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
2356 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
2357 DeregisterEventSource(handle);
2362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2366 % N T R e s o u r c e T o B l o b %
2370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2372 % NTResourceToBlob() returns a blob containing the contents of the resource
2373 % in the current executable specified by the id parameter. This currently
2374 % used to retrieve MGK files tha have been embedded into the various command
2377 % The format of the NTResourceToBlob method is:
2379 % unsigned char *NTResourceToBlob(const char *id)
2381 % A description of each parameter follows:
2383 % o id: Specifies a string that identifies the resource.
2386 MagickPrivate unsigned char *NTResourceToBlob(const char *id)
2389 path[MaxTextExtent];
2407 assert(id != (const char *) NULL);
2408 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
2409 (void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",GetClientPath(),
2410 DirectorySeparator,GetClientName());
2411 if (IsPathAccessible(path) != MagickFalse)
2412 handle=GetModuleHandle(path);
2414 handle=GetModuleHandle(0);
2416 return((unsigned char *) NULL);
2417 resource=FindResource(handle,id,"IMAGEMAGICK");
2419 return((unsigned char *) NULL);
2420 global=LoadResource(handle,resource);
2422 return((unsigned char *) NULL);
2423 length=SizeofResource(handle,resource);
2424 value=(unsigned char *) LockResource(global);
2427 FreeResource(global);
2428 return((unsigned char *) NULL);
2430 blob=(unsigned char *) AcquireQuantumMemory(length+MaxTextExtent,
2432 if (blob != (unsigned char *) NULL)
2434 (void) CopyMagickMemory(blob,value,length);
2437 UnlockResource(global);
2438 FreeResource(global);
2443 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2447 % N T S e e k D i r e c t o r y %
2451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2453 % NTSeekDirectory() sets the position of the next NTReadDirectory() operation
2454 % on the directory stream.
2456 % The format of the NTSeekDirectory method is:
2458 % void NTSeekDirectory(DIR *entry,ssize_t position)
2460 % A description of each parameter follows:
2462 % o entry: Specifies a pointer to a DIR structure.
2464 % o position: specifies the position associated with the directory
2468 MagickPrivate void NTSeekDirectory(DIR *entry,ssize_t position)
2471 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2472 assert(entry != (DIR *) NULL);
2476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2480 % N T S e t S e a r c h P a t h %
2484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2486 % NTSetSearchPath() sets the current locations that the subsystem should
2487 % look at to find dynamically loadable modules.
2489 % The format of the NTSetSearchPath method is:
2491 % int NTSetSearchPath(const char *path)
2493 % A description of each parameter follows:
2495 % o path: Specifies a pointer to string representing the search path
2496 % for DLL's that can be dynamically loaded.
2499 MagickPrivate int NTSetSearchPath(const char *path)
2501 #if defined(MAGICKCORE_LTDL_DELEGATE)
2502 lt_dlsetsearchpath(path);
2504 if (lt_slsearchpath != (char *) NULL)
2505 lt_slsearchpath=DestroyString(lt_slsearchpath);
2506 if (path != (char *) NULL)
2507 lt_slsearchpath=AcquireString(path);
2513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2517 + N T S y n c M e m o r y %
2521 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2523 % NTSyncMemory() emulates the Unix method of the same name.
2525 % The format of the NTSyncMemory method is:
2527 % int NTSyncMemory(void *address,size_t length,int flags)
2529 % A description of each parameter follows:
2531 % o address: the address of the binary large object.
2533 % o length: the length of the binary large object.
2535 % o flags: Option flags (ignored for Windows).
2538 MagickPrivate int NTSyncMemory(void *address,size_t length,int flags)
2541 if (FlushViewOfFile(address,length) == MagickFalse)
2547 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2551 % N T S y s t e m C o m m a n d %
2555 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2557 % NTSystemCommand() executes the specified command and waits until it
2558 % terminates. The returned value is the exit status of the command.
2560 % The format of the NTSystemCommand method is:
2562 % int NTSystemCommand(MagickFalse,const char *command)
2564 % A description of each parameter follows:
2566 % o command: This string is the command to execute.
2569 MagickPrivate int NTSystemCommand(const char *command)
2572 local_command[MaxTextExtent];
2589 if (command == (char *) NULL)
2591 GetStartupInfo(&startup_info);
2592 startup_info.dwFlags=STARTF_USESHOWWINDOW;
2593 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
2594 (void) CopyMagickString(local_command,command,MaxTextExtent);
2595 background_process=command[strlen(command)-1] == '&' ? MagickTrue :
2597 if (background_process)
2598 local_command[strlen(command)-1]='\0';
2599 if (command[strlen(command)-1] == '|')
2600 local_command[strlen(command)-1]='\0';
2602 startup_info.wShowWindow=SW_SHOWDEFAULT;
2603 status=CreateProcess((LPCTSTR) NULL,local_command,
2604 (LPSECURITY_ATTRIBUTES) NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) FALSE,
2605 (DWORD) NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
2609 if (background_process)
2610 return(status == 0);
2611 status=WaitForSingleObject(process_info.hProcess,INFINITE);
2612 if (status != WAIT_OBJECT_0)
2614 status=GetExitCodeProcess(process_info.hProcess,&child_status);
2617 CloseHandle(process_info.hProcess);
2618 CloseHandle(process_info.hThread);
2619 return((int) child_status);
2623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2627 % N T S y s t e m C o n i f i g u r a t i o n %
2631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2633 % NTSystemConfiguration() provides a way for the application to determine
2634 % values for system limits or options at runtime.
2636 % The format of the exit method is:
2638 % ssize_t NTSystemConfiguration(int name)
2640 % A description of each parameter follows:
2642 % o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
2645 MagickPrivate ssize_t NTSystemConfiguration(int name)
2654 GetSystemInfo(&system_info);
2655 return(system_info.dwPageSize);
2657 case _SC_PHYS_PAGES:
2671 handle=GetModuleHandle("kernel32.dll");
2672 if (handle == (HMODULE) NULL)
2674 GetSystemInfo(&system_info);
2675 module=(LPFNDLLFUNC2) NTGetLibrarySymbol(handle,"GlobalMemoryStatusEx");
2676 if (module == (LPFNDLLFUNC2) NULL)
2681 GlobalMemoryStatus(&status);
2682 return((ssize_t) status.dwTotalPhys/system_info.dwPageSize);
2684 status.dwLength=sizeof(status);
2685 if (module(&status) == 0)
2687 return((ssize_t) status.ullTotalPhys/system_info.dwPageSize);
2698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2702 % N T T e l l D i r e c t o r y %
2706 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2708 % NTTellDirectory() returns the current location associated with the named
2711 % The format of the NTTellDirectory method is:
2713 % ssize_t NTTellDirectory(DIR *entry)
2715 % A description of each parameter follows:
2717 % o entry: Specifies a pointer to a DIR structure.
2720 MagickPrivate ssize_t NTTellDirectory(DIR *entry)
2722 assert(entry != (DIR *) NULL);
2727 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2731 % N T T r u n c a t e F i l e %
2735 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2737 % NTTruncateFile() truncates a file to a specified length.
2739 % The format of the NTTruncateFile method is:
2741 % int NTTruncateFile(int file,off_t length)
2743 % A description of each parameter follows:
2747 % o length: the file length.
2750 MagickPrivate int NTTruncateFile(int file,off_t length)
2760 file_handle=_get_osfhandle(file);
2761 if (file_handle == -1L)
2763 low=(long) (length & 0xffffffffUL);
2764 high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
2765 file_pointer=SetFilePointer((HANDLE) file_handle,low,&high,FILE_BEGIN);
2766 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
2768 if (SetEndOfFile((HANDLE) file_handle) == 0)
2774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2778 + N T U n m a p M e m o r y %
2782 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2784 % NTUnmapMemory() emulates the Unix munmap method.
2786 % The format of the NTUnmapMemory method is:
2788 % int NTUnmapMemory(void *map,size_t length)
2790 % A description of each parameter follows:
2792 % o map: the address of the binary large object.
2794 % o length: the length of the binary large object.
2797 MagickPrivate int NTUnmapMemory(void *map,size_t length)
2800 if (UnmapViewOfFile(map) == 0)
2806 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2810 % N T U s e r T i m e %
2814 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2816 % NTUserTime() returns the total time the process has been scheduled (e.g.
2817 % seconds) since the last call to StartTimer().
2819 % The format of the UserTime method is:
2821 % double NTUserTime(void)
2824 MagickPrivate double NTUserTime(void)
2854 OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
2855 GetVersionEx(&OsVersionInfo);
2856 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
2857 return(NTElapsedTime());
2858 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
2859 &kernel_time.filetime,&user_time.filetime);
2862 return((double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
2866 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2870 % N T W a r n i n g H a n d l e r %
2874 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2876 % NTWarningHandler() displays a warning reason.
2878 % The format of the NTWarningHandler method is:
2880 % void NTWarningHandler(const ExceptionType severity,const char *reason,
2881 % const char *description)
2883 % A description of each parameter follows:
2885 % o severity: Specifies the numeric warning category.
2887 % o reason: Specifies the reason to display before terminating the
2890 % o description: Specifies any description to the reason.
2893 MagickExport void NTWarningHandler(const ExceptionType severity,
2894 const char *reason,const char *description)
2897 buffer[2*MaxTextExtent];
2900 if (reason == (char *) NULL)
2902 if (description == (char *) NULL)
2903 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s.\n",GetClientName(),
2906 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s (%s).\n",
2907 GetClientName(),reason,description);
2908 (void) MessageBox(NULL,buffer,"ImageMagick Warning",MB_OK | MB_TASKMODAL |
2909 MB_SETFOREGROUND | MB_ICONINFORMATION);