blob: aaa76ade58795f9a042dc9938bae2ce73500c8d9 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% N N TTTTT %
7% NN N T %
8% N N N T %
9% N NN T %
10% N N T %
11% %
12% %
13% Windows NT Utility Methods for MagickCore %
14% %
15% Software Design %
16% John Cristy %
17% December 1996 %
18% %
19% %
cristy1454be72011-12-19 01:52:48 +000020% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
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. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37*/
38/*
39 Include declarations.
40*/
cristy309042f2012-02-20 18:59:35 +000041#include "MagickCore/studio.h"
cristy0157aea2010-04-24 21:12:18 +000042#if defined(MAGICKCORE_WINDOWS_SUPPORT)
cristy309042f2012-02-20 18:59:35 +000043#include "MagickCore/client.h"
44#include "MagickCore/exception-private.h"
45#include "MagickCore/locale_.h"
46#include "MagickCore/log.h"
47#include "MagickCore/magick.h"
48#include "MagickCore/memory_.h"
cristyd2d11ec2012-03-28 13:53:49 +000049#include "MagickCore/nt-base.h"
50#include "MagickCore/nt-base-private.h"
cristy309042f2012-02-20 18:59:35 +000051#include "MagickCore/resource_.h"
cristy6e2469f2012-02-21 13:57:36 +000052#include "MagickCore/resource-private.h"
cristy309042f2012-02-20 18:59:35 +000053#include "MagickCore/timer.h"
54#include "MagickCore/string_.h"
55#include "MagickCore/utility.h"
56#include "MagickCore/version.h"
cristy3ed852e2009-09-05 21:47:34 +000057#if defined(MAGICKCORE_LTDL_DELEGATE)
58# include "ltdl.h"
59#endif
cristy2c5fc272012-02-22 01:27:46 +000060#include "MagickCore/nt-base-private.h"
cristy3ed852e2009-09-05 21:47:34 +000061#if defined(MAGICKCORE_CIPHER_SUPPORT)
62#include <ntsecapi.h>
63#include <wincrypt.h>
64#endif
65
66/*
67 Define declarations.
68*/
69#if !defined(MAP_FAILED)
70#define MAP_FAILED ((void *) -1)
71#endif
72
73/*
74 Static declarations.
75*/
76#if !defined(MAGICKCORE_LTDL_DELEGATE)
77static char
78 *lt_slsearchpath = (char *) NULL;
79#endif
80
cristydefb3f02009-09-10 02:18:35 +000081static GhostInfo
82 ghost_info;
cristy3ed852e2009-09-05 21:47:34 +000083
84static void
cristydefb3f02009-09-10 02:18:35 +000085 *ghost_handle = (void *) NULL;
cristy3ed852e2009-09-05 21:47:34 +000086
87/*
88 External declarations.
89*/
cristy0157aea2010-04-24 21:12:18 +000090#if !defined(MAGICKCORE_WINDOWS_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +000091extern "C" BOOL WINAPI
92 DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved);
93#endif
94
95/*
96%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97% %
98% %
99% %
100% D l l M a i n %
101% %
102% %
103% %
104%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105%
106% DllMain() is an entry point to the DLL which is called when processes and
107% threads are initialized and terminated, or upon calls to the Windows
108% LoadLibrary and FreeLibrary functions.
109%
110% The function returns TRUE of it succeeds, or FALSE if initialization fails.
111%
112% The format of the DllMain method is:
113%
114% BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
115%
116% A description of each parameter follows:
117%
118% o handle: handle to the DLL module
119%
120% o reason: reason for calling function:
121%
122% DLL_PROCESS_ATTACH - DLL is being loaded into virtual address
123% space of current process.
124% DLL_THREAD_ATTACH - Indicates that the current process is
125% creating a new thread. Called under the
126% context of the new thread.
127% DLL_THREAD_DETACH - Indicates that the thread is exiting.
128% Called under the context of the exiting
129% thread.
130% DLL_PROCESS_DETACH - Indicates that the DLL is being unloaded
131% from the virtual address space of the
132% current process.
133%
134% o lpvReserved: Used for passing additional info during DLL_PROCESS_ATTACH
135% and DLL_PROCESS_DETACH.
136%
137*/
138#if defined(_DLL) && defined( ProvideDllMain )
139BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
140{
141 switch (reason)
142 {
143 case DLL_PROCESS_ATTACH:
144 {
145 char
146 *module_path;
147
148 ssize_t
149 count;
150
151 module_path=(char *) AcquireQuantumMemory(MaxTextExtent,
152 sizeof(*module_path));
153 if (module_path == (char *) NULL)
154 return(FALSE);
155 count=(ssize_t) GetModuleFileName(handle,module_path,MaxTextExtent);
156 if (count != 0)
157 {
158 char
159 *path;
160
161 for ( ; count > 0; count--)
162 if (module_path[count] == '\\')
163 {
164 module_path[count+1]='\0';
165 break;
166 }
167 MagickCoreGenesis(module_path,MagickFalse);
168 path=(char *) AcquireQuantumMemory(16UL*MaxTextExtent,sizeof(*path));
169 if (path == (char *) NULL)
170 {
171 module_path=DestroyString(module_path);
172 return(FALSE);
173 }
174 count=(ssize_t) GetEnvironmentVariable("PATH",path,16*MaxTextExtent);
175 if ((count != 0) && (strstr(path,module_path) == (char *) NULL))
176 {
177 if ((strlen(module_path)+count+1) < (16*MaxTextExtent-1))
178 {
179 char
180 *variable;
181
182 variable=(char *) AcquireQuantumMemory(16UL*MaxTextExtent,
183 sizeof(*variable));
184 if (variable == (char *) NULL)
185 {
186 path=DestroyString(path);
187 module_path=DestroyString(module_path);
188 return(FALSE);
189 }
cristyb51dff52011-05-19 16:55:47 +0000190 (void) FormatLocaleString(variable,16*MaxTextExtent,
cristy3ed852e2009-09-05 21:47:34 +0000191 "%s;%s",module_path,path);
192 SetEnvironmentVariable("PATH",variable);
193 variable=DestroyString(variable);
194 }
195 }
196 path=DestroyString(path);
197 }
198 module_path=DestroyString(module_path);
199 break;
200 }
201 case DLL_PROCESS_DETACH:
202 {
203 MagickCoreTerminus();
204 break;
205 }
206 default:
207 break;
208 }
209 return(TRUE);
210}
211#endif
212
213/*
214%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215% %
216% %
217% %
218% E x i t %
219% %
220% %
221% %
222%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223%
224% Exit() calls TerminateProcess for Win95.
225%
226% The format of the exit method is:
227%
228% int Exit(int status)
229%
230% A description of each parameter follows:
231%
232% o status: an integer value representing the status of the terminating
233% process.
234%
235*/
cristyd2d11ec2012-03-28 13:53:49 +0000236MagickPrivate int Exit(int status)
cristy3ed852e2009-09-05 21:47:34 +0000237{
238 if (IsWindows95())
239 TerminateProcess(GetCurrentProcess(),(unsigned int) status);
240 exit(status);
241 return(0);
242}
243
cristy0157aea2010-04-24 21:12:18 +0000244#if !defined(__MINGW32__)
cristy3ed852e2009-09-05 21:47:34 +0000245/*
246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247% %
248% %
249% %
cristy6d71f8d2010-02-28 00:46:02 +0000250% g e t t i m e o f d a y %
251% %
252% %
253% %
254%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
255%
256% The gettimeofday() method get the time of day.
257%
258% The format of the gettimeofday method is:
259%
260% int gettimeofday(struct timeval *time_value,struct timezone *time_zone)
261%
262% A description of each parameter follows:
263%
264% o time_value: the time value.
265%
266% o time_zone: the time zone.
267%
268*/
cristyd2d11ec2012-03-28 13:53:49 +0000269MagickPrivate int gettimeofday (struct timeval *time_value,
cristy6d71f8d2010-02-28 00:46:02 +0000270 struct timezone *time_zone)
271{
cristyc05bf172010-06-04 19:53:53 +0000272#define EpochFiletime MagickLLConstant(116444736000000000)
cristy6d71f8d2010-02-28 00:46:02 +0000273
274 static int
275 is_tz_set;
276
277 if (time_value != (struct timeval *) NULL)
278 {
279 FILETIME
280 file_time;
281
282 __int64
283 time;
284
285 LARGE_INTEGER
286 date_time;
287
288 GetSystemTimeAsFileTime(&file_time);
289 date_time.LowPart=file_time.dwLowDateTime;
290 date_time.HighPart=file_time.dwHighDateTime;
291 time=date_time.QuadPart;
cristy99881662010-03-04 14:25:26 +0000292 time-=EpochFiletime;
cristy6d71f8d2010-02-28 00:46:02 +0000293 time/=10;
cristybb503372010-05-27 20:51:26 +0000294 time_value->tv_sec=(ssize_t) (time / 1000000);
295 time_value->tv_usec=(ssize_t) (time % 1000000);
cristy6d71f8d2010-02-28 00:46:02 +0000296 }
297 if (time_zone != (struct timezone *) NULL)
298 {
299 if (is_tz_set == 0)
300 {
301 _tzset();
302 is_tz_set++;
303 }
304 time_zone->tz_minuteswest=_timezone/60;
305 time_zone->tz_dsttime=_daylight;
306 }
307 return(0);
308}
cristy807fd932010-04-24 03:38:46 +0000309#endif
cristy6d71f8d2010-02-28 00:46:02 +0000310
311/*
312%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313% %
314% %
315% %
cristy3ed852e2009-09-05 21:47:34 +0000316% I s W i n d o w s 9 5 %
317% %
318% %
319% %
320%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321%
322% IsWindows95() returns true if the system is Windows 95.
323%
324% The format of the IsWindows95 method is:
325%
326% int IsWindows95()
327%
328*/
cristyd2d11ec2012-03-28 13:53:49 +0000329MagickPrivate int IsWindows95()
cristy3ed852e2009-09-05 21:47:34 +0000330{
331 OSVERSIONINFO
332 version_info;
333
334 version_info.dwOSVersionInfoSize=sizeof(version_info);
335 if (GetVersionEx(&version_info) &&
336 (version_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS))
337 return(1);
338 return(0);
339}
340
341/*
342%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343% %
344% %
345% %
cristy66f9c3c2011-08-13 17:12:28 +0000346% N T A r g v T o U T F 8 %
347% %
348% %
349% %
350%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
351%
352% NTArgvToUTF8() converts the wide command line arguments to UTF-8 to ensure
353% compatibility with Linux.
354%
355% The format of the NTArgvToUTF8 method is:
356%
357% char **NTArgvToUTF8(const int argc,wchar_t **argv)
358%
359% A description of each parameter follows:
360%
361% o argc: the number of command line arguments.
362%
363% o argv: the wide-character command line arguments.
364%
365*/
cristyd2d11ec2012-03-28 13:53:49 +0000366MagickPrivate char **NTArgvToUTF8(const int argc,wchar_t **argv)
cristy66f9c3c2011-08-13 17:12:28 +0000367{
368 char
369 **utf8;
370
371 ssize_t
372 i;
373
374 utf8=(char **) AcquireQuantumMemory(argc,sizeof(*utf8));
375 if (utf8 == (char **) NULL)
376 ThrowFatalException(ResourceLimitFatalError,"UnableToConvertStringToARGV");
377 for (i=0; i < (ssize_t) argc; i++)
378 {
379 ssize_t
380 count;
381
382 count=WideCharToMultiByte(CP_UTF8,0,argv[i],-1,NULL,0,NULL,NULL);
383 if (count < 0)
384 count=0;
385 utf8[i]=(char *) AcquireQuantumMemory(count+1,sizeof(**utf8));
386 if (utf8[i] == (char *) NULL)
387 {
388 for (i--; i >= 0; i--)
389 utf8[i]=DestroyString(utf8[i]);
390 utf8=(char **) RelinquishMagickMemory(utf8);
391 ThrowFatalException(ResourceLimitFatalError,
392 "UnableToConvertStringToARGV");
393 }
394 count=WideCharToMultiByte(CP_UTF8,0,argv[i],-1,utf8[i],count,NULL,NULL);
395 utf8[i][count]=0;
396 }
397 return(utf8);
398}
399
400/*
401%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402% %
403% %
404% %
cristy3ed852e2009-09-05 21:47:34 +0000405% N T C l o s e D i r e c t o r y %
406% %
407% %
408% %
409%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410%
411% NTCloseDirectory() closes the named directory stream and frees the DIR
412% structure.
413%
414% The format of the NTCloseDirectory method is:
415%
416% int NTCloseDirectory(DIR *entry)
417%
418% A description of each parameter follows:
419%
420% o entry: Specifies a pointer to a DIR structure.
421%
422*/
cristyd2d11ec2012-03-28 13:53:49 +0000423MagickPrivate int NTCloseDirectory(DIR *entry)
cristy3ed852e2009-09-05 21:47:34 +0000424{
425 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
426 assert(entry != (DIR *) NULL);
427 FindClose(entry->hSearch);
428 entry=(DIR *) RelinquishMagickMemory(entry);
429 return(0);
430}
431
432/*
433%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
434% %
435% %
436% %
437% N T C l o s e L i b r a r y %
438% %
439% %
440% %
441%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
442%
443% NTCloseLibrary() unloads the module associated with the passed handle.
444%
445% The format of the NTCloseLibrary method is:
446%
447% void NTCloseLibrary(void *handle)
448%
449% A description of each parameter follows:
450%
451% o handle: Specifies a handle to a previously loaded dynamic module.
452%
453*/
cristyd2d11ec2012-03-28 13:53:49 +0000454MagickPrivate int NTCloseLibrary(void *handle)
cristy3ed852e2009-09-05 21:47:34 +0000455{
456 if (IsWindows95())
457 return(FreeLibrary((HINSTANCE) handle));
458 return(!(FreeLibrary((HINSTANCE) handle)));
459}
460
461/*
462%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
463% %
464% %
465% %
466% N T C o n t r o l H a n d l e r %
467% %
468% %
469% %
470%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
471%
472% NTControlHandler() registers a control handler that is activated when, for
473% example, a ctrl-c is received.
474%
475% The format of the NTControlHandler method is:
476%
477% int NTControlHandler(void)
478%
479*/
480
481static BOOL ControlHandler(DWORD type)
482{
cristy3b743bb2009-09-14 16:07:59 +0000483 (void) type;
cristyf34a1452009-10-24 22:29:27 +0000484 AsynchronousResourceComponentTerminus();
cristy3ed852e2009-09-05 21:47:34 +0000485 return(FALSE);
486}
487
cristyd2d11ec2012-03-28 13:53:49 +0000488MagickPrivate int NTControlHandler(void)
cristy3ed852e2009-09-05 21:47:34 +0000489{
490 return(SetConsoleCtrlHandler((PHANDLER_ROUTINE) ControlHandler,TRUE));
491}
492
493/*
494%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
495% %
496% %
497% %
498% N T E l a p s e d T i m e %
499% %
500% %
501% %
502%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
503%
504% NTElapsedTime() returns the elapsed time (in seconds) since the last call to
505% StartTimer().
506%
507% The format of the ElapsedTime method is:
508%
509% double NTElapsedTime(void)
510%
511*/
cristyd2d11ec2012-03-28 13:53:49 +0000512MagickPrivate double NTElapsedTime(void)
cristy3ed852e2009-09-05 21:47:34 +0000513{
514 union
515 {
516 FILETIME
517 filetime;
518
519 __int64
520 filetime64;
521 } elapsed_time;
522
523 SYSTEMTIME
524 system_time;
525
526 GetSystemTime(&system_time);
527 SystemTimeToFileTime(&system_time,&elapsed_time.filetime);
528 return((double) 1.0e-7*elapsed_time.filetime64);
529}
530
531/*
532%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
533% %
534% %
535% %
536+ N T E r r o r H a n d l e r %
537% %
538% %
539% %
540%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
541%
542% NTErrorHandler() displays an error reason and then terminates the program.
543%
544% The format of the NTErrorHandler method is:
545%
cristy3b743bb2009-09-14 16:07:59 +0000546% void NTErrorHandler(const ExceptionType severity,const char *reason,
cristy3ed852e2009-09-05 21:47:34 +0000547% const char *description)
548%
549% A description of each parameter follows:
550%
cristy3b743bb2009-09-14 16:07:59 +0000551% o severity: Specifies the numeric error category.
cristy3ed852e2009-09-05 21:47:34 +0000552%
553% o reason: Specifies the reason to display before terminating the
554% program.
555%
556% o description: Specifies any description to the reason.
557%
558*/
cristyd2d11ec2012-03-28 13:53:49 +0000559MagickPrivate void NTErrorHandler(const ExceptionType severity,
cristy3b743bb2009-09-14 16:07:59 +0000560 const char *reason,const char *description)
cristy3ed852e2009-09-05 21:47:34 +0000561{
562 char
563 buffer[3*MaxTextExtent],
564 *message;
565
cristy3b743bb2009-09-14 16:07:59 +0000566 (void) severity;
cristy3ed852e2009-09-05 21:47:34 +0000567 if (reason == (char *) NULL)
568 {
569 MagickCoreTerminus();
570 exit(0);
571 }
572 message=GetExceptionMessage(errno);
573 if ((description != (char *) NULL) && errno)
cristyb51dff52011-05-19 16:55:47 +0000574 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s (%s) [%s].\n",
cristy3ed852e2009-09-05 21:47:34 +0000575 GetClientName(),reason,description,message);
576 else
577 if (description != (char *) NULL)
cristyb51dff52011-05-19 16:55:47 +0000578 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s (%s).\n",
cristy3ed852e2009-09-05 21:47:34 +0000579 GetClientName(),reason,description);
580 else
581 if (errno != 0)
cristyb51dff52011-05-19 16:55:47 +0000582 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s [%s].\n",
cristy3ed852e2009-09-05 21:47:34 +0000583 GetClientName(),reason,message);
584 else
cristyb51dff52011-05-19 16:55:47 +0000585 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s.\n",
cristy3ed852e2009-09-05 21:47:34 +0000586 GetClientName(),reason);
587 message=DestroyString(message);
588 (void) MessageBox(NULL,buffer,"ImageMagick Exception",MB_OK | MB_TASKMODAL |
589 MB_SETFOREGROUND | MB_ICONEXCLAMATION);
590 MagickCoreTerminus();
591 exit(0);
592}
593
594/*
595%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
596% %
597% %
598% %
599% N T E x i t L i b r a r y %
600% %
601% %
602% %
603%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
604%
605% NTExitLibrary() exits the dynamic module loading subsystem.
606%
607% The format of the NTExitLibrary method is:
608%
609% int NTExitLibrary(void)
610%
611*/
cristyd2d11ec2012-03-28 13:53:49 +0000612MagickPrivate int NTExitLibrary(void)
cristy3ed852e2009-09-05 21:47:34 +0000613{
614 return(0);
615}
616
617/*
618%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
619% %
620% %
621% %
622% N T G a t h e r R a n d o m D a t a %
623% %
624% %
625% %
626%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
627%
628% NTGatherRandomData() gathers random data and returns it.
629%
630% The format of the GatherRandomData method is:
631%
632% MagickBooleanType NTGatherRandomData(const size_t length,
633% unsigned char *random)
634%
635% A description of each parameter follows:
636%
637% length: the length of random data buffer
638%
639% random: the random data is returned here.
640%
641*/
cristyd2d11ec2012-03-28 13:53:49 +0000642MagickPrivate MagickBooleanType NTGatherRandomData(const size_t length,
cristy3ed852e2009-09-05 21:47:34 +0000643 unsigned char *random)
644{
645#if defined(MAGICKCORE_CIPHER_SUPPORT) && defined(_MSC_VER) && (_MSC_VER > 1200)
646 HCRYPTPROV
647 handle;
648
649 int
650 status;
651
652 handle=(HCRYPTPROV) NULL;
653 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
654 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET));
655 if (status == 0)
656 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
657 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET));
658 if (status == 0)
659 return(MagickFalse);
660 status=CryptGenRandom(handle,(DWORD) length,random);
661 if (status == 0)
662 {
663 status=CryptReleaseContext(handle,0);
664 return(MagickFalse);
665 }
666 status=CryptReleaseContext(handle,0);
667 if (status == 0)
668 return(MagickFalse);
cristy3b743bb2009-09-14 16:07:59 +0000669#else
670 (void) random;
671 (void) length;
cristy3ed852e2009-09-05 21:47:34 +0000672#endif
673 return(MagickTrue);
674}
675
676/*
677%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
678% %
679% %
680% %
681% N T G e t E x e c u t i o n P a t h %
682% %
683% %
684% %
685%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
686%
687% NTGetExecutionPath() returns the execution path of a program.
688%
689% The format of the GetExecutionPath method is:
690%
691% MagickBooleanType NTGetExecutionPath(char *path,const size_t extent)
692%
693% A description of each parameter follows:
694%
695% o path: the pathname of the executable that started the process.
696%
697% o extent: the maximum extent of the path.
698%
699*/
cristyd2d11ec2012-03-28 13:53:49 +0000700MagickPrivate MagickBooleanType NTGetExecutionPath(char *path,
cristy3ed852e2009-09-05 21:47:34 +0000701 const size_t extent)
702{
703 GetModuleFileName(0,path,(DWORD) extent);
704 return(MagickTrue);
705}
706
707/*
708%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
709% %
710% %
711% %
712% N T G e t L a s t E r r o r %
713% %
714% %
715% %
716%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
717%
718% NTGetLastError() returns the last error that occurred.
719%
720% The format of the NTGetLastError method is:
721%
722% char *NTGetLastError(void)
723%
724*/
cristyf7836bf2012-02-20 16:32:47 +0000725char *NTGetLastError(void)
cristy3ed852e2009-09-05 21:47:34 +0000726{
727 char
728 *reason;
729
730 int
731 status;
732
733 LPVOID
734 buffer;
735
736 status=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
737 FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),
738 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR) &buffer,0,NULL);
739 if (!status)
740 reason=AcquireString("An unknown error occurred");
741 else
742 {
743 reason=AcquireString((const char *) buffer);
744 LocalFree(buffer);
745 }
746 return(reason);
747}
748
749/*
750%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
751% %
752% %
753% %
754% N T G e t L i b r a r y E r r o r %
755% %
756% %
757% %
758%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
759%
760% Lt_dlerror() returns a pointer to a string describing the last error
761% associated with a lt_dl method. Note that this function is not thread
762% safe so it should only be used under the protection of a lock.
763%
764% The format of the NTGetLibraryError method is:
765%
766% const char *NTGetLibraryError(void)
767%
768*/
cristyd2d11ec2012-03-28 13:53:49 +0000769MagickPrivate const char *NTGetLibraryError(void)
cristy3ed852e2009-09-05 21:47:34 +0000770{
771 static char
772 last_error[MaxTextExtent];
773
774 char
775 *error;
776
777 *last_error='\0';
778 error=NTGetLastError();
779 if (error)
780 (void) CopyMagickString(last_error,error,MaxTextExtent);
781 error=DestroyString(error);
782 return(last_error);
783}
784
785/*
786%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
787% %
788% %
789% %
790% N T G e t L i b r a r y S y m b o l %
791% %
792% %
793% %
794%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
795%
796% NTGetLibrarySymbol() retrieve the procedure address of the method
797% specified by the passed character string.
798%
799% The format of the NTGetLibrarySymbol method is:
800%
801% void *NTGetLibrarySymbol(void *handle,const char *name)
802%
803% A description of each parameter follows:
804%
805% o handle: Specifies a handle to the previously loaded dynamic module.
806%
807% o name: Specifies the procedure entry point to be returned.
808%
809*/
810void *NTGetLibrarySymbol(void *handle,const char *name)
811{
812 LPFNDLLFUNC1
813 lpfnDllFunc1;
814
815 lpfnDllFunc1=(LPFNDLLFUNC1) GetProcAddress((HINSTANCE) handle,name);
816 if (!lpfnDllFunc1)
817 return((void *) NULL);
818 return((void *) lpfnDllFunc1);
819}
820
821/*
822%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
823% %
824% %
825% %
826% N T G e t M o d u l e P a t h %
827% %
828% %
829% %
830%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
831%
832% NTGetModulePath() returns the path of the specified module.
833%
834% The format of the GetModulePath method is:
835%
836% MagickBooleanType NTGetModulePath(const char *module,char *path)
837%
838% A description of each parameter follows:
839%
840% modith: the module name.
841%
842% path: the module path is returned here.
843%
844*/
cristyd2d11ec2012-03-28 13:53:49 +0000845MagickPrivate MagickBooleanType NTGetModulePath(const char *module,char *path)
cristy3ed852e2009-09-05 21:47:34 +0000846{
847 char
848 module_path[MaxTextExtent];
849
850 HMODULE
851 handle;
852
cristybb503372010-05-27 20:51:26 +0000853 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000854 length;
855
856 *path='\0';
857 handle=GetModuleHandle(module);
858 if (handle == (HMODULE) NULL)
859 return(MagickFalse);
860 length=GetModuleFileName(handle,module_path,MaxTextExtent);
861 if (length != 0)
862 GetPathComponent(module_path,HeadPath,path);
863 return(MagickTrue);
864}
865
866/*
867%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
868% %
869% %
870% %
871% N T G h o s t s c r i p t D L L %
872% %
873% %
874% %
875%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
876%
cristydefb3f02009-09-10 02:18:35 +0000877% NTGhostscriptDLL() returns the path to the most recent Ghostscript version
878% DLL. The method returns TRUE on success otherwise FALSE.
cristy3ed852e2009-09-05 21:47:34 +0000879%
880% The format of the NTGhostscriptDLL method is:
881%
cristyfc0f64b2009-09-09 18:57:08 +0000882% int NTGhostscriptDLL(char *path,int length)
cristy3ed852e2009-09-05 21:47:34 +0000883%
884% A description of each parameter follows:
885%
cristyfc0f64b2009-09-09 18:57:08 +0000886% o path: return the Ghostscript DLL path here.
cristy3ed852e2009-09-05 21:47:34 +0000887%
cristyfc0f64b2009-09-09 18:57:08 +0000888% o length: the buffer length.
cristy3ed852e2009-09-05 21:47:34 +0000889%
890*/
891
cristy945364f2012-03-14 11:13:17 +0000892static int NTGetRegistryValue(HKEY root,const char *key,DWORD flags,const char *name,
cristyfc0f64b2009-09-09 18:57:08 +0000893 char *value,int *length)
cristy3ed852e2009-09-05 21:47:34 +0000894{
cristyfc0f64b2009-09-09 18:57:08 +0000895 BYTE
896 byte,
cristy3ed852e2009-09-05 21:47:34 +0000897 *p;
898
cristyfc0f64b2009-09-09 18:57:08 +0000899 DWORD
900 extent,
901 type;
cristy3ed852e2009-09-05 21:47:34 +0000902
cristy3ed852e2009-09-05 21:47:34 +0000903 HKEY
904 hkey;
905
cristy3ed852e2009-09-05 21:47:34 +0000906 LONG
cristyfc0f64b2009-09-09 18:57:08 +0000907 status;
cristy3ed852e2009-09-05 21:47:34 +0000908
cristyfc0f64b2009-09-09 18:57:08 +0000909 /*
cristydefb3f02009-09-10 02:18:35 +0000910 Get a registry value: key = root\\key, named value = name.
911 */
cristy945364f2012-03-14 11:13:17 +0000912 if (RegOpenKeyExA(root,key,0,KEY_READ | flags,&hkey) != ERROR_SUCCESS)
cristyfc0f64b2009-09-09 18:57:08 +0000913 return(1); /* no match */
914 p=(BYTE *) value;
915 type=REG_SZ;
916 extent=(*length);
917 if (p == (BYTE *) NULL)
cristydefb3f02009-09-10 02:18:35 +0000918 p=(&byte); /* ERROR_MORE_DATA only if value is NULL */
cristyfc0f64b2009-09-09 18:57:08 +0000919 status=RegQueryValueExA(hkey,(char *) name,0,&type,p,&extent);
920 RegCloseKey(hkey);
921 if (status == ERROR_SUCCESS)
cristy3ed852e2009-09-05 21:47:34 +0000922 {
cristyfc0f64b2009-09-09 18:57:08 +0000923 *length=extent;
924 return(0); /* return the match */
925 }
926 if (status == ERROR_MORE_DATA)
927 {
928 *length=extent;
cristydefb3f02009-09-10 02:18:35 +0000929 return(-1); /* buffer not large enough */
cristy3ed852e2009-09-05 21:47:34 +0000930 }
931 return(1); /* not found */
932}
933
cristy945364f2012-03-14 11:13:17 +0000934static int NTLocateGhostscript(DWORD flags,const char **product_family,int *major_version,
cristyfc0f64b2009-09-09 18:57:08 +0000935 int *minor_version)
cristy3ed852e2009-09-05 21:47:34 +0000936{
cristyfc0f64b2009-09-09 18:57:08 +0000937 int
938 i;
cristy3ed852e2009-09-05 21:47:34 +0000939
cristyfc0f64b2009-09-09 18:57:08 +0000940 MagickBooleanType
941 status;
942
943 static const char
944 *products[4] =
945 {
946 "GPL Ghostscript",
947 "GNU Ghostscript",
948 "AFPL Ghostscript",
cristy82b15832009-10-06 19:17:37 +0000949 "Aladdin Ghostscript"
cristyfc0f64b2009-09-09 18:57:08 +0000950 };
951
952 /*
953 Find the most recent version of Ghostscript.
954 */
955 status=FALSE;
956 *product_family=NULL;
957 *major_version=5;
958 *minor_version=49; /* min version of Ghostscript is 5.50 */
cristybb503372010-05-27 20:51:26 +0000959 for (i=0; i < (ssize_t) (sizeof(products)/sizeof(products[0])); i++)
cristyfc0f64b2009-09-09 18:57:08 +0000960 {
961 char
962 key[MaxTextExtent];
963
964 HKEY
965 hkey,
966 root;
967
cristye66bcb42009-09-17 13:31:08 +0000968 REGSAM
969 mode;
970
cristyb51dff52011-05-19 16:55:47 +0000971 (void) FormatLocaleString(key,MaxTextExtent,"SOFTWARE\\%s",products[i]);
cristyfc0f64b2009-09-09 18:57:08 +0000972 root=HKEY_LOCAL_MACHINE;
cristy945364f2012-03-14 11:13:17 +0000973 mode=KEY_READ | flags;
cristye66bcb42009-09-17 13:31:08 +0000974 if (RegOpenKeyExA(root,key,0,mode,&hkey) == ERROR_SUCCESS)
cristyfc0f64b2009-09-09 18:57:08 +0000975 {
976 DWORD
977 extent;
978
979 int
980 j;
981
982 /*
983 Now enumerate the keys.
984 */
985 extent=sizeof(key)/sizeof(char);
986 for (j=0; RegEnumKeyA(hkey,j,key,extent) == ERROR_SUCCESS; j++)
987 {
988 int
989 major,
990 minor;
991
992 major=0;
993 minor=0;
994 if (sscanf(key,"%d.%d",&major,&minor) != 2)
995 continue;
996 if ((major > *major_version) || ((major == *major_version) &&
997 (minor > *minor_version)))
998 {
999 *product_family=products[i];
1000 *major_version=major;
1001 *minor_version=minor;
cristy37f63772009-11-16 17:06:36 +00001002 status=TRUE;
cristyfc0f64b2009-09-09 18:57:08 +00001003 }
cristyfc0f64b2009-09-09 18:57:08 +00001004 }
cristye66bcb42009-09-17 13:31:08 +00001005 (void) RegCloseKey(hkey);
1006 }
1007 }
cristy37f63772009-11-16 17:06:36 +00001008 if (status == FALSE)
cristyfc0f64b2009-09-09 18:57:08 +00001009 {
1010 *major_version=0;
1011 *minor_version=0;
1012 }
1013 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"Ghostscript (%s) "
1014 "version %d.%02d",*product_family,*major_version,*minor_version);
1015 return(status);
1016}
1017
cristy945364f2012-03-14 11:13:17 +00001018static BOOL NTIs64BitPlatform()
1019{
1020#if defined(_WIN64)
1021 return(TRUE);
1022#else
1023 BOOL is64=FALSE;
1024 return(IsWow64Process(GetCurrentProcess(), &is64) && is64);
1025#endif
1026}
1027
1028static int NTGhostscriptGetString(const char *name,BOOL *is_64_bit,char *value,
cristyfc0f64b2009-09-09 18:57:08 +00001029 const size_t length)
1030{
cristy3ed852e2009-09-05 21:47:34 +00001031 char
cristy3ed852e2009-09-05 21:47:34 +00001032 key[MaxTextExtent];
1033
1034 int
cristyfc0f64b2009-09-09 18:57:08 +00001035 i,
1036 extent;
cristy82b15832009-10-06 19:17:37 +00001037
cristyfc0f64b2009-09-09 18:57:08 +00001038 static const char
cristydefb3f02009-09-10 02:18:35 +00001039 *product_family = (const char *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00001040
cristy945364f2012-03-14 11:13:17 +00001041 static BOOL
1042 is_64_bit_version = FALSE;
1043
cristyfc0f64b2009-09-09 18:57:08 +00001044 static int
cristy945364f2012-03-14 11:13:17 +00001045 flags=0,
cristyfc0f64b2009-09-09 18:57:08 +00001046 major_version=0,
1047 minor_version=0;
cristy3ed852e2009-09-05 21:47:34 +00001048
cristyfc0f64b2009-09-09 18:57:08 +00001049 struct
1050 {
1051 const HKEY
1052 hkey;
cristy3ed852e2009-09-05 21:47:34 +00001053
cristyfc0f64b2009-09-09 18:57:08 +00001054 const char
1055 *name;
1056 }
1057 hkeys[2] =
1058 {
1059 { HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
1060 { HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" }
1061 };
1062
1063 /*
1064 Get a string from the installed Ghostscript.
1065 */
cristy945364f2012-03-14 11:13:17 +00001066 if (is_64_bit!=NULL)
1067 *is_64_bit=FALSE;
cristydefb3f02009-09-10 02:18:35 +00001068 *value='\0';
cristyfc0f64b2009-09-09 18:57:08 +00001069 if (product_family == NULL)
cristy945364f2012-03-14 11:13:17 +00001070 {
1071 flags=NTIs64BitPlatform() ? KEY_WOW64_64KEY : 0;
1072 (void) NTLocateGhostscript(flags,&product_family,&major_version,&minor_version);
1073 if (product_family == NULL)
1074 {
1075 if (flags!=0)
1076 {
1077 /* We are running on a 64 bit platform - check for a 32 bit Ghostscript, too */
1078 flags=KEY_WOW64_32KEY;
1079 (void) NTLocateGhostscript(flags,&product_family,&major_version,&minor_version);
1080 }
1081 }
1082 else
1083 is_64_bit_version=NTIs64BitPlatform();
1084 }
1085 if (is_64_bit!=NULL)
1086 *is_64_bit=is_64_bit_version;
cristyfc0f64b2009-09-09 18:57:08 +00001087 if (product_family == NULL)
1088 return(FALSE);
cristyb51dff52011-05-19 16:55:47 +00001089 (void) FormatLocaleString(key,MaxTextExtent,"SOFTWARE\\%s\\%d.%02d",
cristyfc0f64b2009-09-09 18:57:08 +00001090 product_family,major_version,minor_version);
cristybb503372010-05-27 20:51:26 +00001091 for (i=0; i < (ssize_t) (sizeof(hkeys)/sizeof(hkeys[0])); i++)
cristyfc0f64b2009-09-09 18:57:08 +00001092 {
cristy76319442009-09-22 02:04:05 +00001093 extent=(int) length;
cristy945364f2012-03-14 11:13:17 +00001094 if (NTGetRegistryValue(hkeys[i].hkey,key,flags,name,value,&extent) == 0)
cristyfc0f64b2009-09-09 18:57:08 +00001095 {
1096 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1097 "registry: \"%s\\%s\\%s\"=\"%s\"",hkeys[i].name,key,name,value);
1098 return(TRUE);
1099 }
1100 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1101 "registry: \"%s\\%s\\%s\" (failed)",hkeys[i].name,key,name);
1102 }
cristy3ed852e2009-09-05 21:47:34 +00001103 return(FALSE);
1104}
1105
cristyd2d11ec2012-03-28 13:53:49 +00001106MagickPrivate int NTGhostscriptDLL(char *path,int length)
cristy3ed852e2009-09-05 21:47:34 +00001107{
cristy4c11ed82009-09-11 03:36:46 +00001108 static char
1109 dll[MaxTextExtent] = { "" };
cristy3ed852e2009-09-05 21:47:34 +00001110
cristy945364f2012-03-14 11:13:17 +00001111 static BOOL
1112 is_64_bit_version;
1113
cristy3ed852e2009-09-05 21:47:34 +00001114 *path='\0';
cristy4c11ed82009-09-11 03:36:46 +00001115 if ((*dll == '\0') &&
cristy945364f2012-03-14 11:13:17 +00001116 (NTGhostscriptGetString("GS_DLL",&is_64_bit_version,dll,sizeof(dll)) == FALSE))
cristy106919c2009-09-11 03:46:56 +00001117 return(FALSE);
cristy945364f2012-03-14 11:13:17 +00001118
1119#if defined(_WIN64)
1120 if (!is_64_bit_version)
1121 return(FALSE);
1122#else
1123 if (is_64_bit_version)
1124 return(FALSE);
1125#endif
cristy4c11ed82009-09-11 03:36:46 +00001126 (void) CopyMagickString(path,dll,length);
cristy3ed852e2009-09-05 21:47:34 +00001127 return(TRUE);
1128}
1129
1130/*
1131%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1132% %
1133% %
1134% %
1135% N T G h o s t s c r i p t D L L V e c t o r s %
1136% %
1137% %
1138% %
1139%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1140%
cristydefb3f02009-09-10 02:18:35 +00001141% NTGhostscriptDLLVectors() returns a GhostInfo structure that includes
1142% function vectors to invoke Ghostscript DLL functions. A null pointer is
1143% returned if there is an error when loading the DLL or retrieving the
1144% function vectors.
cristy3ed852e2009-09-05 21:47:34 +00001145%
1146% The format of the NTGhostscriptDLLVectors method is:
1147%
cristydefb3f02009-09-10 02:18:35 +00001148% const GhostInfo *NTGhostscriptDLLVectors(void)
cristy3ed852e2009-09-05 21:47:34 +00001149%
1150*/
cristyd2d11ec2012-03-28 13:53:49 +00001151MagickPrivate const GhostInfo *NTGhostscriptDLLVectors(void)
cristy3ed852e2009-09-05 21:47:34 +00001152{
cristyfc0f64b2009-09-09 18:57:08 +00001153 if (NTGhostscriptLoadDLL() == FALSE)
cristydefb3f02009-09-10 02:18:35 +00001154 return((GhostInfo *) NULL);
1155 return(&ghost_info);
cristy3ed852e2009-09-05 21:47:34 +00001156}
1157
1158/*
1159%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1160% %
1161% %
1162% %
1163% N T G h o s t s c r i p t E X E %
1164% %
1165% %
1166% %
1167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1168%
1169% NTGhostscriptEXE() obtains the path to the latest Ghostscript executable.
cristyfc0f64b2009-09-09 18:57:08 +00001170% The method returns FALSE if a full path value is not obtained and returns
1171% a default path of gswin32c.exe.
cristy3ed852e2009-09-05 21:47:34 +00001172%
1173% The format of the NTGhostscriptEXE method is:
1174%
cristyfc0f64b2009-09-09 18:57:08 +00001175% int NTGhostscriptEXE(char *path,int length)
cristy3ed852e2009-09-05 21:47:34 +00001176%
1177% A description of each parameter follows:
1178%
cristyfc0f64b2009-09-09 18:57:08 +00001179% o path: return the Ghostscript executable path here.
cristy3ed852e2009-09-05 21:47:34 +00001180%
cristyb32b90a2009-09-07 21:45:48 +00001181% o length: length of buffer.
cristy3ed852e2009-09-05 21:47:34 +00001182%
1183*/
cristyd2d11ec2012-03-28 13:53:49 +00001184MagickPrivate int NTGhostscriptEXE(char *path,int length)
cristy3ed852e2009-09-05 21:47:34 +00001185{
cristy4c11ed82009-09-11 03:36:46 +00001186 register char
cristy3ed852e2009-09-05 21:47:34 +00001187 *p;
1188
cristyfc0f64b2009-09-09 18:57:08 +00001189 static char
cristy4c11ed82009-09-11 03:36:46 +00001190 program[MaxTextExtent] = { "" };
cristy3ed852e2009-09-05 21:47:34 +00001191
cristy945364f2012-03-14 11:13:17 +00001192 static BOOL
1193 is_64_bit_version = FALSE;
1194
cristyb32b90a2009-09-07 21:45:48 +00001195 (void) CopyMagickString(path,"gswin32c.exe",length);
cristy4c11ed82009-09-11 03:36:46 +00001196 if ((*program == '\0') &&
cristy945364f2012-03-14 11:13:17 +00001197 (NTGhostscriptGetString("GS_DLL",&is_64_bit_version,program,sizeof(program)) == FALSE))
cristyb32b90a2009-09-07 21:45:48 +00001198 return(FALSE);
cristy4c11ed82009-09-11 03:36:46 +00001199 p=strrchr(program,'\\');
cristy7ba1b042011-02-05 19:07:50 +00001200 if (p != (char *) NULL)
cristy4c11ed82009-09-11 03:36:46 +00001201 {
1202 p++;
1203 *p='\0';
cristy945364f2012-03-14 11:13:17 +00001204 (void) ConcatenateMagickString(program,is_64_bit_version ? "gswin64c.exe" : "gswin32c.exe",sizeof(program));
cristy4c11ed82009-09-11 03:36:46 +00001205 }
1206 (void) CopyMagickString(path,program,length);
cristyb32b90a2009-09-07 21:45:48 +00001207 return(TRUE);
cristy3ed852e2009-09-05 21:47:34 +00001208}
1209
1210/*
1211%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1212% %
1213% %
1214% %
1215% N T G h o s t s c r i p t F o n t s %
1216% %
1217% %
1218% %
1219%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1220%
cristyfc0f64b2009-09-09 18:57:08 +00001221% NTGhostscriptFonts() obtains the path to the Ghostscript fonts. The method
1222% returns FALSE if it cannot determine the font path.
cristy3ed852e2009-09-05 21:47:34 +00001223%
1224% The format of the NTGhostscriptFonts method is:
1225%
cristyfc0f64b2009-09-09 18:57:08 +00001226% int NTGhostscriptFonts(char *path, int length)
cristy3ed852e2009-09-05 21:47:34 +00001227%
1228% A description of each parameter follows:
1229%
cristyfc0f64b2009-09-09 18:57:08 +00001230% o path: return the font path here.
cristy3ed852e2009-09-05 21:47:34 +00001231%
cristyfc0f64b2009-09-09 18:57:08 +00001232% o length: length of the path buffer.
cristy3ed852e2009-09-05 21:47:34 +00001233%
1234*/
cristyd2d11ec2012-03-28 13:53:49 +00001235MagickPrivate int NTGhostscriptFonts(char *path,int length)
cristy3ed852e2009-09-05 21:47:34 +00001236{
1237 char
1238 buffer[MaxTextExtent],
1239 filename[MaxTextExtent];
1240
cristy3ed852e2009-09-05 21:47:34 +00001241 register char
1242 *p,
1243 *q;
1244
1245 *path='\0';
cristy945364f2012-03-14 11:13:17 +00001246 if (NTGhostscriptGetString("GS_LIB",NULL,buffer,MaxTextExtent) == FALSE)
cristy3ed852e2009-09-05 21:47:34 +00001247 return(FALSE);
1248 for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
1249 {
1250 (void) CopyMagickString(path,p+1,length+1);
1251 q=strchr(path,DirectoryListSeparator);
1252 if (q != (char *) NULL)
1253 *q='\0';
cristyb51dff52011-05-19 16:55:47 +00001254 (void) FormatLocaleString(filename,MaxTextExtent,"%s%sfonts.dir",path,
cristy3ed852e2009-09-05 21:47:34 +00001255 DirectorySeparator);
1256 if (IsPathAccessible(filename) != MagickFalse)
1257 return(TRUE);
1258 }
1259 return(FALSE);
1260}
1261
1262/*
1263%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1264% %
1265% %
1266% %
1267% N T G h o s t s c r i p t L o a d D L L %
1268% %
1269% %
1270% %
1271%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1272%
1273% NTGhostscriptLoadDLL() attempts to load the Ghostscript DLL and returns
cristyfc0f64b2009-09-09 18:57:08 +00001274% TRUE if it succeeds.
cristy3ed852e2009-09-05 21:47:34 +00001275%
1276% The format of the NTGhostscriptLoadDLL method is:
1277%
1278% int NTGhostscriptLoadDLL(void)
1279%
1280*/
cristyd2d11ec2012-03-28 13:53:49 +00001281MagickPrivate int NTGhostscriptLoadDLL(void)
cristy3ed852e2009-09-05 21:47:34 +00001282{
1283 char
cristyfc0f64b2009-09-09 18:57:08 +00001284 path[MaxTextExtent];
cristy3ed852e2009-09-05 21:47:34 +00001285
cristydefb3f02009-09-10 02:18:35 +00001286 if (ghost_handle != (void *) NULL)
cristyfc0f64b2009-09-09 18:57:08 +00001287 return(TRUE);
1288 if (NTGhostscriptDLL(path,sizeof(path)) == FALSE)
1289 return(FALSE);
cristydefb3f02009-09-10 02:18:35 +00001290 ghost_handle=lt_dlopen(path);
1291 if (ghost_handle == (void *) NULL)
cristyfc0f64b2009-09-09 18:57:08 +00001292 return(FALSE);
cristydefb3f02009-09-10 02:18:35 +00001293 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1294 ghost_info.exit=(int (MagickDLLCall *)(gs_main_instance*))
1295 lt_dlsym(ghost_handle,"gsapi_exit");
1296 ghost_info.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,int,
1297 char **)) (lt_dlsym(ghost_handle,"gsapi_init_with_args"));
1298 ghost_info.new_instance=(int (MagickDLLCall *)(gs_main_instance **,void *)) (
1299 lt_dlsym(ghost_handle,"gsapi_new_instance"));
1300 ghost_info.run_string=(int (MagickDLLCall *)(gs_main_instance *,const char *,
1301 int,int *)) (lt_dlsym(ghost_handle,"gsapi_run_string"));
1302 ghost_info.delete_instance=(void (MagickDLLCall *) (gs_main_instance *)) (
1303 lt_dlsym(ghost_handle,"gsapi_delete_instance"));
1304 if ((ghost_info.exit == NULL) || (ghost_info.init_with_args == NULL) ||
1305 (ghost_info.new_instance == NULL) || (ghost_info.run_string == NULL) ||
1306 (ghost_info.delete_instance == NULL))
cristyfc0f64b2009-09-09 18:57:08 +00001307 return(FALSE);
1308 return(TRUE);
cristy3ed852e2009-09-05 21:47:34 +00001309}
1310
1311/*
1312%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1313% %
1314% %
1315% %
1316% N T G h o s t s c r i p t U n L o a d D L L %
1317% %
1318% %
1319% %
1320%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1321%
cristyfc0f64b2009-09-09 18:57:08 +00001322% NTGhostscriptUnLoadDLL() unloads the Ghostscript DLL and returns TRUE if
1323% it succeeds.
cristy3ed852e2009-09-05 21:47:34 +00001324%
1325% The format of the NTGhostscriptUnLoadDLL method is:
1326%
1327% int NTGhostscriptUnLoadDLL(void)
1328%
1329*/
cristyd2d11ec2012-03-28 13:53:49 +00001330MagickPrivate int NTGhostscriptUnLoadDLL(void)
cristy3ed852e2009-09-05 21:47:34 +00001331{
cristyfc0f64b2009-09-09 18:57:08 +00001332 int
1333 status;
1334
cristydefb3f02009-09-10 02:18:35 +00001335 if (ghost_handle == (void *) NULL)
cristyfc0f64b2009-09-09 18:57:08 +00001336 return(FALSE);
cristydefb3f02009-09-10 02:18:35 +00001337 status=lt_dlclose(ghost_handle);
1338 ghost_handle=(void *) NULL;
1339 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
cristyfc0f64b2009-09-09 18:57:08 +00001340 return(status);
cristy3ed852e2009-09-05 21:47:34 +00001341}
1342
1343/*
1344%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1345% %
1346% %
1347% %
1348% N T I n i t i a l i z e L i b r a r y %
1349% %
1350% %
1351% %
1352%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1353%
1354% NTInitializeLibrary() initializes the dynamic module loading subsystem.
1355%
1356% The format of the NTInitializeLibrary method is:
1357%
1358% int NTInitializeLibrary(void)
1359%
1360*/
cristyd2d11ec2012-03-28 13:53:49 +00001361MagickPrivate int NTInitializeLibrary(void)
cristy3ed852e2009-09-05 21:47:34 +00001362{
1363 return(0);
1364}
1365
1366/*
1367%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1368% %
1369% %
1370% %
1371+ N T M a p M e m o r y %
1372% %
1373% %
1374% %
1375%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1376%
1377% Mmap() emulates the Unix method of the same name.
1378%
1379% The format of the NTMapMemory method is:
1380%
cristyd2d11ec2012-03-28 13:53:49 +00001381% MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
cristy3ed852e2009-09-05 21:47:34 +00001382% int access,int file,MagickOffsetType offset)
1383%
1384*/
cristyd2d11ec2012-03-28 13:53:49 +00001385MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
cristy3ed852e2009-09-05 21:47:34 +00001386 int flags,int file,MagickOffsetType offset)
1387{
1388 DWORD
1389 access_mode,
1390 high_length,
1391 high_offset,
1392 low_length,
1393 low_offset,
1394 protection_mode;
1395
1396 HANDLE
1397 file_handle,
1398 map_handle;
1399
1400 void
1401 *map;
1402
cristy3b743bb2009-09-14 16:07:59 +00001403 (void) address;
cristy3ed852e2009-09-05 21:47:34 +00001404 access_mode=0;
1405 file_handle=INVALID_HANDLE_VALUE;
1406 low_length=(DWORD) (length & 0xFFFFFFFFUL);
1407 high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
1408 map_handle=INVALID_HANDLE_VALUE;
1409 map=(void *) NULL;
1410 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
1411 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
1412 protection_mode=0;
1413 if (protection & PROT_WRITE)
1414 {
1415 access_mode=FILE_MAP_WRITE;
1416 if (!(flags & MAP_PRIVATE))
1417 protection_mode=PAGE_READWRITE;
1418 else
1419 {
1420 access_mode=FILE_MAP_COPY;
1421 protection_mode=PAGE_WRITECOPY;
1422 }
1423 }
1424 else
1425 if (protection & PROT_READ)
1426 {
1427 access_mode=FILE_MAP_READ;
1428 protection_mode=PAGE_READONLY;
1429 }
1430 if ((file == -1) && (flags & MAP_ANONYMOUS))
1431 file_handle=INVALID_HANDLE_VALUE;
1432 else
1433 file_handle=(HANDLE) _get_osfhandle(file);
1434 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
1435 low_length,0);
1436 if (map_handle)
1437 {
1438 map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
1439 length);
1440 CloseHandle(map_handle);
1441 }
1442 if (map == (void *) NULL)
1443 return((void *) MAP_FAILED);
1444 return((void *) ((char *) map));
1445}
1446
1447/*
1448%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1449% %
1450% %
1451% %
1452% N T O p e n D i r e c t o r y %
1453% %
1454% %
1455% %
1456%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1457%
1458% NTOpenDirectory() opens the directory named by filename and associates a
1459% directory stream with it.
1460%
1461% The format of the NTOpenDirectory method is:
1462%
1463% DIR *NTOpenDirectory(const char *path)
1464%
1465% A description of each parameter follows:
1466%
1467% o entry: Specifies a pointer to a DIR structure.
1468%
1469*/
cristyd2d11ec2012-03-28 13:53:49 +00001470MagickPrivate DIR *NTOpenDirectory(const char *path)
cristy3ed852e2009-09-05 21:47:34 +00001471{
1472 char
1473 file_specification[MaxTextExtent];
1474
1475 DIR
1476 *entry;
1477
1478 size_t
1479 length;
1480
1481 assert(path != (const char *) NULL);
1482 length=CopyMagickString(file_specification,path,MaxTextExtent);
cristy37e0b382011-06-07 13:31:21 +00001483 if (length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00001484 return((DIR *) NULL);
1485 length=ConcatenateMagickString(file_specification,DirectorySeparator,
1486 MaxTextExtent);
cristy37e0b382011-06-07 13:31:21 +00001487 if (length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00001488 return((DIR *) NULL);
cristy73bd4a52010-10-05 11:24:23 +00001489 entry=(DIR *) AcquireMagickMemory(sizeof(DIR));
cristy3ed852e2009-09-05 21:47:34 +00001490 if (entry != (DIR *) NULL)
1491 {
1492 entry->firsttime=TRUE;
1493 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1494 }
1495 if (entry->hSearch == INVALID_HANDLE_VALUE)
1496 {
1497 length=ConcatenateMagickString(file_specification,"\\*.*",MaxTextExtent);
cristy37e0b382011-06-07 13:31:21 +00001498 if (length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00001499 {
1500 entry=(DIR *) RelinquishMagickMemory(entry);
1501 return((DIR *) NULL);
1502 }
1503 entry->hSearch=FindFirstFile(file_specification,&entry->Win32FindData);
1504 if (entry->hSearch == INVALID_HANDLE_VALUE)
1505 {
1506 entry=(DIR *) RelinquishMagickMemory(entry);
1507 return((DIR *) NULL);
1508 }
1509 }
1510 return(entry);
1511}
1512
1513/*
1514%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1515% %
1516% %
1517% %
1518% N T O p e n L i b r a r y %
1519% %
1520% %
1521% %
1522%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1523%
1524% NTOpenLibrary() loads a dynamic module into memory and returns a handle that
1525% can be used to access the various procedures in the module.
1526%
1527% The format of the NTOpenLibrary method is:
1528%
1529% void *NTOpenLibrary(const char *filename)
1530%
1531% A description of each parameter follows:
1532%
1533% o path: Specifies a pointer to string representing dynamic module that
1534% is to be loaded.
1535%
1536*/
1537
1538static const char *GetSearchPath( void )
1539{
1540#if defined(MAGICKCORE_LTDL_DELEGATE)
1541 return(lt_dlgetsearchpath());
1542#else
1543 return(lt_slsearchpath);
1544#endif
1545}
1546
cristyd2d11ec2012-03-28 13:53:49 +00001547MagickPrivate void *NTOpenLibrary(const char *filename)
cristy3ed852e2009-09-05 21:47:34 +00001548{
1549#define MaxPathElements 31
1550
1551 char
1552 buffer[MaxTextExtent];
1553
1554 int
1555 index;
1556
1557 register const char
1558 *p,
1559 *q;
1560
1561 register int
1562 i;
1563
1564 UINT
1565 mode;
1566
1567 void
1568 *handle;
1569
1570 mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
1571 handle=(void *) LoadLibraryEx(filename,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1572 if ((handle != (void *) NULL) || (GetSearchPath() == (char *) NULL))
1573 {
1574 SetErrorMode(mode);
1575 return(handle);
1576 }
1577 p=(char *) GetSearchPath();
1578 index=0;
1579 while (index < MaxPathElements)
1580 {
1581 q=strchr(p,DirectoryListSeparator);
1582 if (q == (char *) NULL)
1583 {
1584 (void) CopyMagickString(buffer,p,MaxTextExtent);
1585 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
1586 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
1587 handle=(void *) LoadLibraryEx(buffer,NULL,
1588 LOAD_WITH_ALTERED_SEARCH_PATH);
1589 break;
1590 }
1591 i=q-p;
1592 (void) CopyMagickString(buffer,p,i+1);
1593 (void) ConcatenateMagickString(buffer,"\\",MaxTextExtent);
1594 (void) ConcatenateMagickString(buffer,filename,MaxTextExtent);
1595 handle=(void *) LoadLibraryEx(buffer,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1596 if (handle != (void *) NULL)
1597 break;
1598 p=q+1;
1599 }
1600 SetErrorMode(mode);
1601 return(handle);
1602}
1603
1604/*
1605%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1606% %
1607% %
1608% %
1609% N T R e a d D i r e c t o r y %
1610% %
1611% %
1612% %
1613%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1614%
1615% NTReadDirectory() returns a pointer to a structure representing the
1616% directory entry at the current position in the directory stream to which
1617% entry refers.
1618%
1619% The format of the NTReadDirectory
1620%
1621% NTReadDirectory(entry)
1622%
1623% A description of each parameter follows:
1624%
1625% o entry: Specifies a pointer to a DIR structure.
1626%
1627*/
cristyd2d11ec2012-03-28 13:53:49 +00001628MagickPrivate struct dirent *NTReadDirectory(DIR *entry)
cristy3ed852e2009-09-05 21:47:34 +00001629{
1630 int
1631 status;
1632
1633 size_t
1634 length;
1635
1636 if (entry == (DIR *) NULL)
1637 return((struct dirent *) NULL);
1638 if (!entry->firsttime)
1639 {
1640 status=FindNextFile(entry->hSearch,&entry->Win32FindData);
1641 if (status == 0)
1642 return((struct dirent *) NULL);
1643 }
1644 length=CopyMagickString(entry->file_info.d_name,
1645 entry->Win32FindData.cFileName,sizeof(entry->file_info.d_name));
1646 if (length >= sizeof(entry->file_info.d_name))
1647 return((struct dirent *) NULL);
1648 entry->firsttime=FALSE;
1649 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
1650 return(&entry->file_info);
1651}
1652
1653/*
1654%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1655% %
1656% %
1657% %
1658% N T R e g i s t r y K e y L o o k u p %
1659% %
1660% %
1661% %
1662%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1663%
1664% NTRegistryKeyLookup() returns ImageMagick installation path settings
1665% stored in the Windows Registry. Path settings are specific to the
1666% installed ImageMagick version so that multiple Image Magick installations
1667% may coexist.
1668%
1669% Values are stored in the registry under a base path path similar to
cristyf7836bf2012-02-20 16:32:47 +00001670% "HKEY_LOCAL_MACHINE/SOFTWARE\ImageMagick\6.7.4\Q:16" or
1671% "HKEY_CURRENT_USER/SOFTWARE\ImageMagick\6.7.4\Q:16". The provided subkey
cristy3ed852e2009-09-05 21:47:34 +00001672% is appended to this base path to form the full key.
1673%
1674% The format of the NTRegistryKeyLookup method is:
1675%
1676% unsigned char *NTRegistryKeyLookup(const char *subkey)
1677%
1678% A description of each parameter follows:
1679%
1680% o subkey: Specifies a string that identifies the registry object.
1681% Currently supported sub-keys include: "BinPath", "ConfigurePath",
1682% "LibPath", "CoderModulesPath", "FilterModulesPath", "SharePath".
1683%
1684*/
cristyd2d11ec2012-03-28 13:53:49 +00001685MagickPrivate unsigned char *NTRegistryKeyLookup(const char *subkey)
cristy3ed852e2009-09-05 21:47:34 +00001686{
1687 char
1688 package_key[MaxTextExtent];
1689
1690 DWORD
1691 size,
1692 type;
1693
1694 HKEY
1695 registry_key;
1696
1697 LONG
1698 status;
1699
1700 unsigned char
1701 *value;
1702
1703 /*
1704 Look-up base key.
1705 */
cristyb51dff52011-05-19 16:55:47 +00001706 (void) FormatLocaleString(package_key,MaxTextExtent,"SOFTWARE\\%s\\%s\\Q:%d",
cristy3ed852e2009-09-05 21:47:34 +00001707 MagickPackageName,MagickLibVersionText,MAGICKCORE_QUANTUM_DEPTH);
1708 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",package_key);
1709 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1710 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,package_key,0,KEY_READ,&registry_key);
1711 if (status != ERROR_SUCCESS)
cristyd06bf862011-12-21 02:18:45 +00001712 status=RegOpenKeyExA(HKEY_CURRENT_USER,package_key,0,KEY_READ,
1713 &registry_key);
1714 if (status != ERROR_SUCCESS)
cristy3ed852e2009-09-05 21:47:34 +00001715 {
1716 registry_key=(HKEY) INVALID_HANDLE_VALUE;
1717 return((unsigned char *) NULL);
1718 }
1719 /*
1720 Look-up sub key.
1721 */
1722 size=32;
1723 value=(unsigned char *) AcquireQuantumMemory(size,sizeof(*value));
1724 if (value == (unsigned char *) NULL)
1725 {
1726 RegCloseKey(registry_key);
1727 return((unsigned char *) NULL);
1728 }
1729 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",subkey);
1730 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1731 if ((status == ERROR_MORE_DATA) && (type == REG_SZ))
1732 {
1733 value=(unsigned char *) ResizeQuantumMemory(value,size,sizeof(*value));
1734 if (value == (BYTE *) NULL)
1735 {
1736 RegCloseKey(registry_key);
1737 return((unsigned char *) NULL);
1738 }
1739 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
1740 }
1741 RegCloseKey(registry_key);
1742 if ((type != REG_SZ) || (status != ERROR_SUCCESS))
1743 value=(unsigned char *) RelinquishMagickMemory(value);
1744 return((unsigned char *) value);
1745}
1746
1747/*
1748%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1749% %
1750% %
1751% %
1752% N T R e p o r t E v e n t %
1753% %
1754% %
1755% %
1756%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1757%
1758% NTReportEvent() reports an event.
1759%
1760% The format of the NTReportEvent method is:
1761%
1762% MagickBooleanType NTReportEvent(const char *event,
1763% const MagickBooleanType error)
1764%
1765% A description of each parameter follows:
1766%
1767% o event: the event.
1768%
1769% o error: MagickTrue the event is an error.
1770%
1771*/
cristyd2d11ec2012-03-28 13:53:49 +00001772MagickPrivate MagickBooleanType NTReportEvent(const char *event,
cristy3ed852e2009-09-05 21:47:34 +00001773 const MagickBooleanType error)
1774{
1775 const char
1776 *events[1];
1777
1778 HANDLE
1779 handle;
1780
1781 WORD
1782 type;
1783
1784 handle=RegisterEventSource(NULL,MAGICKCORE_PACKAGE_NAME);
1785 if (handle == NULL)
1786 return(MagickFalse);
1787 events[0]=event;
1788 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
1789 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
1790 DeregisterEventSource(handle);
1791 return(MagickTrue);
1792}
1793
1794/*
1795%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1796% %
1797% %
1798% %
1799% N T R e s o u r c e T o B l o b %
1800% %
1801% %
1802% %
1803%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1804%
1805% NTResourceToBlob() returns a blob containing the contents of the resource
1806% in the current executable specified by the id parameter. This currently
1807% used to retrieve MGK files tha have been embedded into the various command
1808% line utilities.
1809%
1810% The format of the NTResourceToBlob method is:
1811%
1812% unsigned char *NTResourceToBlob(const char *id)
1813%
1814% A description of each parameter follows:
1815%
1816% o id: Specifies a string that identifies the resource.
1817%
1818*/
cristyd2d11ec2012-03-28 13:53:49 +00001819MagickPrivate unsigned char *NTResourceToBlob(const char *id)
cristy3ed852e2009-09-05 21:47:34 +00001820{
1821 char
1822 path[MaxTextExtent];
1823
1824 DWORD
1825 length;
1826
1827 HGLOBAL
1828 global;
1829
1830 HMODULE
1831 handle;
1832
1833 HRSRC
1834 resource;
1835
1836 unsigned char
1837 *blob,
1838 *value;
1839
1840 assert(id != (const char *) NULL);
1841 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
cristyb51dff52011-05-19 16:55:47 +00001842 (void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",GetClientPath(),
cristy3ed852e2009-09-05 21:47:34 +00001843 DirectorySeparator,GetClientName());
1844 if (IsPathAccessible(path) != MagickFalse)
1845 handle=GetModuleHandle(path);
1846 else
1847 handle=GetModuleHandle(0);
1848 if (!handle)
1849 return((unsigned char *) NULL);
1850 resource=FindResource(handle,id,"IMAGEMAGICK");
1851 if (!resource)
1852 return((unsigned char *) NULL);
1853 global=LoadResource(handle,resource);
1854 if (!global)
1855 return((unsigned char *) NULL);
1856 length=SizeofResource(handle,resource);
1857 value=(unsigned char *) LockResource(global);
1858 if (!value)
1859 {
1860 FreeResource(global);
1861 return((unsigned char *) NULL);
1862 }
1863 blob=(unsigned char *) AcquireQuantumMemory(length+MaxTextExtent,
1864 sizeof(*blob));
1865 if (blob != (unsigned char *) NULL)
1866 {
1867 (void) CopyMagickMemory(blob,value,length);
1868 blob[length]='\0';
1869 }
1870 UnlockResource(global);
1871 FreeResource(global);
1872 return(blob);
1873}
1874
1875/*
1876%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1877% %
1878% %
1879% %
1880% N T S e e k D i r e c t o r y %
1881% %
1882% %
1883% %
1884%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1885%
1886% NTSeekDirectory() sets the position of the next NTReadDirectory() operation
1887% on the directory stream.
1888%
1889% The format of the NTSeekDirectory method is:
1890%
cristybb503372010-05-27 20:51:26 +00001891% void NTSeekDirectory(DIR *entry,ssize_t position)
cristy3ed852e2009-09-05 21:47:34 +00001892%
1893% A description of each parameter follows:
1894%
1895% o entry: Specifies a pointer to a DIR structure.
1896%
1897% o position: specifies the position associated with the directory
1898% stream.
1899%
1900*/
cristyd2d11ec2012-03-28 13:53:49 +00001901MagickPrivate void NTSeekDirectory(DIR *entry,ssize_t position)
cristy3ed852e2009-09-05 21:47:34 +00001902{
cristy3b743bb2009-09-14 16:07:59 +00001903 (void) position;
cristy3ed852e2009-09-05 21:47:34 +00001904 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1905 assert(entry != (DIR *) NULL);
1906}
1907
1908/*
1909%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1910% %
1911% %
1912% %
1913% N T S e t S e a r c h P a t h %
1914% %
1915% %
1916% %
1917%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1918%
1919% NTSetSearchPath() sets the current locations that the subsystem should
1920% look at to find dynamically loadable modules.
1921%
1922% The format of the NTSetSearchPath method is:
1923%
1924% int NTSetSearchPath(const char *path)
1925%
1926% A description of each parameter follows:
1927%
1928% o path: Specifies a pointer to string representing the search path
1929% for DLL's that can be dynamically loaded.
1930%
1931*/
cristyd2d11ec2012-03-28 13:53:49 +00001932MagickPrivate int NTSetSearchPath(const char *path)
cristy3ed852e2009-09-05 21:47:34 +00001933{
1934#if defined(MAGICKCORE_LTDL_DELEGATE)
1935 lt_dlsetsearchpath(path);
1936#else
1937 if (lt_slsearchpath != (char *) NULL)
1938 lt_slsearchpath=DestroyString(lt_slsearchpath);
1939 if (path != (char *) NULL)
1940 lt_slsearchpath=AcquireString(path);
1941#endif
1942 return(0);
1943}
1944
1945/*
1946%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1947% %
1948% %
1949% %
1950+ N T S y n c M e m o r y %
1951% %
1952% %
1953% %
1954%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1955%
1956% NTSyncMemory() emulates the Unix method of the same name.
1957%
1958% The format of the NTSyncMemory method is:
1959%
1960% int NTSyncMemory(void *address,size_t length,int flags)
1961%
1962% A description of each parameter follows:
1963%
1964% o address: the address of the binary large object.
1965%
1966% o length: the length of the binary large object.
1967%
1968% o flags: Option flags (ignored for Windows).
1969%
1970*/
cristyd2d11ec2012-03-28 13:53:49 +00001971MagickPrivate int NTSyncMemory(void *address,size_t length,int flags)
cristy3ed852e2009-09-05 21:47:34 +00001972{
cristy3b743bb2009-09-14 16:07:59 +00001973 (void) flags;
cristy3ed852e2009-09-05 21:47:34 +00001974 if (FlushViewOfFile(address,length) == MagickFalse)
1975 return(-1);
1976 return(0);
1977}
1978
1979/*
1980%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1981% %
1982% %
1983% %
1984% N T S y s t e m C o m m a n d %
1985% %
1986% %
1987% %
1988%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1989%
1990% NTSystemCommand() executes the specified command and waits until it
1991% terminates. The returned value is the exit status of the command.
1992%
cristyb32b90a2009-09-07 21:45:48 +00001993% The format of the NTSystemCommand method is:
cristy3ed852e2009-09-05 21:47:34 +00001994%
cristy6de4bc22010-01-12 17:10:35 +00001995% int NTSystemCommand(MagickFalse,const char *command)
cristy3ed852e2009-09-05 21:47:34 +00001996%
1997% A description of each parameter follows:
1998%
1999% o command: This string is the command to execute.
2000%
2001*/
cristyd2d11ec2012-03-28 13:53:49 +00002002MagickPrivate int NTSystemCommand(const char *command)
cristy3ed852e2009-09-05 21:47:34 +00002003{
2004 char
2005 local_command[MaxTextExtent];
2006
2007 DWORD
2008 child_status;
2009
2010 int
2011 status;
2012
2013 MagickBooleanType
2014 background_process;
2015
2016 PROCESS_INFORMATION
2017 process_info;
2018
2019 STARTUPINFO
2020 startup_info;
2021
2022 if (command == (char *) NULL)
2023 return(-1);
2024 GetStartupInfo(&startup_info);
2025 startup_info.dwFlags=STARTF_USESHOWWINDOW;
2026 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
2027 (void) CopyMagickString(local_command,command,MaxTextExtent);
2028 background_process=command[strlen(command)-1] == '&' ? MagickTrue :
2029 MagickFalse;
cristy99a00592012-02-25 02:33:01 +00002030 if (background_process != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002031 local_command[strlen(command)-1]='\0';
2032 if (command[strlen(command)-1] == '|')
2033 local_command[strlen(command)-1]='\0';
2034 else
2035 startup_info.wShowWindow=SW_SHOWDEFAULT;
cristy99a00592012-02-25 02:33:01 +00002036 status=CreateProcess((LPCTSTR) NULL,local_command,(LPSECURITY_ATTRIBUTES)
2037 NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) FALSE,(DWORD)
2038 NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
cristy3ed852e2009-09-05 21:47:34 +00002039 &process_info);
2040 if (status == 0)
2041 return(-1);
cristy99a00592012-02-25 02:33:01 +00002042 if (background_process != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002043 return(status == 0);
2044 status=WaitForSingleObject(process_info.hProcess,INFINITE);
2045 if (status != WAIT_OBJECT_0)
2046 return(status);
2047 status=GetExitCodeProcess(process_info.hProcess,&child_status);
2048 if (status == 0)
2049 return(-1);
2050 CloseHandle(process_info.hProcess);
2051 CloseHandle(process_info.hThread);
2052 return((int) child_status);
2053}
2054
2055/*
2056%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2057% %
2058% %
2059% %
2060% N T S y s t e m C o n i f i g u r a t i o n %
2061% %
2062% %
2063% %
2064%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2065%
2066% NTSystemConfiguration() provides a way for the application to determine
2067% values for system limits or options at runtime.
2068%
2069% The format of the exit method is:
2070%
cristybb503372010-05-27 20:51:26 +00002071% ssize_t NTSystemConfiguration(int name)
cristy3ed852e2009-09-05 21:47:34 +00002072%
2073% A description of each parameter follows:
2074%
2075% o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
2076%
2077*/
cristyd2d11ec2012-03-28 13:53:49 +00002078MagickPrivate ssize_t NTSystemConfiguration(int name)
cristy3ed852e2009-09-05 21:47:34 +00002079{
2080 switch (name)
2081 {
2082 case _SC_PAGESIZE:
2083 {
2084 SYSTEM_INFO
2085 system_info;
2086
2087 GetSystemInfo(&system_info);
2088 return(system_info.dwPageSize);
2089 }
2090 case _SC_PHYS_PAGES:
2091 {
2092 HMODULE
2093 handle;
2094
2095 LPFNDLLFUNC2
2096 module;
2097
2098 NTMEMORYSTATUSEX
2099 status;
2100
2101 SYSTEM_INFO
2102 system_info;
2103
2104 handle=GetModuleHandle("kernel32.dll");
2105 if (handle == (HMODULE) NULL)
2106 return(0L);
2107 GetSystemInfo(&system_info);
2108 module=(LPFNDLLFUNC2) NTGetLibrarySymbol(handle,"GlobalMemoryStatusEx");
2109 if (module == (LPFNDLLFUNC2) NULL)
2110 {
2111 MEMORYSTATUS
2112 status;
2113
2114 GlobalMemoryStatus(&status);
cristybb503372010-05-27 20:51:26 +00002115 return((ssize_t) status.dwTotalPhys/system_info.dwPageSize);
cristy3ed852e2009-09-05 21:47:34 +00002116 }
2117 status.dwLength=sizeof(status);
2118 if (module(&status) == 0)
2119 return(0L);
cristybb503372010-05-27 20:51:26 +00002120 return((ssize_t) status.ullTotalPhys/system_info.dwPageSize);
cristy3ed852e2009-09-05 21:47:34 +00002121 }
2122 case _SC_OPEN_MAX:
2123 return(2048);
2124 default:
2125 break;
2126 }
2127 return(-1);
2128}
2129
2130/*
2131%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2132% %
2133% %
2134% %
2135% N T T e l l D i r e c t o r y %
2136% %
2137% %
2138% %
2139%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2140%
2141% NTTellDirectory() returns the current location associated with the named
2142% directory stream.
2143%
2144% The format of the NTTellDirectory method is:
2145%
cristybb503372010-05-27 20:51:26 +00002146% ssize_t NTTellDirectory(DIR *entry)
cristy3ed852e2009-09-05 21:47:34 +00002147%
2148% A description of each parameter follows:
2149%
2150% o entry: Specifies a pointer to a DIR structure.
2151%
2152*/
cristyd2d11ec2012-03-28 13:53:49 +00002153MagickPrivate ssize_t NTTellDirectory(DIR *entry)
cristy3ed852e2009-09-05 21:47:34 +00002154{
2155 assert(entry != (DIR *) NULL);
2156 return(0);
2157}
2158
2159/*
2160%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2161% %
2162% %
2163% %
2164% N T T r u n c a t e F i l e %
2165% %
2166% %
2167% %
2168%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2169%
2170% NTTruncateFile() truncates a file to a specified length.
2171%
2172% The format of the NTTruncateFile method is:
2173%
2174% int NTTruncateFile(int file,off_t length)
2175%
2176% A description of each parameter follows:
2177%
2178% o file: the file.
2179%
2180% o length: the file length.
2181%
2182*/
cristyd2d11ec2012-03-28 13:53:49 +00002183MagickPrivate int NTTruncateFile(int file,off_t length)
cristy3ed852e2009-09-05 21:47:34 +00002184{
2185 DWORD
2186 file_pointer;
2187
cristyfeb262e2010-06-04 22:57:35 +00002188 long
cristy3ed852e2009-09-05 21:47:34 +00002189 file_handle,
2190 high,
2191 low;
2192
2193 file_handle=_get_osfhandle(file);
2194 if (file_handle == -1L)
2195 return(-1);
cristyfeb262e2010-06-04 22:57:35 +00002196 low=(long) (length & 0xffffffffUL);
2197 high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
cristy3ed852e2009-09-05 21:47:34 +00002198 file_pointer=SetFilePointer((HANDLE) file_handle,low,&high,FILE_BEGIN);
2199 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
2200 return(-1);
2201 if (SetEndOfFile((HANDLE) file_handle) == 0)
2202 return(-1);
2203 return(0);
2204}
2205
2206/*
2207%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2208% %
2209% %
2210% %
2211+ N T U n m a p M e m o r y %
2212% %
2213% %
2214% %
2215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2216%
2217% NTUnmapMemory() emulates the Unix munmap method.
2218%
2219% The format of the NTUnmapMemory method is:
2220%
2221% int NTUnmapMemory(void *map,size_t length)
2222%
2223% A description of each parameter follows:
2224%
2225% o map: the address of the binary large object.
2226%
2227% o length: the length of the binary large object.
2228%
2229*/
cristyd2d11ec2012-03-28 13:53:49 +00002230MagickPrivate int NTUnmapMemory(void *map,size_t length)
cristy3ed852e2009-09-05 21:47:34 +00002231{
cristy3b743bb2009-09-14 16:07:59 +00002232 (void) length;
cristy3ed852e2009-09-05 21:47:34 +00002233 if (UnmapViewOfFile(map) == 0)
2234 return(-1);
2235 return(0);
2236}
2237
2238/*
2239%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2240% %
2241% %
2242% %
2243% N T U s e r T i m e %
2244% %
2245% %
2246% %
2247%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2248%
2249% NTUserTime() returns the total time the process has been scheduled (e.g.
2250% seconds) since the last call to StartTimer().
2251%
2252% The format of the UserTime method is:
2253%
2254% double NTUserTime(void)
2255%
2256*/
cristyd2d11ec2012-03-28 13:53:49 +00002257MagickPrivate double NTUserTime(void)
cristy3ed852e2009-09-05 21:47:34 +00002258{
2259 DWORD
2260 status;
2261
2262 FILETIME
2263 create_time,
2264 exit_time;
2265
2266 OSVERSIONINFO
2267 OsVersionInfo;
2268
2269 union
2270 {
2271 FILETIME
2272 filetime;
2273
2274 __int64
2275 filetime64;
2276 } kernel_time;
2277
2278 union
2279 {
2280 FILETIME
2281 filetime;
2282
2283 __int64
2284 filetime64;
2285 } user_time;
2286
2287 OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
2288 GetVersionEx(&OsVersionInfo);
2289 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
2290 return(NTElapsedTime());
2291 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
2292 &kernel_time.filetime,&user_time.filetime);
2293 if (status != TRUE)
2294 return(0.0);
2295 return((double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
2296}
2297
2298/*
2299%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2300% %
2301% %
2302% %
2303% N T W a r n i n g H a n d l e r %
2304% %
2305% %
2306% %
2307%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2308%
2309% NTWarningHandler() displays a warning reason.
2310%
2311% The format of the NTWarningHandler method is:
2312%
cristy3b743bb2009-09-14 16:07:59 +00002313% void NTWarningHandler(const ExceptionType severity,const char *reason,
cristy3ed852e2009-09-05 21:47:34 +00002314% const char *description)
2315%
2316% A description of each parameter follows:
2317%
cristy3b743bb2009-09-14 16:07:59 +00002318% o severity: Specifies the numeric warning category.
cristy3ed852e2009-09-05 21:47:34 +00002319%
2320% o reason: Specifies the reason to display before terminating the
2321% program.
2322%
2323% o description: Specifies any description to the reason.
2324%
2325*/
cristyd2d11ec2012-03-28 13:53:49 +00002326MagickPrivate void NTWarningHandler(const ExceptionType severity,
cristy3ed852e2009-09-05 21:47:34 +00002327 const char *reason,const char *description)
2328{
2329 char
2330 buffer[2*MaxTextExtent];
2331
cristy3b743bb2009-09-14 16:07:59 +00002332 (void) severity;
cristy3ed852e2009-09-05 21:47:34 +00002333 if (reason == (char *) NULL)
2334 return;
2335 if (description == (char *) NULL)
cristyb51dff52011-05-19 16:55:47 +00002336 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s.\n",GetClientName(),
cristy3ed852e2009-09-05 21:47:34 +00002337 reason);
2338 else
cristyb51dff52011-05-19 16:55:47 +00002339 (void) FormatLocaleString(buffer,MaxTextExtent,"%s: %s (%s).\n",
cristy3ed852e2009-09-05 21:47:34 +00002340 GetClientName(),reason,description);
2341 (void) MessageBox(NULL,buffer,"ImageMagick Warning",MB_OK | MB_TASKMODAL |
2342 MB_SETFOREGROUND | MB_ICONINFORMATION);
2343}
2344#endif