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,ExceptionInfo *exception)
502 % A description of each parameter follows:
504 % o image: the image to convert.
506 % o exception: return any errors or warnings in this structure.
509 MagickExport void *ImageToHBITMAP(Image *image,ExceptionInfo *exception)
523 register const Quantum
538 (void) ResetMagickMemory(&bitmap,0,sizeof(bitmap));
540 bitmap.bmWidth=(LONG) image->columns;
541 bitmap.bmHeight=(LONG) image->rows;
542 bitmap.bmWidthBytes=4*bitmap.bmWidth;
544 bitmap.bmBitsPixel=32;
546 length=bitmap.bmWidthBytes*bitmap.bmHeight;
547 bitmap_bitsH=(HANDLE) GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,length);
548 if (bitmap_bitsH == NULL)
553 message=GetExceptionMessage(errno);
554 (void) ThrowMagickException(exception,GetMagickModule(),
555 ResourceLimitError,"MemoryAllocationFailed","`%s'",message);
556 message=DestroyString(message);
559 bitmap_bits=(RGBQUAD *) GlobalLock((HGLOBAL) bitmap_bitsH);
561 if (bitmap.bmBits == NULL)
562 bitmap.bmBits=bitmap_bits;
563 (void) TransformImageColorspace(image,RGBColorspace,exception);
564 for (y=0; y < (ssize_t) image->rows; y++)
566 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
567 if (p == (const Quantum *) NULL)
569 for (x=0; x < (ssize_t) image->columns; x++)
571 q->rgbRed=ScaleQuantumToChar(GetPixelRed(image,p));
572 q->rgbGreen=ScaleQuantumToChar(GetPixelGreen(image,p));
573 q->rgbBlue=ScaleQuantumToChar(GetPixelBlue(image,p));
575 p+=GetPixelChannels(image);
579 bitmap.bmBits=bitmap_bits;
580 bitmapH=CreateBitmapIndirect(&bitmap);
586 message=GetExceptionMessage(errno);
587 (void) ThrowMagickException(exception,GetMagickModule(),
588 ResourceLimitError,"MemoryAllocationFailed","`%s'",message);
589 message=DestroyString(message);
591 GlobalUnlock((HGLOBAL) bitmap_bitsH);
592 GlobalFree((HGLOBAL) bitmap_bitsH);
593 return((void *) bitmapH);
597 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601 % I s W i n d o w s 9 5 %
605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
607 % IsWindows95() returns true if the system is Windows 95.
609 % The format of the IsWindows95 method is:
614 MagickPrivate int IsWindows95(void)
619 version_info.dwOSVersionInfoSize=sizeof(version_info);
620 if (GetVersionEx(&version_info) &&
621 (version_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS))
627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
631 % N T A r g v T o U T F 8 %
635 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
637 % NTArgvToUTF8() converts the wide command line arguments to UTF-8 to ensure
638 % compatibility with Linux.
640 % The format of the NTArgvToUTF8 method is:
642 % char **NTArgvToUTF8(const int argc,wchar_t **argv)
644 % A description of each parameter follows:
646 % o argc: the number of command line arguments.
648 % o argv: the wide-character command line arguments.
651 MagickExport char **NTArgvToUTF8(const int argc,wchar_t **argv)
659 utf8=(char **) AcquireQuantumMemory(argc,sizeof(*utf8));
660 if (utf8 == (char **) NULL)
661 ThrowFatalException(ResourceLimitFatalError,"UnableToConvertStringToARGV");
662 for (i=0; i < (ssize_t) argc; i++)
667 count=WideCharToMultiByte(CP_UTF8,0,argv[i],-1,NULL,0,NULL,NULL);
670 utf8[i]=(char *) AcquireQuantumMemory(count+1,sizeof(**utf8));
671 if (utf8[i] == (char *) NULL)
673 for (i--; i >= 0; i--)
674 utf8[i]=DestroyString(utf8[i]);
675 utf8=(char **) RelinquishMagickMemory(utf8);
676 ThrowFatalException(ResourceLimitFatalError,
677 "UnableToConvertStringToARGV");
679 count=WideCharToMultiByte(CP_UTF8,0,argv[i],-1,utf8[i],count,NULL,NULL);
686 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
690 % N T C l o s e D i r e c t o r y %
694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
696 % NTCloseDirectory() closes the named directory stream and frees the DIR
699 % The format of the NTCloseDirectory method is:
701 % int NTCloseDirectory(DIR *entry)
703 % A description of each parameter follows:
705 % o entry: Specifies a pointer to a DIR structure.
708 MagickPrivate int NTCloseDirectory(DIR *entry)
710 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
711 assert(entry != (DIR *) NULL);
712 FindClose(entry->hSearch);
713 entry=(DIR *) RelinquishMagickMemory(entry);
718 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
722 % N T C l o s e L i b r a r y %
726 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
728 % NTCloseLibrary() unloads the module associated with the passed handle.
730 % The format of the NTCloseLibrary method is:
732 % void NTCloseLibrary(void *handle)
734 % A description of each parameter follows:
736 % o handle: Specifies a handle to a previously loaded dynamic module.
739 MagickPrivate int NTCloseLibrary(void *handle)
742 return(FreeLibrary((HINSTANCE) handle));
743 return(!(FreeLibrary((HINSTANCE) handle)));
747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
751 % N T C o n t r o l H a n d l e r %
755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
757 % NTControlHandler() registers a control handler that is activated when, for
758 % example, a ctrl-c is received.
760 % The format of the NTControlHandler method is:
762 % int NTControlHandler(void)
766 static BOOL ControlHandler(DWORD type)
769 AsynchronousResourceComponentTerminus();
773 MagickPrivate int NTControlHandler(void)
775 return(SetConsoleCtrlHandler((PHANDLER_ROUTINE) ControlHandler,TRUE));
779 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
783 % N T E l a p s e d T i m e %
787 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
789 % NTElapsedTime() returns the elapsed time (in seconds) since the last call to
792 % The format of the ElapsedTime method is:
794 % double NTElapsedTime(void)
797 MagickPrivate double NTElapsedTime(void)
811 GetSystemTime(&system_time);
812 SystemTimeToFileTime(&system_time,&elapsed_time.filetime);
813 return((double) 1.0e-7*elapsed_time.filetime64);
817 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
821 + N T E r r o r H a n d l e r %
825 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
827 % NTErrorHandler() displays an error reason and then terminates the program.
829 % The format of the NTErrorHandler method is:
831 % void NTErrorHandler(const ExceptionType severity,const char *reason,
832 % const char *description)
834 % A description of each parameter follows:
836 % o severity: Specifies the numeric error category.
838 % o reason: Specifies the reason to display before terminating the
841 % o description: Specifies any description to the reason.
844 MagickExport void NTErrorHandler(const ExceptionType severity,
845 const char *reason,const char *description)
848 buffer[3*MaxTextExtent],
852 if (reason == (char *) NULL)
854 MagickCoreTerminus();
857 message=GetExceptionMessage(errno);
858 if ((description != (char *) NULL) && errno)
859 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s (%s) [%s].\n",
860 GetClientName(),reason,description,message);
862 if (description != (char *) NULL)
863 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s (%s).\n",
864 GetClientName(),reason,description);
867 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s [%s].\n",
868 GetClientName(),reason,message);
870 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s.\n",
871 GetClientName(),reason);
872 message=DestroyString(message);
873 (void) MessageBox(NULL,buffer,"ImageMagick Exception",MB_OK | MB_TASKMODAL |
874 MB_SETFOREGROUND | MB_ICONEXCLAMATION);
875 MagickCoreTerminus();
880 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
884 % N T E x i t L i b r a r y %
888 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
890 % NTExitLibrary() exits the dynamic module loading subsystem.
892 % The format of the NTExitLibrary method is:
894 % int NTExitLibrary(void)
897 MagickPrivate int NTExitLibrary(void)
903 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
907 % N T G a t h e r R a n d o m D a t a %
911 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
913 % NTGatherRandomData() gathers random data and returns it.
915 % The format of the GatherRandomData method is:
917 % MagickBooleanType NTGatherRandomData(const size_t length,
918 % unsigned char *random)
920 % A description of each parameter follows:
922 % length: the length of random data buffer
924 % random: the random data is returned here.
927 MagickPrivate MagickBooleanType NTGatherRandomData(const size_t length,
928 unsigned char *random)
930 #if defined(MAGICKCORE_CIPHER_SUPPORT) && defined(_MSC_VER) && (_MSC_VER > 1200)
937 handle=(HCRYPTPROV) NULL;
938 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
939 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET));
941 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
942 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET));
945 status=CryptGenRandom(handle,(DWORD) length,random);
948 status=CryptReleaseContext(handle,0);
951 status=CryptReleaseContext(handle,0);
962 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
966 % N T G e t E x e c u t i o n P a t h %
970 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
972 % NTGetExecutionPath() returns the execution path of a program.
974 % The format of the GetExecutionPath method is:
976 % MagickBooleanType NTGetExecutionPath(char *path,const size_t extent)
978 % A description of each parameter follows:
980 % o path: the pathname of the executable that started the process.
982 % o extent: the maximum extent of the path.
985 MagickPrivate MagickBooleanType NTGetExecutionPath(char *path,
988 GetModuleFileName(0,path,(DWORD) extent);
993 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
997 % N T G e t L a s t E r r o r %
1001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1003 % NTGetLastError() returns the last error that occurred.
1005 % The format of the NTGetLastError method is:
1007 % char *NTGetLastError(void)
1010 MagickPrivate char *NTGetLastError(void)
1021 status=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
1022 FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),
1023 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR) &buffer,0,NULL);
1025 reason=AcquireString("An unknown error occurred");
1028 reason=AcquireString((const char *) buffer);
1035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1039 % N T G e t L i b r a r y E r r o r %
1043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1045 % Lt_dlerror() returns a pointer to a string describing the last error
1046 % associated with a lt_dl method. Note that this function is not thread
1047 % safe so it should only be used under the protection of a lock.
1049 % The format of the NTGetLibraryError method is:
1051 % const char *NTGetLibraryError(void)
1054 MagickPrivate const char *NTGetLibraryError(void)
1057 last_error[MaxTextExtent];
1063 error=NTGetLastError();
1065 (void) CopyMagickString(last_error,error,MaxTextExtent);
1066 error=DestroyString(error);
1071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1075 % N T G e t L i b r a r y S y m b o l %
1079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1081 % NTGetLibrarySymbol() retrieve the procedure address of the method
1082 % specified by the passed character string.
1084 % The format of the NTGetLibrarySymbol method is:
1086 % void *NTGetLibrarySymbol(void *handle,const char *name)
1088 % A description of each parameter follows:
1090 % o handle: Specifies a handle to the previously loaded dynamic module.
1092 % o name: Specifies the procedure entry point to be returned.
1095 void *NTGetLibrarySymbol(void *handle,const char *name)
1100 lpfnDllFunc1=(LPFNDLLFUNC1) GetProcAddress((HINSTANCE) handle,name);
1102 return((void *) NULL);
1103 return((void *) lpfnDllFunc1);
1107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1111 % N T G e t M o d u l e P a t h %
1115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1117 % NTGetModulePath() returns the path of the specified module.
1119 % The format of the GetModulePath method is:
1121 % MagickBooleanType NTGetModulePath(const char *module,char *path)
1123 % A description of each parameter follows:
1125 % modith: the module name.
1127 % path: the module path is returned here.
1130 MagickPrivate MagickBooleanType NTGetModulePath(const char *module,char *path)
1133 module_path[MaxTextExtent];
1142 handle=GetModuleHandle(module);
1143 if (handle == (HMODULE) NULL)
1144 return(MagickFalse);
1145 length=GetModuleFileName(handle,module_path,MaxTextExtent);
1147 GetPathComponent(module_path,HeadPath,path);
1152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1156 + N T G e t T y pe L i s t %
1160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1162 % NTLoadTypeLists() loads a Windows TrueType fonts.
1164 % The format of the NTLoadTypeLists method is:
1166 % MagickBooleanType NTLoadTypeLists(SplayTreeInfo *type_list)
1168 % A description of each parameter follows:
1170 % o type_list: A linked list of fonts.
1173 MagickPrivate MagickBooleanType NTLoadTypeLists(SplayTreeInfo *type_list,
1174 ExceptionInfo *exception)
1177 reg_key = (HKEY) INVALID_HANDLE_VALUE;
1187 buffer[MaxTextExtent],
1188 system_root[MaxTextExtent],
1189 font_root[MaxTextExtent];
1199 Try to find the right Windows*\CurrentVersion key, the SystemRoot and
1202 res = RegOpenKeyExA (HKEY_LOCAL_MACHINE,
1203 "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, ®_key);
1204 if (res == ERROR_SUCCESS) {
1205 system_root_length=sizeof(system_root)-1;
1206 res = RegQueryValueExA(reg_key,"SystemRoot",NULL, &type,
1207 (BYTE*) system_root, &system_root_length);
1209 if (res != ERROR_SUCCESS) {
1210 res = RegOpenKeyExA (HKEY_LOCAL_MACHINE,
1211 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 0, KEY_READ, ®_key);
1212 if (res == ERROR_SUCCESS) {
1213 system_root_length=sizeof(system_root)-1;
1214 res = RegQueryValueExA(reg_key,"SystemRoot",NULL, &type,
1215 (BYTE*)system_root, &system_root_length);
1218 if (res == ERROR_SUCCESS)
1219 res = RegOpenKeyExA (reg_key, "Fonts",0, KEY_READ, ®_key);
1220 if (res != ERROR_SUCCESS)
1221 return(MagickFalse);
1223 (void) CopyMagickString(buffer,system_root,MaxTextExtent);
1224 (void) ConcatenateMagickString(buffer,"\\fonts\\arial.ttf",MaxTextExtent);
1225 if (IsPathAccessible(buffer) != MagickFalse)
1227 (void) CopyMagickString(font_root,system_root,MaxTextExtent);
1228 (void) ConcatenateMagickString(font_root,"\\fonts\\",MaxTextExtent);
1232 (void) CopyMagickString(font_root,system_root,MaxTextExtent);
1233 (void) ConcatenateMagickString(font_root,"\\",MaxTextExtent);
1247 value_data[MaxTextExtent],
1248 value_name[MaxTextExtent];
1250 res = ERROR_SUCCESS;
1252 while (res != ERROR_NO_MORE_ITEMS)
1256 token[MaxTextExtent],
1260 value_name_length = sizeof(value_name) - 1;
1261 value_data_size = sizeof(value_data) - 1;
1262 res = RegEnumValueA ( reg_key, registry_index, value_name,
1263 &value_name_length, 0, &type, (BYTE*)value_data, &value_data_size);
1265 if (res != ERROR_SUCCESS)
1267 if ( (pos = strstr(value_name, " (TrueType)")) == (char*) NULL )
1269 *pos='\0'; /* Remove (TrueType) from string */
1271 type_info=(TypeInfo *) AcquireMagickMemory(sizeof(*type_info));
1272 if (type_info == (TypeInfo *) NULL)
1273 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1274 (void) ResetMagickMemory(type_info,0,sizeof(TypeInfo));
1276 type_info->path=ConstantString("Windows Fonts");
1277 type_info->signature=MagickSignature;
1280 (void) CopyMagickString(buffer,value_name,MaxTextExtent);
1281 for(pos = buffer; *pos != 0 ; pos++)
1284 type_info->name=ConstantString(buffer);
1287 type_info->description=ConstantString(value_name);
1290 type_info->format=ConstantString("truetype");
1293 if (strchr(value_data,'\\') != (char *) NULL)
1294 (void) CopyMagickString(buffer,value_data,MaxTextExtent);
1297 (void) CopyMagickString(buffer,font_root,MaxTextExtent);
1298 (void) ConcatenateMagickString(buffer,value_data,MaxTextExtent);
1301 LocaleLower(buffer);
1302 type_info->glyphs=ConstantString(buffer);
1304 type_info->stretch=NormalStretch;
1305 type_info->style=NormalStyle;
1306 type_info->weight=400;
1308 /* Some fonts are known to require special encodings */
1309 if ( (LocaleCompare(type_info->name, "Symbol") == 0 ) ||
1310 (LocaleCompare(type_info->name, "Wingdings") == 0 ) ||
1311 (LocaleCompare(type_info->name, "Wingdings-2") == 0 ) ||
1312 (LocaleCompare(type_info->name, "Wingdings-3") == 0 ) )
1313 type_info->encoding=ConstantString("AppleRoman");
1315 family_extent=value_name;
1317 for (q=value_name; *q != '\0'; )
1319 GetMagickToken(q,(const char **) &q,token);
1323 if (LocaleCompare(token,"Italic") == 0)
1325 type_info->style=ItalicStyle;
1328 else if (LocaleCompare(token,"Oblique") == 0)
1330 type_info->style=ObliqueStyle;
1333 else if (LocaleCompare(token,"Bold") == 0)
1335 type_info->weight=700;
1338 else if (LocaleCompare(token,"Thin") == 0)
1340 type_info->weight=100;
1343 else if ( (LocaleCompare(token,"ExtraLight") == 0) ||
1344 (LocaleCompare(token,"UltraLight") == 0) )
1346 type_info->weight=200;
1349 else if (LocaleCompare(token,"Light") == 0)
1351 type_info->weight=300;
1354 else if ( (LocaleCompare(token,"Normal") == 0) ||
1355 (LocaleCompare(token,"Regular") == 0) )
1357 type_info->weight=400;
1360 else if (LocaleCompare(token,"Medium") == 0)
1362 type_info->weight=500;
1365 else if ( (LocaleCompare(token,"SemiBold") == 0) ||
1366 (LocaleCompare(token,"DemiBold") == 0) )
1368 type_info->weight=600;
1371 else if ( (LocaleCompare(token,"ExtraBold") == 0) ||
1372 (LocaleCompare(token,"UltraBold") == 0) )
1374 type_info->weight=800;
1377 else if ( (LocaleCompare(token,"Heavy") == 0) ||
1378 (LocaleCompare(token,"Black") == 0) )
1380 type_info->weight=900;
1383 else if (LocaleCompare(token,"Condensed") == 0)
1385 type_info->stretch = CondensedStretch;
1388 else if (LocaleCompare(token,"Expanded") == 0)
1390 type_info->stretch = ExpandedStretch;
1393 else if (LocaleCompare(token,"ExtraCondensed") == 0)
1395 type_info->stretch = ExtraCondensedStretch;
1398 else if (LocaleCompare(token,"ExtraExpanded") == 0)
1400 type_info->stretch = ExtraExpandedStretch;
1403 else if (LocaleCompare(token,"SemiCondensed") == 0)
1405 type_info->stretch = SemiCondensedStretch;
1408 else if (LocaleCompare(token,"SemiExpanded") == 0)
1410 type_info->stretch = SemiExpandedStretch;
1413 else if (LocaleCompare(token,"UltraCondensed") == 0)
1415 type_info->stretch = UltraCondensedStretch;
1418 else if (LocaleCompare(token,"UltraExpanded") == 0)
1420 type_info->stretch = UltraExpandedStretch;
1429 (void) CopyMagickString(buffer,value_name,family_extent-value_name+1);
1430 StripString(buffer);
1431 type_info->family=ConstantString(buffer);
1434 status=AddValueToSplayTree(type_list,ConstantString(type_info->name),
1436 if (status == MagickFalse)
1437 (void) ThrowMagickException(exception,GetMagickModule(),
1438 ResourceLimitError,"MemoryAllocationFailed","`%s'",type_info->name);
1441 RegCloseKey ( reg_key );
1446 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1450 % N T G h o s t s c r i p t D L L %
1454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1456 % NTGhostscriptDLL() returns the path to the most recent Ghostscript version
1457 % DLL. The method returns TRUE on success otherwise FALSE.
1459 % The format of the NTGhostscriptDLL method is:
1461 % int NTGhostscriptDLL(char *path,int length)
1463 % A description of each parameter follows:
1465 % o path: return the Ghostscript DLL path here.
1467 % o length: the buffer length.
1471 static int NTGetRegistryValue(HKEY root,const char *key,const char *name,
1472 char *value,int *length)
1489 Get a registry value: key = root\\key, named value = name.
1491 if (RegOpenKeyExA(root,key,0,KEY_READ,&hkey) != ERROR_SUCCESS)
1492 return(1); /* no match */
1496 if (p == (BYTE *) NULL)
1497 p=(&byte); /* ERROR_MORE_DATA only if value is NULL */
1498 status=RegQueryValueExA(hkey,(char *) name,0,&type,p,&extent);
1500 if (status == ERROR_SUCCESS)
1503 return(0); /* return the match */
1505 if (status == ERROR_MORE_DATA)
1508 return(-1); /* buffer not large enough */
1510 return(1); /* not found */
1513 static int NTLocateGhostscript(const char **product_family,int *major_version,
1528 "Aladdin Ghostscript"
1532 Find the most recent version of Ghostscript.
1535 *product_family=NULL;
1537 *minor_version=49; /* min version of Ghostscript is 5.50 */
1538 for (i=0; i < (ssize_t) (sizeof(products)/sizeof(products[0])); i++)
1550 (void) FormatLocaleString(key,MaxTextExtent,"SOFTWARE\\%s",products[i]);
1551 root=HKEY_LOCAL_MACHINE;
1553 if (RegOpenKeyExA(root,key,0,mode,&hkey) == ERROR_SUCCESS)
1562 Now enumerate the keys.
1564 extent=sizeof(key)/sizeof(char);
1565 for (j=0; RegEnumKeyA(hkey,j,key,extent) == ERROR_SUCCESS; j++)
1573 if (sscanf(key,"%d.%d",&major,&minor) != 2)
1575 if ((major > *major_version) || ((major == *major_version) &&
1576 (minor > *minor_version)))
1578 *product_family=products[i];
1579 *major_version=major;
1580 *minor_version=minor;
1584 (void) RegCloseKey(hkey);
1587 if (status == FALSE)
1592 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"Ghostscript (%s) "
1593 "version %d.%02d",*product_family,*major_version,*minor_version);
1597 static int NTGhostscriptGetString(const char *name,char *value,
1598 const size_t length)
1608 *product_family = (const char *) NULL;
1624 { HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
1625 { HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" }
1629 Get a string from the installed Ghostscript.
1632 if (product_family == NULL)
1633 (void) NTLocateGhostscript(&product_family,&major_version,&minor_version);
1634 if (product_family == NULL)
1636 (void) FormatLocaleString(key,MaxTextExtent,"SOFTWARE\\%s\\%d.%02d",
1637 product_family,major_version,minor_version);
1638 for (i=0; i < (ssize_t) (sizeof(hkeys)/sizeof(hkeys[0])); i++)
1640 extent=(int) length;
1641 if (NTGetRegistryValue(hkeys[i].hkey,key,name,value,&extent) == 0)
1643 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1644 "registry: \"%s\\%s\\%s\"=\"%s\"",hkeys[i].name,key,name,value);
1647 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1648 "registry: \"%s\\%s\\%s\" (failed)",hkeys[i].name,key,name);
1653 MagickPrivate int NTGhostscriptDLL(char *path,int length)
1656 dll[MaxTextExtent] = { "" };
1659 if ((*dll == '\0') &&
1660 (NTGhostscriptGetString("GS_DLL",dll,sizeof(dll)) == FALSE))
1662 (void) CopyMagickString(path,dll,length);
1667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1671 % N T G h o s t s c r i p t D L L V e c t o r s %
1675 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1677 % NTGhostscriptDLLVectors() returns a GhostInfo structure that includes
1678 % function vectors to invoke Ghostscript DLL functions. A null pointer is
1679 % returned if there is an error when loading the DLL or retrieving the
1682 % The format of the NTGhostscriptDLLVectors method is:
1684 % const GhostInfo *NTGhostscriptDLLVectors(void)
1687 MagickExport const GhostInfo *NTGhostscriptDLLVectors(void)
1689 if (NTGhostscriptLoadDLL() == FALSE)
1690 return((GhostInfo *) NULL);
1691 return(&ghost_info);
1695 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1699 % N T G h o s t s c r i p t E X E %
1703 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1705 % NTGhostscriptEXE() obtains the path to the latest Ghostscript executable.
1706 % The method returns FALSE if a full path value is not obtained and returns
1707 % a default path of gswin32c.exe.
1709 % The format of the NTGhostscriptEXE method is:
1711 % int NTGhostscriptEXE(char *path,int length)
1713 % A description of each parameter follows:
1715 % o path: return the Ghostscript executable path here.
1717 % o length: length of buffer.
1720 MagickPrivate int NTGhostscriptEXE(char *path,int length)
1726 program[MaxTextExtent] = { "" };
1728 (void) CopyMagickString(path,"gswin32c.exe",length);
1729 if ((*program == '\0') &&
1730 (NTGhostscriptGetString("GS_DLL",program,sizeof(program)) == FALSE))
1732 p=strrchr(program,'\\');
1733 if (p != (char *) NULL)
1737 (void) ConcatenateMagickString(program,"gswin32c.exe",sizeof(program));
1739 (void) CopyMagickString(path,program,length);
1744 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1748 % N T G h o s t s c r i p t F o n t s %
1752 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1754 % NTGhostscriptFonts() obtains the path to the Ghostscript fonts. The method
1755 % returns FALSE if it cannot determine the font path.
1757 % The format of the NTGhostscriptFonts method is:
1759 % int NTGhostscriptFonts(char *path, int length)
1761 % A description of each parameter follows:
1763 % o path: return the font path here.
1765 % o length: length of the path buffer.
1768 MagickPrivate int NTGhostscriptFonts(char *path,int length)
1771 buffer[MaxTextExtent],
1772 filename[MaxTextExtent];
1779 if (NTGhostscriptGetString("GS_LIB",buffer,MaxTextExtent) == FALSE)
1781 for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
1783 (void) CopyMagickString(path,p+1,length+1);
1784 q=strchr(path,DirectoryListSeparator);
1785 if (q != (char *) NULL)
1787 (void) FormatLocaleString(filename,MaxTextExtent,"%s%sfonts.dir",path,
1788 DirectorySeparator);
1789 if (IsPathAccessible(filename) != MagickFalse)
1796 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1800 % N T G h o s t s c r i p t L o a d D L L %
1804 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1806 % NTGhostscriptLoadDLL() attempts to load the Ghostscript DLL and returns
1807 % TRUE if it succeeds.
1809 % The format of the NTGhostscriptLoadDLL method is:
1811 % int NTGhostscriptLoadDLL(void)
1814 MagickPrivate int NTGhostscriptLoadDLL(void)
1817 path[MaxTextExtent];
1819 if (ghost_handle != (void *) NULL)
1821 if (NTGhostscriptDLL(path,sizeof(path)) == FALSE)
1823 ghost_handle=lt_dlopen(path);
1824 if (ghost_handle == (void *) NULL)
1826 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1827 ghost_info.exit=(int (MagickDLLCall *)(gs_main_instance*))
1828 lt_dlsym(ghost_handle,"gsapi_exit");
1829 ghost_info.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,int,
1830 char **)) (lt_dlsym(ghost_handle,"gsapi_init_with_args"));
1831 ghost_info.new_instance=(int (MagickDLLCall *)(gs_main_instance **,void *)) (
1832 lt_dlsym(ghost_handle,"gsapi_new_instance"));
1833 ghost_info.run_string=(int (MagickDLLCall *)(gs_main_instance *,const char *,
1834 int,int *)) (lt_dlsym(ghost_handle,"gsapi_run_string"));
1835 ghost_info.delete_instance=(void (MagickDLLCall *) (gs_main_instance *)) (
1836 lt_dlsym(ghost_handle,"gsapi_delete_instance"));
1837 if ((ghost_info.exit == NULL) || (ghost_info.init_with_args == NULL) ||
1838 (ghost_info.new_instance == NULL) || (ghost_info.run_string == NULL) ||
1839 (ghost_info.delete_instance == NULL))
1845 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1849 % N T G h o s t s c r i p t U n L o a d D L L %
1853 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1855 % NTGhostscriptUnLoadDLL() unloads the Ghostscript DLL and returns TRUE if
1858 % The format of the NTGhostscriptUnLoadDLL method is:
1860 % int NTGhostscriptUnLoadDLL(void)
1863 MagickExport int NTGhostscriptUnLoadDLL(void)
1868 if (ghost_handle == (void *) NULL)
1870 status=lt_dlclose(ghost_handle);
1871 ghost_handle=(void *) NULL;
1872 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1877 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1881 % N T I n i t i a l i z e L i b r a r y %
1885 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1887 % NTInitializeLibrary() initializes the dynamic module loading subsystem.
1889 % The format of the NTInitializeLibrary method is:
1891 % int NTInitializeLibrary(void)
1894 MagickPrivate int NTInitializeLibrary(void)
1900 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1904 % N T I s M a g i c k C o n f l i c t %
1908 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1910 % NTIsMagickConflict() returns true if the image format conflicts with a
1911 % logical drive (.e.g. X:).
1913 % The format of the IsMagickConflict method is:
1915 % MagickBooleanType IsMagickConflict(const char *magick)
1917 % A description of each parameter follows:
1919 % o magick: Specifies the image format.
1922 MagickPrivate MagickBooleanType NTIsMagickConflict(const char *magick)
1927 assert(magick != (char *) NULL);
1928 if (strlen(magick) > 1)
1929 return(MagickFalse);
1930 status=(GetLogicalDrives() & (1 << ((toupper((int) (*magick)))-'A'))) != 0 ?
1931 MagickTrue : MagickFalse;
1936 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1940 + N T M a p M e m o r y %
1944 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1946 % Mmap() emulates the Unix method of the same name.
1948 % The format of the NTMapMemory method is:
1950 % MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
1951 % int access,int file,MagickOffsetType offset)
1954 MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
1955 int flags,int file,MagickOffsetType offset)
1974 file_handle=INVALID_HANDLE_VALUE;
1975 low_length=(DWORD) (length & 0xFFFFFFFFUL);
1976 high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
1977 map_handle=INVALID_HANDLE_VALUE;
1979 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
1980 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
1982 if (protection & PROT_WRITE)
1984 access_mode=FILE_MAP_WRITE;
1985 if (!(flags & MAP_PRIVATE))
1986 protection_mode=PAGE_READWRITE;
1989 access_mode=FILE_MAP_COPY;
1990 protection_mode=PAGE_WRITECOPY;
1994 if (protection & PROT_READ)
1996 access_mode=FILE_MAP_READ;
1997 protection_mode=PAGE_READONLY;
1999 if ((file == -1) && (flags & MAP_ANONYMOUS))
2000 file_handle=INVALID_HANDLE_VALUE;
2002 file_handle=(HANDLE) _get_osfhandle(file);
2003 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
2007 map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
2009 CloseHandle(map_handle);
2011 if (map == (void *) NULL)
2012 return((void *) MAP_FAILED);
2013 return((void *) ((char *) map));
2017 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2021 % N T O p e n D i r e c t o r y %
2025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2027 % NTOpenDirectory() opens the directory named by filename and associates a
2028 % directory stream with it.
2030 % The format of the NTOpenDirectory method is:
2032 % DIR *NTOpenDirectory(const char *path)
2034 % A description of each parameter follows:
2036 % o entry: Specifies a pointer to a DIR structure.
2039 MagickPrivate DIR *NTOpenDirectory(const char *path)
2042 file_specification[MaxTextExtent];
2050 assert(path != (const char *) NULL);
2051 length=CopyMagickString(file_specification,path,MaxTextExtent);
2052 if (length >= (MaxTextExtent-1))
2053 return((DIR *) NULL);
2054 length=ConcatenateMagickString(file_specification,DirectorySeparator,
2056 if (length >= (MaxTextExtent-1))
2057 return((DIR *) NULL);
2058 entry=(DIR *) AcquireMagickMemory(sizeof(DIR));
2059 if (entry != (DIR *) NULL)
2061 entry->firsttime=TRUE;
2062 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
2064 if (entry->hSearch == INVALID_HANDLE_VALUE)
2066 length=ConcatenateMagickString(file_specification,"\\*.*",MaxTextExtent);
2067 if (length >= (MaxTextExtent-1))
2069 entry=(DIR *) RelinquishMagickMemory(entry);
2070 return((DIR *) NULL);
2072 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
2073 if (entry->hSearch == INVALID_HANDLE_VALUE)
2075 entry=(DIR *) RelinquishMagickMemory(entry);
2076 return((DIR *) NULL);
2083 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2087 % N T O p e n L i b r a r y %
2091 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2093 % NTOpenLibrary() loads a dynamic module into memory and returns a handle that
2094 % can be used to access the various procedures in the module.
2096 % The format of the NTOpenLibrary method is:
2098 % void *NTOpenLibrary(const char *filename)
2100 % A description of each parameter follows:
2102 % o path: Specifies a pointer to string representing dynamic module that
2107 static const char *GetSearchPath( void )
2109 #if defined(MAGICKCORE_LTDL_DELEGATE)
2110 return(lt_dlgetsearchpath());
2112 return(lt_slsearchpath);
2116 MagickPrivate void *NTOpenLibrary(const char *filename)
2118 #define MaxPathElements 31
2121 buffer[MaxTextExtent];
2139 mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
2140 handle=(void *) LoadLibraryEx(filename,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
2141 if ((handle != (void *) NULL) || (GetSearchPath() == (char *) NULL))
2146 p=(char *) GetSearchPath();
2148 while (index < MaxPathElements)
2150 q=strchr(p,DirectoryListSeparator);
2151 if (q == (char *) NULL)
2153 (void) CopyMagickString(buffer,p,MaxTextExtent);
2154 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
2155 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
2156 handle=(void *) LoadLibraryEx(buffer,NULL,
2157 LOAD_WITH_ALTERED_SEARCH_PATH);
2161 (void) CopyMagickString(buffer,p,i+1);
2162 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
2163 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
2164 handle=(void *) LoadLibraryEx(buffer,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
2165 if (handle != (void *) NULL)
2174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2178 % N T R e a d D i r e c t o r y %
2182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2184 % NTReadDirectory() returns a pointer to a structure representing the
2185 % directory entry at the current position in the directory stream to which
2188 % The format of the NTReadDirectory
2190 % NTReadDirectory(entry)
2192 % A description of each parameter follows:
2194 % o entry: Specifies a pointer to a DIR structure.
2197 MagickPrivate struct dirent *NTReadDirectory(DIR *entry)
2205 if (entry == (DIR *) NULL)
2206 return((struct dirent *) NULL);
2207 if (!entry->firsttime)
2209 status=FindNextFile(entry->hSearch,&entry->Win32FindData);
2211 return((struct dirent *) NULL);
2213 length=CopyMagickString(entry->file_info.d_name,
2214 entry->Win32FindData.cFileName,sizeof(entry->file_info.d_name));
2215 if (length >= sizeof(entry->file_info.d_name))
2216 return((struct dirent *) NULL);
2217 entry->firsttime=FALSE;
2218 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
2219 return(&entry->file_info);
2223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2227 % N T R e g i s t r y K e y L o o k u p %
2231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2233 % NTRegistryKeyLookup() returns ImageMagick installation path settings
2234 % stored in the Windows Registry. Path settings are specific to the
2235 % installed ImageMagick version so that multiple Image Magick installations
2238 % Values are stored in the registry under a base path path similar to
2239 % "HKEY_LOCAL_MACHINE/SOFTWARE\ImageMagick\5.5.7\Q:16". The provided subkey
2240 % is appended to this base path to form the full key.
2242 % The format of the NTRegistryKeyLookup method is:
2244 % unsigned char *NTRegistryKeyLookup(const char *subkey)
2246 % A description of each parameter follows:
2248 % o subkey: Specifies a string that identifies the registry object.
2249 % Currently supported sub-keys include: "BinPath", "ConfigurePath",
2250 % "LibPath", "CoderModulesPath", "FilterModulesPath", "SharePath".
2253 MagickPrivate unsigned char *NTRegistryKeyLookup(const char *subkey)
2256 package_key[MaxTextExtent];
2274 (void) FormatLocaleString(package_key,MaxTextExtent,"SOFTWARE\\%s\\%s\\Q:%d",
2275 MagickPackageName,MagickLibVersionText,MAGICKCORE_QUANTUM_DEPTH);
2276 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",package_key);
2277 registry_key=(HKEY) INVALID_HANDLE_VALUE;
2278 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,package_key,0,KEY_READ,®istry_key);
2279 if (status != ERROR_SUCCESS)
2281 registry_key=(HKEY) INVALID_HANDLE_VALUE;
2282 return((unsigned char *) NULL);
2288 value=(unsigned char *) AcquireQuantumMemory(size,sizeof(*value));
2289 if (value == (unsigned char *) NULL)
2291 RegCloseKey(registry_key);
2292 return((unsigned char *) NULL);
2294 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",subkey);
2295 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
2296 if ((status == ERROR_MORE_DATA) && (type == REG_SZ))
2298 value=(unsigned char *) ResizeQuantumMemory(value,size,sizeof(*value));
2299 if (value == (BYTE *) NULL)
2301 RegCloseKey(registry_key);
2302 return((unsigned char *) NULL);
2304 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
2306 RegCloseKey(registry_key);
2307 if ((type != REG_SZ) || (status != ERROR_SUCCESS))
2308 value=(unsigned char *) RelinquishMagickMemory(value);
2309 return((unsigned char *) value);
2313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2317 % N T R e p o r t E v e n t %
2321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2323 % NTReportEvent() reports an event.
2325 % The format of the NTReportEvent method is:
2327 % MagickBooleanType NTReportEvent(const char *event,
2328 % const MagickBooleanType error)
2330 % A description of each parameter follows:
2332 % o event: the event.
2334 % o error: MagickTrue the event is an error.
2337 MagickPrivate MagickBooleanType NTReportEvent(const char *event,
2338 const MagickBooleanType error)
2349 handle=RegisterEventSource(NULL,MAGICKCORE_PACKAGE_NAME);
2351 return(MagickFalse);
2353 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
2354 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
2355 DeregisterEventSource(handle);
2360 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2364 % N T R e s o u r c e T o B l o b %
2368 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2370 % NTResourceToBlob() returns a blob containing the contents of the resource
2371 % in the current executable specified by the id parameter. This currently
2372 % used to retrieve MGK files tha have been embedded into the various command
2375 % The format of the NTResourceToBlob method is:
2377 % unsigned char *NTResourceToBlob(const char *id)
2379 % A description of each parameter follows:
2381 % o id: Specifies a string that identifies the resource.
2384 MagickPrivate unsigned char *NTResourceToBlob(const char *id)
2387 path[MaxTextExtent];
2405 assert(id != (const char *) NULL);
2406 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
2407 (void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",GetClientPath(),
2408 DirectorySeparator,GetClientName());
2409 if (IsPathAccessible(path) != MagickFalse)
2410 handle=GetModuleHandle(path);
2412 handle=GetModuleHandle(0);
2414 return((unsigned char *) NULL);
2415 resource=FindResource(handle,id,"IMAGEMAGICK");
2417 return((unsigned char *) NULL);
2418 global=LoadResource(handle,resource);
2420 return((unsigned char *) NULL);
2421 length=SizeofResource(handle,resource);
2422 value=(unsigned char *) LockResource(global);
2425 FreeResource(global);
2426 return((unsigned char *) NULL);
2428 blob=(unsigned char *) AcquireQuantumMemory(length+MaxTextExtent,
2430 if (blob != (unsigned char *) NULL)
2432 (void) CopyMagickMemory(blob,value,length);
2435 UnlockResource(global);
2436 FreeResource(global);
2441 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2445 % N T S e e k D i r e c t o r y %
2449 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2451 % NTSeekDirectory() sets the position of the next NTReadDirectory() operation
2452 % on the directory stream.
2454 % The format of the NTSeekDirectory method is:
2456 % void NTSeekDirectory(DIR *entry,ssize_t position)
2458 % A description of each parameter follows:
2460 % o entry: Specifies a pointer to a DIR structure.
2462 % o position: specifies the position associated with the directory
2466 MagickPrivate void NTSeekDirectory(DIR *entry,ssize_t position)
2469 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2470 assert(entry != (DIR *) NULL);
2474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2478 % N T S e t S e a r c h P a t h %
2482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2484 % NTSetSearchPath() sets the current locations that the subsystem should
2485 % look at to find dynamically loadable modules.
2487 % The format of the NTSetSearchPath method is:
2489 % int NTSetSearchPath(const char *path)
2491 % A description of each parameter follows:
2493 % o path: Specifies a pointer to string representing the search path
2494 % for DLL's that can be dynamically loaded.
2497 MagickPrivate int NTSetSearchPath(const char *path)
2499 #if defined(MAGICKCORE_LTDL_DELEGATE)
2500 lt_dlsetsearchpath(path);
2502 if (lt_slsearchpath != (char *) NULL)
2503 lt_slsearchpath=DestroyString(lt_slsearchpath);
2504 if (path != (char *) NULL)
2505 lt_slsearchpath=AcquireString(path);
2511 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2515 + N T S y n c M e m o r y %
2519 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2521 % NTSyncMemory() emulates the Unix method of the same name.
2523 % The format of the NTSyncMemory method is:
2525 % int NTSyncMemory(void *address,size_t length,int flags)
2527 % A description of each parameter follows:
2529 % o address: the address of the binary large object.
2531 % o length: the length of the binary large object.
2533 % o flags: Option flags (ignored for Windows).
2536 MagickPrivate int NTSyncMemory(void *address,size_t length,int flags)
2539 if (FlushViewOfFile(address,length) == MagickFalse)
2545 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2549 % N T S y s t e m C o m m a n d %
2553 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2555 % NTSystemCommand() executes the specified command and waits until it
2556 % terminates. The returned value is the exit status of the command.
2558 % The format of the NTSystemCommand method is:
2560 % int NTSystemCommand(MagickFalse,const char *command)
2562 % A description of each parameter follows:
2564 % o command: This string is the command to execute.
2567 MagickPrivate int NTSystemCommand(const char *command)
2570 local_command[MaxTextExtent];
2587 if (command == (char *) NULL)
2589 GetStartupInfo(&startup_info);
2590 startup_info.dwFlags=STARTF_USESHOWWINDOW;
2591 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
2592 (void) CopyMagickString(local_command,command,MaxTextExtent);
2593 background_process=command[strlen(command)-1] == '&' ? MagickTrue :
2595 if (background_process)
2596 local_command[strlen(command)-1]='\0';
2597 if (command[strlen(command)-1] == '|')
2598 local_command[strlen(command)-1]='\0';
2600 startup_info.wShowWindow=SW_SHOWDEFAULT;
2601 status=CreateProcess((LPCTSTR) NULL,local_command,
2602 (LPSECURITY_ATTRIBUTES) NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) FALSE,
2603 (DWORD) NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
2607 if (background_process)
2608 return(status == 0);
2609 status=WaitForSingleObject(process_info.hProcess,INFINITE);
2610 if (status != WAIT_OBJECT_0)
2612 status=GetExitCodeProcess(process_info.hProcess,&child_status);
2615 CloseHandle(process_info.hProcess);
2616 CloseHandle(process_info.hThread);
2617 return((int) child_status);
2621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2625 % N T S y s t e m C o n i f i g u r a t i o n %
2629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2631 % NTSystemConfiguration() provides a way for the application to determine
2632 % values for system limits or options at runtime.
2634 % The format of the exit method is:
2636 % ssize_t NTSystemConfiguration(int name)
2638 % A description of each parameter follows:
2640 % o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
2643 MagickPrivate ssize_t NTSystemConfiguration(int name)
2652 GetSystemInfo(&system_info);
2653 return(system_info.dwPageSize);
2655 case _SC_PHYS_PAGES:
2669 handle=GetModuleHandle("kernel32.dll");
2670 if (handle == (HMODULE) NULL)
2672 GetSystemInfo(&system_info);
2673 module=(LPFNDLLFUNC2) NTGetLibrarySymbol(handle,"GlobalMemoryStatusEx");
2674 if (module == (LPFNDLLFUNC2) NULL)
2679 GlobalMemoryStatus(&status);
2680 return((ssize_t) status.dwTotalPhys/system_info.dwPageSize);
2682 status.dwLength=sizeof(status);
2683 if (module(&status) == 0)
2685 return((ssize_t) status.ullTotalPhys/system_info.dwPageSize);
2696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2700 % N T T e l l D i r e c t o r y %
2704 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2706 % NTTellDirectory() returns the current location associated with the named
2709 % The format of the NTTellDirectory method is:
2711 % ssize_t NTTellDirectory(DIR *entry)
2713 % A description of each parameter follows:
2715 % o entry: Specifies a pointer to a DIR structure.
2718 MagickPrivate ssize_t NTTellDirectory(DIR *entry)
2720 assert(entry != (DIR *) NULL);
2725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2729 % N T T r u n c a t e F i l e %
2733 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2735 % NTTruncateFile() truncates a file to a specified length.
2737 % The format of the NTTruncateFile method is:
2739 % int NTTruncateFile(int file,off_t length)
2741 % A description of each parameter follows:
2745 % o length: the file length.
2748 MagickPrivate int NTTruncateFile(int file,off_t length)
2758 file_handle=_get_osfhandle(file);
2759 if (file_handle == -1L)
2761 low=(long) (length & 0xffffffffUL);
2762 high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
2763 file_pointer=SetFilePointer((HANDLE) file_handle,low,&high,FILE_BEGIN);
2764 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
2766 if (SetEndOfFile((HANDLE) file_handle) == 0)
2772 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2776 + N T U n m a p M e m o r y %
2780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2782 % NTUnmapMemory() emulates the Unix munmap method.
2784 % The format of the NTUnmapMemory method is:
2786 % int NTUnmapMemory(void *map,size_t length)
2788 % A description of each parameter follows:
2790 % o map: the address of the binary large object.
2792 % o length: the length of the binary large object.
2795 MagickPrivate int NTUnmapMemory(void *map,size_t length)
2798 if (UnmapViewOfFile(map) == 0)
2804 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2808 % N T U s e r T i m e %
2812 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2814 % NTUserTime() returns the total time the process has been scheduled (e.g.
2815 % seconds) since the last call to StartTimer().
2817 % The format of the UserTime method is:
2819 % double NTUserTime(void)
2822 MagickPrivate double NTUserTime(void)
2852 OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
2853 GetVersionEx(&OsVersionInfo);
2854 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
2855 return(NTElapsedTime());
2856 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
2857 &kernel_time.filetime,&user_time.filetime);
2860 return((double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
2864 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2868 % N T W a r n i n g H a n d l e r %
2872 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2874 % NTWarningHandler() displays a warning reason.
2876 % The format of the NTWarningHandler method is:
2878 % void NTWarningHandler(const ExceptionType severity,const char *reason,
2879 % const char *description)
2881 % A description of each parameter follows:
2883 % o severity: Specifies the numeric warning category.
2885 % o reason: Specifies the reason to display before terminating the
2888 % o description: Specifies any description to the reason.
2891 MagickExport void NTWarningHandler(const ExceptionType severity,
2892 const char *reason,const char *description)
2895 buffer[2*MaxTextExtent];
2898 if (reason == (char *) NULL)
2900 if (description == (char *) NULL)
2901 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s.\n",GetClientName(),
2904 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s (%s).\n",
2905 GetClientName(),reason,description);
2906 (void) MessageBox(NULL,buffer,"ImageMagick Warning",MB_OK | MB_TASKMODAL |
2907 MB_SETFOREGROUND | MB_ICONINFORMATION);