OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
module.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1991, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of class TModule. TModule defines the base behavior for
7/// OWL libraries and applications.
8//----------------------------------------------------------------------------
9
10#if defined(__BORLANDC__)
11# pragma option -w-inl // Disable warning "Functions containing 'statement' is not expanded inline".
12#endif
13
14#include <owl/pch.h>
15
16#include <owl/defs.h>
17#include <owl/module.h>
18#include <owl/appdict.h>
19#include <owl/applicat.h>
20#include <owl/pointer.h>
21#include <stdio.h>
22#include <winnls.h>
23#include <owl/template.h>
24
25#if defined(BI_MULTI_THREAD_RTL)
26#include <owl/thread.h>
27#endif
28
29#include <owl/window.h>
30#include <owl/framewin.h>
31
32#if defined(BI_COMP_MSC)
33#include <new.h>
34#endif
35
36#if OWL_STACKWALKER
37# include "stackwalker.h"
38#endif
39
40#include <array>
41
42long TlsAddRefs();
43long TlsRelease();
44
45#if defined(__BORLANDC__)
46# pragma option -w-ccc // Disable "Condition is always true/false"
47#endif
48
49#if defined(_MSC_VER)
50# pragma warning(disable: 4996) // Turn off deprecation warnings (triggered by GetVersion/GetVersionEx).
51#endif
52
53namespace owl {
54
56DIAG_DECLARE_GROUP(OwlApp); // General Application diagnostic group
57
58//
59// Global message id for GetWindowPtr call defined in owl.cpp
60//
62
63} // OWL namespace
64
65using namespace std;
66
67namespace owl {
68
69//
70/// Returns the class name in string form.
71/// If the class name is represented by an atom, then the Windows API function GetAtomName is
72/// called to look up the string associated with the atom.
73//
75{
76 auto getAtomName = [](ATOM a) -> tstring
77 {
78 auto b = array<tchar, 256>{};
79 const auto n = ::GetAtomName(a, b.data(), static_cast<int>(b.size()));
80 return tstring(b.data(), n);
81 };
83}
84
85//----------------------------------------------------------------------------
86
87//
88// TSystemMessage
89// ~~~~~~~~~~~~~~
90//
92{
93 Error = ::GetLastError();
95}
96
97//
98//
99//
106
107//
108//
109//
110int TSystemMessage::MessageBox(TWindow* win, const tstring& msg, const tstring& title, uint flags) const
111{
112 flags |= MB_SYSTEMMODAL;
113
115 message += Message;
117 if(!win && (appl = OWLGetAppDictionary().GetApplication(0))!=nullptr && appl->GetMainWindow())
118 win = appl->GetMainWindow();
119 if(win)
120 return win->MessageBox(message.c_str(), title, flags);
121 return ::MessageBox(nullptr, message.c_str(), title.c_str(), flags);
122}
123
124//
125//
126//
128{
129 LPVOID ptr = 0;
131 nullptr, Error, langId, (LPTSTR)&ptr, 0, nullptr) != 0)
132 {
133 Message = (LPTSTR)ptr;
134 LocalFree(ptr); // free the memory allocated by FormatMessage
135 }
136 else{
138 wsprintf(buffer, _T("Error: %#X occurred (no further info)"), Error);
139 Message = buffer;
140 }
141}
142//----------------------------------------------------------------------------
143
144//} // OWL namespace
145
146// Implement
147//////////////////////////////////////////////////////////////////////////////////////////////////
148// multithread support
149/// \cond
150class __TModuleList {
151 public:
152 static TModule* Next(TModule* module);
153 static bool Find(TModule* module);
154 static void Add(TModule* module);
155 static void Remove(TModule* module);
156 static TModule* FindResModule(TResId id, TResId type);
157
159
160#if defined(BI_MULTI_THREAD_RTL)
161 static TMRSWSection* Lock;
162#endif
163
164};
165/// \endcond
166
167TPtrArray<TModule*>* __TModuleList::ModuleArray = nullptr;
168#if defined(BI_MULTI_THREAD_RTL)
169TMRSWSection* __TModuleList::Lock = nullptr;
170#endif
171
172#if defined(BI_MULTI_THREAD_RTL)
173#define LOCKLIST(s) TMRSWSection::TLock __lock(*__TModuleList::Lock, s)
174#else
175#define LOCKLIST(s)
176#endif
177//
178TModule* __TModuleList::Next(TModule* module)
179{
180 if(!ModuleArray)
181 return nullptr;
182 LOCKLIST(true);
183 if(!module){
184 return (*ModuleArray)[0];
185 }
186 else{
187 for(uint i = 0; i < ModuleArray->Size(); i++){
188 if(module == (*ModuleArray)[i])
189 return (i+1 < ModuleArray->Size()) ? (*ModuleArray)[i+1] : nullptr;
190 }
191 }
192 return nullptr;
193}
194//
195void __TModuleList::Add(TModule* module)
196{
197 if(Find(module))
198 return;
199
200 if(!ModuleArray)
201 {
202#if defined(BI_MULTI_THREAD_RTL)
203 Lock = new TMRSWSection;
204#endif
206 }
207 {
208 LOCKLIST(false);
209
210 // If there is another object, but with the same hInstance, replace it.
211 // This usualy happens when the global module is created and added to the list,
212 // and afterwards the TApplication-derived object with the same hInstance is created
213 for (uint i = 0; i < ModuleArray->Size(); i++)
214 {
215 if (module->GetHandle() == (*ModuleArray)[i]->GetHandle())
216 {
217 (*ModuleArray)[i] = module;
218 return;
219 }
220 }
221
222
223 ModuleArray->AddAt(module,0);
224 }
225}
226//
227void __TModuleList::Remove(TModule* module)
228{
229 if(!Find(module))
230 return;
231
233 {
234 LOCKLIST(false);
235 ModuleArray->DetachItem(module);
236 if(ModuleArray->Empty())
237 {
238 delete ModuleArray;
239 ModuleArray = nullptr;
240 }
241 }
242#if defined(BI_MULTI_THREAD_RTL)
243 if(!ModuleArray){
244 delete Lock;
245 Lock = nullptr;
246 }
247#endif
248}
249//
250bool __TModuleList::Find(TModule* module)
251{
252 if(!ModuleArray)
253 return false;
254 LOCKLIST(true);
255
256 for (uint i = 0; i < ModuleArray->Size(); i++){
257 if (module == (*ModuleArray)[i])
258 return true;
259 }
260 return false;
261}
262//
263TModule* __TModuleList::FindResModule(TResId id, TResId type)
264{
265 if(!ModuleArray)
266 return nullptr;
267
268 LOCKLIST(true);
269
270 TApplication* appl = OWLGetAppDictionary().GetApplication(0);
271 TLangId langId = appl ? appl->GetLangId() : LangNeutral;
273 while(Iter1){
274 if((*Iter1)->FindResourceEx(id, type, langId))
275 return *Iter1;
276 Iter1++;
277 }
278
280 while(Iter){
281 if((*Iter)->FindResource(id, type))
282 return *Iter;
283 Iter++;
284 }
285 return nullptr;
286}
287
288///////////////////////////////////////////////////////////////////////////
289//
291{
292 return __TModuleList::Next(module);
293}
294
295//namespace owl {
296
297//
298// Implementation of Constructors for a TModule object
299//
300
301//
302/// Constructs a TModule object that is used as an alias for a DLL. If shouldLoad is
303/// true, TModule will automatically load and free the DLL. If shouldLoad is false,
304/// then the HInstance needs to be set later using InitModule.
305///
306/// "mustLoad" determines if a load failure should cause an exception throw
307//
309{
310 if (shouldLoad) {
312 Handle = ::LoadLibrary(name.c_str());
313 if (Handle <= HINSTANCE(HINSTANCE_ERROR) && mustLoad) {
314 TRACEX(OwlApp, 0, _T("Unable to load DLL '") << name.c_str() << _T('\''));
315 TXInvalidModule::Raise(name); // !CQ use a better exception. This is for windows
316 }
317 }
318 else {
319 Handle = nullptr;
320 }
321
322 ShouldFree = shouldLoad;
323 SetName(name);
324
325 //
326 // Add Module into global Array
327 //
328 if(addToList)
329 __TModuleList::Add(this);
330}
331
332//
333/// Constructs a TModule object that is an alias for an already loaded DLL or
334/// program with an available HInstance. When the TModule is destructed, the
335/// instance isn't automatically freed. name, which is optional, can be 0.
336/// No cmdLine is set up.
337/// If null-pointer is passed for name, and the module handle is valid, the name is retrieved using GetModuleFileName.
338//
340{
342 Handle = hInstance;
343 ShouldFree = false;
344 SetName(name);
345
346 //
347 // Add Module into global Array
348 //
349 if (addToList)
350 __TModuleList::Add(this);
351}
352
353//
354/// String-aware overload.
355/// If an empty name is passed, and the module handle is valid, the name is retrieved using GetModuleFileName.
356//
358{
360 Handle = hInstance;
361 ShouldFree = false;
362 SetName(name);
363
364 //
365 // Add Module into global Array
366 //
367 if(addToList)
368 __TModuleList::Add(this);
369}
370
371//
372/// Constructs a TModule object for an ObjectWindows DLL or program from within
373/// LibMain or WinMain. Calls InitModule to initialize hInstance and cmdLine.
374/// If null-pointer is passed for name, and the module handle is valid, the name is retrieved using GetModuleFileName.
375//
377{
378 Handle = nullptr;
379 ShouldFree = false;
380 if (hInstance)
382 SetName(name);
383
384 //
385 // Add Module into global Array
386 //
387 if(addToList)
388 __TModuleList::Add(this);
389}
390
391//
392/// String-aware overload.
393/// If an empty name is passed, and the module handle is valid, the name is retrieved using GetModuleFileName.
394//
396{
397 Handle = nullptr;
398 ShouldFree = false;
399 if (hInstance)
401 SetName(name);
402
403 //
404 // Add Module into global Array
405 //
406 if (addToList)
407 __TModuleList::Add(this);
408}
409
410//
411/// Destructs a TModule, freeing the instance if appropriate, and deleting
412/// new'd strings
413//
415{
416 if (ShouldFree && Handle > HINSTANCE(HINSTANCE_ERROR))
417 ::FreeLibrary(Handle);
418
419 //
420 // Detach Module from global ModuleArray
421 //
422 __TModuleList::Remove(this);
423}
424
425//
426/// Global search for resources
427//
428TModule*
430{
431 return __TModuleList::FindResModule(id, type);
432}
433
434//
435/// Accessor function that sets the name of the module.
436/// If null-pointer is passed, and the module handle is valid, the name is retrieved using GetModuleFileName.
437//
438void
440{
441 Name = name ? name :
443 _T("");
444}
445
446//
447/// String-aware overload.
448/// If an empty string is passed, and the module handle is valid, the name is retrieved using GetModuleFileName.
449//
450void
452{
453 Name = (name.length() == 0 && Handle > HINSTANCE(HINSTANCE_ERROR)) ?
455}
456
457//
458/// Performs any instance initialization necessary for the module. If the module
459/// cannot be created, a TXInvalidModule exception is thrown.
460///
461/// Copies cmd line, and gets proc
462/// instance handles for the standard procs.
463//
464
465#if !defined(BI_COMP_GNUC)
466#pragma warn -par
467#endif
468
469void
471{
473
474#if defined(BI_COMP_GNUC)
475 // Borland removes the first element of argv (program name) from
476 // owl::CmdLine somehow ("the RTL takes care of this" above), but
477 // g++ does not. Modifying the cmdLine argument won't have any effect
478 // because it's const and is passed as string::c_str().
479 char const* cmdLine = TApplication::GetCmdLine().c_str();
480 if(cmdLine){
481 while (*cmdLine && *cmdLine++ != _T(' '))
482 ;
484 }
485#endif
486
487 // Register a system-wide "GetWindowPtr" message as GetWindowPtr(hInstance)
488 // Each running copy of ObjectWindows will get a unique message Id
489 // instance of OWL library. !!!
490 if (!GetWindowPtrMsgId) {
491 const tchar msgTemplate[] = _T("GetWindowPtr(%X)");
493 wsprintf(msgName, msgTemplate, static_cast<uint>(reinterpret_cast<UINT_PTR>(hInstance)));
496 }
497}
498
499#if !defined(BI_COMP_GNUC)
500#pragma warn .par
501#endif
502
503//
504/// Replaceable exception handler; may be redefined to process OWL exceptions
505/// if canResume is false, then the user doesn't have the option of ignoring
506//
507/// Called when fatal exceptions occur, Error takes an xmsg exception
508/// object, a resource ID for a message box caption, and an optional resource ID for
509/// a user prompt. By default, Error calls HandleGlobalException with the xmsg
510/// object and the strings obtained from the resources. An application (derived from
511/// TApplication which is derived from TModule) can reimplement this function to
512/// provide alternative behavior.
513/// A nonzero status code is returned to indicate that an error condition is to be
514/// propagated; a zero status indicates that the condition has been handled and that
515/// it is OK to proceed. ObjectWindows uses this status code inside its message loop
516/// to allow the program to resume. The global error handler (defined in except.h),
517/// which displays the message text, is
518/// \code
519/// int _OWLFUNC HandleGlobalException(xmsg& x, char* caption, char* canResume);
520/// \endcode
521int
523{
524 tchar cbuf[80];
525 tchar pbuf[80];
526
527 if (!captionResId)
529 return HandleGlobalException(x,
530 LoadString(captionResId, cbuf, 80) ? cbuf : nullptr,
532 (LoadString(promptResId, pbuf, 80) ? pbuf : _T("OK to Resume?"))
533 : nullptr);
534}
535
536//
537/// For use with CopyText.
538//
539struct TGetModuleFileName
540{
541 const TModule& module;
542 TGetModuleFileName(const TModule& m) : module(m) {}
543
544 int operator()(LPTSTR buf, int buf_size) const
545 {
546 int n = module.GetModuleFileName(buf, buf_size);
547 WARN(n == buf_size, _T("TModule::GetModuleFileName truncated the result."));
548 return n;
549 }
550};
551
552//
553/// String-aware overload
554//
556{
557 return CopyText(_MAX_PATH, TGetModuleFileName(*this));
558}
559
560//
561/// Set the instance handle for a module that does not yet have one. Cannot
562/// be called on a module that already has an instance handle.
563//
564void
566{
567 PRECONDITION(!ShouldFree && !Handle);
568 Handle = hInstance;
569}
570
571//
572// LoadString replacements which do not generated debug warning output
573//
574 typedef WCHAR* TResText;
575 typedef WCHAR* TResCount;
576
577//
578// Wrapper for loading a string resource.
579//
580/// Loads a string resource identified by id into the buffer pointed to by
581/// buff. maxChars indicates the size of the buffer to which the zero-terminated
582/// string is copied. A string longer than the length specified in maxChars is
583/// truncated. The return value is the number of characters copied into the buffer,
584/// or 0 if the string resource does not exist.
585int
587{
588#ifdef MAINWIN
589 int resource = ::LoadString( GetInstance(), id, buf, bufSize);
590 if (resource)
591 return resource;
592#else /// MAINWIN
593 uint len = 0;
597
599 resHdl = FindResourceEx(id/16+1, RT_STRING, appl ? appl->GetLangId() : LangNeutral);
600 if(!resHdl)
601 resHdl = FindResource(id/16+1, RT_STRING);
602 if(resHdl != nullptr){
603 if((glbHdl = LoadResource(resHdl)) != nullptr) {
604 if ((resData = (TResText)LockResource(glbHdl)) != nullptr) {
605 // get pointer to our string
606 int cnt;
607 for (cnt = id % 16; len = *(TResCount)resData++, cnt--; resData += len)
608 ;
609 if (len != 0) {
610# if defined(UNICODE)
611 if (len >= uint(bufSize))
612 len = bufSize-1;
613 wmemset(buf, 0, bufSize);
614 ::_tcsncpy(buf, resData, len);
615 //::_tcscpy(buf, resData); // Ma, 09.10.2003 string too long
616# else
617 len = ::WideCharToMultiByte(CP_ACP, 0, resData, len, buf, bufSize, nullptr, nullptr);
618 if (len > 0)
619 buf[len] = 0;
620# endif
621 }
622 }
624 if (len)
625 return len;
626 }
627 }
628 else{
629 // if not found look in Module List
630 TModule* module = TModule::FindResModule(id/16+1, RT_STRING);
631 if (module)
632 return module->LoadString(id, buf, bufSize);
633 }
634#endif //else not MAINWIN
635 if (bufSize)
636 *buf = 0; // make empty string just in case caller doesn't check return
637 return 0; // indicate string not found
638}
639
640//
641// Wrapper for loading a string resource.
642//
643/// Loads a string resource identified by id
644//
645#ifdef UNIX
648{
649
650// Added by Val Ovechkin 7:18 PM 6/11/98
651 char str[1024] = "<empty>";
652 int res = ::LoadString( GetInstance(), id, str, sizeof str );
653 if( !res ) str[0] = 0;
654 return tstring( str );
655
656
657 uint len = 0;
662
663 if ((resHdl = FindResource(id/16+1, RT_STRING)) != 0
664 && (glbHdl = LoadResource(resHdl)) != 0) {
665 if ((resData = (TResText)LockResource(glbHdl)) != 0) {
666 int cnt;
667 for (cnt = id % 16; len = *(TResCount)resData++, cnt--; resData += len)
668 ;
669 if (len != 0) {
670#if (0) // This is dangerous unless string is changed to handle non-terminated
671 // char arrays
672 //
673 retString.append(resData, 0, len);
674#else
675 int n = ::WideCharToMultiByte(CP_ACP, 0, resData, len, 0, 0, 0, 0);
676 TAPointer<char> buf = new char[n+1];
677 len = ::WideCharToMultiByte(CP_ACP, 0, resData, len, buf, n+1, 0, 0);
678 #if 0
679 retString.resize(len+1);
680 uint i;
681 for (i = 0; i < len; i++)
682 retString[i] = static_cast<char>(buf[i]);
683 retString[i] = 0;
684 #else
685 // The string object does not need the terminating null of C-strings
686 //
687 retString.resize(len);
688 uint i;
689 for (i = 0; i < len; i++)
690 retString[i] = static_cast<char>(buf[i]);
691 #endif
692#endif
693 }
694 }
696 if (len)
697 return retString;
698 }
699
700 if (&GetGlobalModule() != this) // look in OWL module if different
701 return GetGlobalModule().LoadString(id);
702
703 return retString; // empty if string not found
704}
705
706#else
707
708/// Loads a string resource identified by id
711{
712 int len = 0;
717
719 resHdl = FindResourceEx(id/16+1, RT_STRING, appl ? appl->GetLangId() : LangNeutral);
720 if(!resHdl)
721 resHdl = FindResource(id/16+1, RT_STRING);
722 if (resHdl != nullptr){
723 if((glbHdl = LoadResource(resHdl)) != nullptr){
724 if ((resData = (TResText)LockResource(glbHdl)) != nullptr) {
725 int cnt;
726 for (cnt = id % 16; len = *(TResCount)resData++, cnt--; resData += len)
727 ;
728 if (len != 0) {
729#if (0) // This is dangerous unless string is changed to handle non-terminated
730 // char arrays
731 retString.append(resData, 0, len);
732#else
733# if defined(UNICODE)
734 // The string object does not need the terminating null of C-strings
735 retString.resize(len); // Ma, 09.10.2003 string is not terminated!
736
737 for (int i = 0; i < len; i++)
738 retString[i] = resData[i];
739# else
740 int n = ::WideCharToMultiByte(CP_ACP, 0, resData, len, nullptr, 0, nullptr, nullptr);
742 tchar* buf = __ClnObj;
743 len = ::WideCharToMultiByte(CP_ACP, 0, resData, len, buf, n+1, nullptr, nullptr);
744 // The string object does not need the terminating null of C-strings
745 retString.resize(len);
746 int i;
747 for (i = 0; i < len; i++)
748 retString[i] = buf[i];
749# endif
750#endif
751 }
752 }
753 if (len)
754 return retString;
755 }
756 }
757 else{
758 // if not found look in Module List
759 TModule* module = TModule::FindResModule(id/16+1, RT_STRING);
760 if (module)
761 return module->LoadString(id);
762 }
763
764 return retString; // empty if string not found
765}
766#endif
767
768
769
770//
771/// Wrapper for the Windows API.
772//
773/// Loads the bitmap resource specified by id. If the bitmap cannot be found,
774/// LoadBitmap returns 0.
775//
777{
779#if 0
783
785 resHdl = FindResourceEx(id, RT_BITMAP, appl ? appl->GetLangId() : LangNeutral);
786
787 if(resHdl){
788 if((glbHdl = LoadResource(resHdl)) !=0)
790 }
791#else
792 HBITMAP hBitmap = ::LoadBitmap(Handle, id);
793#endif
794 WARNX(OwlApp, !hBitmap, 0, _T("Bitmap resource not found Id:") << id);
795
796 if(!hBitmap){// if not found look in Module List
797 TModule* module = TModule::FindResModule(id, RT_BITMAP);
798 if(module)
799 return module->LoadBitmap(id);
800 }
801
802 CHECKX(hBitmap,_T("Bitmap resource not found even in module list."));
803 return hBitmap;
804}
805//
806/// Wrapper for the Windows API.
807//
808/// Loads the accelerator table resource specified by id. LoadAccelerators loads the
809/// table only if it has not been previously loaded. If the table has already been
810/// loaded, LoadAccelerators returns a handle to the loaded table.
811//
813{
815
816#if 0
819
820 HACCEL hAccel = 0;
821
823 resHdl = FindResourceEx(id, RT_ACCELERATOR, appl ? appl->GetLangId() : LangNeutral);
824 if(!resHdl)
826 if(resHdl){
827 if((glbHdl = LoadResource(resHdl)) !=0)
829 }
830#else
831 HACCEL hAccel = ::LoadAccelerators(Handle, id);
832#endif
833 WARNX(OwlApp,!hAccel,0,_T("Accelerator resource not found") << id);
834
835 if(!hAccel){ // if not found look in Module List
836 TModule* module = TModule::FindResModule(id, RT_ACCELERATOR);
837 if(module)
838 return module->LoadAccelerators(id);
839 }
840
841 WARNX(OwlApp,!hAccel,0,_T("Accelerator resource not found even in module list") << id);
842 //CHECKX(hAccel,_T("Accelerator resource not found even in module list."));
843
844 return hAccel;
845}
846//----------------------------------------------------------------------------
847
848//
849/// Wrapper for the Windows API.
850//
851/// Loads the menu resource indicated by id into memory. If the menu resource cannot
852/// be found, LoadMenu returns 0.
853//
855{
857#if 0
860 HMENU hMenu = 0;
862 resHdl = FindResourceEx(id, RT_MENU, appl ? appl->GetLangId() : LangNeutral);
863 if(!resHdl)
865 if(resHdl){
866 if((glbHdl = LoadResource(resHdl)) !=0)
868 }
869#else
870 HMENU hMenu = ::LoadMenu(Handle, id);
871#endif
872 WARNX(OwlApp,!hMenu,0,_T("Menu resource not found") << id);
873
874 if (!hMenu){ // if not found look in Module List
875 TModule* module = TModule::FindResModule(id, RT_MENU);
876 if(module)
877 return module->LoadMenu(id);
878 }
879
880 CHECKX(hMenu,_T("Menu resource not found even in module list."));
881 return hMenu;
882}
883//----------------------------------------------------------------------------
884
885//
886/// Wrapper for the Windows API.
887//
888/// Loads the cursor resource specified by id into memory and returns a handle to
889/// the cursor resource. If the cursor resource cannot be found or identifies a
890/// resource that is not a cursor, LoadCursor returns 0.
891//
893{
895#if 0
898 HCURSOR hCursor = 0;
899
901 resHdl = FindResourceEx(id, RT_CURSOR, appl ? appl->GetLangId() : LangNeutral);
902
903 if(resHdl){
904 if((glbHdl = LoadResource(resHdl)) !=0)
906 }
907#else
908 HCURSOR hCursor = ::LoadCursor(Handle, id);
909#endif
910 WARNX(OwlApp,!hCursor,0,_T("Cursor resource not found") << id);
911
912 if (!hCursor){ // if not found look in Module List
913 TModule* module = TModule::FindResModule(id, RT_CURSOR);
914 if(module)
915 return module->LoadCursor(id);
916 }
917
918 CHECKX(hCursor,_T("Cursor resource not found even in module list."));
919 return hCursor;
920}
921
922//----------------------------------------------------------------------------
923//
924/// Wrapper for the Windows API.
925//
926/// Loads the icon resource indicated by the parameter, name, into memory. LoadIcon
927/// loads the icon only if it has not been previously loaded. If the icon resource
928/// cannot be found, LoadIcon returns 0.
929///
930/// LoadIcon can be used to load a predefined Windows icon if name points to one of
931/// the Windows IDI_XXXX values.
932//
934{
936#if 0
939 HICON hIcon = 0;
940
943
944 if(resHdl){
945 if((glbHdl = LoadResource(resHdl)) !=0)
946 hIcon = (HICON)LockResource(glbHdl);
947 }
948#else
949 HICON hIcon = ::LoadIcon(Handle, name);
950#endif
951 WARNX(OwlApp,!hIcon,0,_T("Icon resource not found") << name);
952
953 if (!hIcon){ // if not found look in Module List
954 TModule* module = TModule::FindResModule(name, RT_ICON);
955 if(module)
956 return module->LoadIcon(name);
957 }
958
959 CHECKX(hIcon,_T("Icon resource not found even in module list"));
960 return hIcon;
961}
962
963//----------------------------------------------------------------------------
964//
965/// Loads the given HTML resource and returns it as a narrow string.
966/// It is left to the client to detect the character set and encoding of the contents.
967/// If the resource is not found in this module, the module list is tried.
968/// If that also fails, an assertion exception is thrown in diagnostics mode.
969/// In non-diagnostics mode, an empty string is returned on failure.
970//
971string TModule::LoadHtml(TResId id) const
972{
975 WARNX(OwlApp, !r, 0, _T("HTML resource not found: ") << id);
976 if (!r)
977 {
978 // The resource was not found in this module, so try the module list.
979 //
980 TModule* module = FindResModule(id, RT_HTML);
981 CHECKX(module, _T("HTML resource not found even in the module list."));
982 return module ? module->LoadHtml(id) : string();
983 }
985 const char* p = static_cast<const char*>(LockResource(g)); // Note: No unlocking needed (see API doc).
986 return string(p, p + SizeofResource(r));
987}
988
989//----------------------------------------------------------------------------
990// Module entry dynamic binding base class
991
992//
993/// Functional-style overload.
994/// Throws TXOwl on error.
995//
997{
998 auto w = WNDCLASS{};
999 const auto r = GetClassInfo(name, &w);
1000 if (!r) throw TXOwl{_T("TModule::GetClassInfo failed")};
1001 return w;
1002}
1003
1004//
1005/// Returns `true` if the given window class has been registered.
1006/// \sa GetClassInfo
1007//
1009{
1010 auto w = WNDCLASS{};
1011 return GetClassInfo(name, &w) == true;
1012}
1013
1014//----------------------------------------------------------------------------
1015
1016//
1017/// Constructs a Module entry object given a narrow Windows resource identifier.
1018/// The resource identifier encodes either a function name or a function ordinal
1019/// for one of the exported functions in the module.
1020//
1022{
1023 Proc = module.GetProcAddress(id);
1024 if (!Proc) // Handle failure.
1025 {
1026 tstring msg = id.IsInt() ?
1029 msg += module.GetName(); // Just tack on the module name.
1031 }
1032}
1033
1034//----------------------------------------------------------------------------
1035// Wrappers for Windows API
1036//
1037
1038
1039 static const tchar userStr[] = _T("USER32");
1040# if defined(UNICODE)
1041 static const char LoadIconStr[] = "LoadIconW";
1042 static const char GetClassInfoStr[] = "GetClassInfoW";
1043 static const char GetMenuStringStr[]= "GetMenuStringW";
1044# else
1045 static const char LoadIconStr[] = "LoadIconA";
1046 static const char GetClassInfoStr[] = "GetClassInfoA";
1047 static const char GetMenuStringStr[]= "GetMenuStringA";
1048# endif
1049
1050static const char GetMenuStateStr[] = "GetMenuState";
1051static const char DestroyIconStr[] = "DestroyIcon";
1052
1053//
1054// Returns TModule object wrapping the handle of the USER module
1055//
1056TModule&
1058{
1059 static TModule userModule(userStr, ::GetModuleHandle(userStr),false);
1060 return userModule;
1061}
1062
1063//
1064// Invokes 'LoadIcon' indirectly
1065//
1066HICON
1068{
1070 loadIcon(GetModule(), LoadIconStr);
1071 return loadIcon(p1, p2);
1072}
1073
1074//
1075// Invokes 'DestroyIcon' indirectly
1076//
1077BOOL
1079{
1080 static TModuleProc1<BOOL, HICON> destroyIcon(GetModule(), DestroyIconStr);
1081 return destroyIcon(p1);
1082}
1083
1084//
1085// Invokes 'GetClassInfo' indirectly
1086//
1087BOOL
1094
1095//
1096// Invokes 'GetMenuString' indirectly
1097//
1098int
1105
1106//
1107// Invokes 'GetMenuState' indirectly
1108//
1109UINT
1111{
1113 getMenuState(GetModule(), GetMenuStateStr);
1114 return getMenuState(p1, p2, p3);
1115}
1116
1117/////////////////////////////////////////////////////////////
1118// VERSION.DLL or VER.DLL
1119 static const tchar verStr[] = _T("VERSION.DLL");
1120# if defined(UNICODE)
1121 static const char GetFileVersionInfoStr[] = "GetFileVersionInfoW";
1122 static const char GetFileVersionInfoSizeStr[] = "GetFileVersionInfoSizeW";
1123 static const char VerQueryValueStr[]= "VerQueryValueW";
1124 static const char VerLanguageNameStr[] = "VerLanguageNameW";
1125# else
1126 static const char GetFileVersionInfoStr[] = "GetFileVersionInfoA";
1127 static const char GetFileVersionInfoSizeStr[] = "GetFileVersionInfoSizeA";
1128 static const char VerQueryValueStr[]= "VerQueryValueA";
1129 static const char VerLanguageNameStr[] = "VerLanguageNameA";
1130# endif
1131
1132//
1133// Returns TModule object wrapping the handle of the VERSION.DLL module
1134//
1135TModule&
1137{
1138 static TModule verModule(verStr, true, true, false);
1139 return verModule;
1140}
1141
1142//
1143// Invokes 'GetFileVersionInfo' indirectly
1144//
1145BOOL
1152
1153//
1154// Invokes 'GetFileVersionInfoSize' indirectly
1155//
1156DWORD
1163
1164//
1165// Invokes 'VerQueryValue' indirectly
1166//
1167BOOL
1174
1175//
1176// Invokes 'VerLanguageName' indirectly
1177//
1178DWORD
1185
1186/////////////////////////////////////////////////////////////
1187//
1188// Delay loading OLE libraries
1189//
1190static const tchar oleStr[] = _T("OLE32.DLL");
1191static const tchar oleAutStr[] = _T("OLEAUT32.DLL");
1192
1193static const char CoCreateInstanceStr[] = "CoCreateInstance";
1194static const char SysFreeStringStr[] = "SysFreeString";
1195static const char SysStringLenStr[] = "SysStringLen";
1196static const char SysAllocStringStr[] = "SysAllocString";
1197
1198//
1199// Returns TModule object wrapping the handle of the OLE32.DLL/COMPOBJ.DLL module
1200//
1201TModule&
1203{
1204 static TModule oleModule(oleStr, true, true, false);
1205 return oleModule;
1206}
1207
1208//
1209// Invokes 'CoCreateInstance' indirectly
1210//
1211HRESULT
1218
1219//
1220// Returns TModule object wrapping the handle of the OLE32.DLL/COMPOBJ.DLL module
1221//
1222TModule&
1224{
1225 static TModule oleautoModule(oleAutStr, true, true, false);
1226 return oleautoModule;
1227}
1228
1229//
1230// Invokes 'SysFreeString' indirectly
1231//
1232HRESULT
1234{
1236 sysFreeString(GetModule(), SysFreeStringStr);
1237 return sysFreeString(p1);
1238}
1239
1240//
1241// Invokes 'SysStringLen' indirectly
1242//
1243UINT
1245{
1247 sysStringLen(GetModule(), SysStringLenStr);
1248 return sysStringLen(p1);
1249}
1250
1251
1252//
1253// Invokes 'SysAllocString' indirectly
1254//
1255BSTR
1257{
1259 sysAllocString(GetModule(), SysAllocStringStr);
1260 return sysAllocString(p1);
1261}
1262
1263//----------------------------------------------------------------------------
1264//
1265// Exception class
1266//
1267
1268//
1269/// Creates the Invalid Module exception.
1270//
1272:
1273 TXOwl(MakeMessage(IDS_INVALIDMODULE, name))
1274{
1275}
1276
1277//
1278/// Creates a copy of the exception
1279//
1282{
1283 return new TXInvalidModule(*this);
1284}
1285
1286
1287//
1288/// Throws the exception
1289//
1290void
1292{
1293 throw *this;
1294}
1295
1296//
1297/// Throws the exception
1298//
1299void
1301{
1302 TXInvalidModule(name).Throw();
1303}
1304} // OWL namespace
1305
1306
1307namespace owl {
1308
1309
1310//----------------------------------------------------------------------------
1311// TModule streaming
1312//
1313
1315
1316#if OWL_PERSISTENT_STREAMS
1317
1318//
1319/// Extracts the module object from the persistent stream.
1320//
1321void*
1322TModule::Streamer::Read(ipstream& is, uint32 /*version*/) const
1323{
1324 TModule* o = GetObject();
1325 is >> o->Name;
1326 is >> o->ShouldFree;
1327 if (o->ShouldFree)
1328 o->Handle = ::LoadLibrary(o->Name.c_str());
1329
1330 return o;
1331}
1332
1333//
1334/// Writes the module into a persistent stream.
1335//
1336void
1337TModule::Streamer::Write(opstream& os) const
1338{
1339 TModule* o = GetObject();
1340 os << o->Name;
1341 os << o->ShouldFree;
1342}
1343
1344#endif
1345
1346} // OWL namespace
1347
1348
1349//----------------------------------------------------------------------------
1350//
1351// Entry (& exit) functions for Owl in a DLL
1352//
1353
1354#if defined(_BUILDOWLDLL)
1355
1356namespace owl {
1357
1359{
1360 if (Module == NULL)
1361 {
1363 GetModuleFileName(hInstance, buffer, _MAX_PATH);
1364 static TModule module(buffer, hInstance);
1365 Module = &module;
1366 TRACEX(OwlApp, 0, "Global Module " << hInstance << ", " << buffer << " created");
1367 }
1368
1369}
1370
1371TModule& GetGlobalModule()
1372{
1373 if (Module == NULL)
1374 {
1377 }
1378
1379 return *Module;
1380}
1381
1382//
1383/// TModule derived class to facilitate streaming pointer to the OWL Library
1384/// the OWL module must be streamed by reference before any pointers to it
1385/// the following code simply prevents writing data back over the OWL module
1386//
1387class _OWLCLASS TObjectWindowsLibrary : public TModule {
1388 public:
1389 TObjectWindowsLibrary(HINSTANCE hInst) : TModule(_T("ObjectWindowsDLL"), hInst){}
1391};
1392
1393
1395
1396# if OWL_PERSISTENT_STREAMS
1397
1398//
1399/// Reads the object from the persistent stream.
1400//
1401void*
1402TObjectWindowsLibrary::Streamer::Read(ipstream&, uint32) const
1403{
1404 return GetObject();
1405}
1406
1407//
1408/// Writes the object into a persistent stream.
1409//
1410void
1411TObjectWindowsLibrary::Streamer::Write(opstream&) const
1412{
1413}
1414
1415#endif
1416
1417
1418//JJH - following stuff is defined in global.cpp, we do not need it here.
1419//Jogy - it is needed in both places for DLL builds.
1420//VH - Reason is that the VC and BC build script doesn't link global.obj for the DLL itself, only for the import lib.
1421//
1422# if !defined(WINELIB)
1423extern TModule* Module = 0; // Global Module ptr in each DLL/EXE
1424# endif // !WINELIB
1425
1426} // OWL namespace
1427
1428# if !defined(BI_COMP_BORLANDC) && !defined(BI_COMP_GNUC)
1429
1430int __cdecl xnew_handler(size_t) {throw std::bad_alloc(); return 0;}
1431
1432static void init_new_handler(void)
1433{
1435}
1436
1437# endif // !defined(BI_COMP_BORLANDC) && !defined(BI_COMP_GNUC)
1438
1439
1441# if defined(BI_COMP_BORLANDC)
1443# else
1444extern "C" BOOL (WINAPI* _pRawDllMain)(HINSTANCE, DWORD, LPVOID); //JJH split this to declaration and initialization
1446# endif
1447
1448extern "C"
1449//# if !defined(BI_COMP_MSC)
1450//BOOL WINAPI RawDllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
1451//# else
1453//# endif
1454{
1456#if OWL_STACKWALKER
1457 //Start gathering memory leaks:
1459#endif
1460
1461# ifdef _UNICODE
1462 // give error message and exit if running Unicode on non-Unicode system
1463 if (::GetVersion() & 0x80000000){
1464 // Note: this message is for programmers who can read english
1465 ::MessageBoxA(nullptr,
1466 "This application or DLL can not be loaded "
1467 "on Windows 95 or on Windows 3.1. It takes advantage "
1468 "of Unicode features only available on Windows NT.",
1469 "OWL Runtime Module", MB_ICONSTOP|MB_OK);
1470 return FALSE; // and fail
1471 }
1472# endif
1473
1474
1475 //
1476 ///! SetErrorMode(GetErrorMode(0)|SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
1477 // add a reference to thread local storage data
1478 TlsAddRefs();
1479
1480 }
1481 else if (dwReason == DLL_PROCESS_DETACH){
1482 TlsRelease();
1483#if OWL_STACKWALKER
1484 //Stop gathering memory leaks:
1486#endif
1487 }
1488 return TRUE; // ok
1489}
1490
1491#if !defined(BI_COMP_BORLANDC)
1492#if defined(WINELIB) //JJH
1493extern "C"
1494#endif
1497#else
1498int WINAPI
1500#endif
1501{
1502 switch (reason) {
1503 case DLL_PROCESS_ATTACH: {
1504#if !defined(BI_COMP_BORLANDC) && !defined(BI_COMP_GNUC)
1506#endif
1507
1508//JJH Ok, we don't need to initialize owl::Module, since TApplication object
1509// does this for us, see also applicat.cpp:420, applicat.h:132
1510//#if !defined(WINELIB)
1511 owl::Module = new owl::TObjectWindowsLibrary(hInstance);
1512//#endif
1513 break;
1514 }
1515 case DLL_PROCESS_DETACH: {
1516 break;
1517 }
1518 }
1519 return true;
1520}
1521
1522/////////////////////////////////////////////////////////////////////////////
1523//
1524// Here VC bug with vector constructor
1525//
1526// Special code to wire up vector deleting destructors
1527// TODO: Jogy - check if this is needed with modern VC++ compilers
1528#if defined(BI_COMP_MSC)
1529static void _OwlForceVectorDelete()
1530{
1531#ifdef _DEBUG
1532 PRECONDITION(false); // never called
1533#endif
1534
1535 new owl::TPoint[2];
1536 new owl::TPointF[2];
1537 new owl::TPointL[2];
1538 new owl::TRect[2];
1539 new owl::TSize[2];
1540 new owl::TColor[2];
1541 new owl::TMenu[2];
1542 new owl::TResId[2];
1543 new owl::TFileTime[2];
1544 new owl::TSystemTime[2];
1545}
1546#endif // BI_COM_MSC
1547#else // else _BUILDOWLDLL
1548////////////////////////////////////////////////////////////////////////////////////////
1549// static lib????
1550/////////////////////////////////////
1551#if defined(BI_COMP_BORLANDC)
1552//
1553// Doesn't work here -> moved to winmain
1554//
1555//
1556// NOTE: We use priority 31 to come just before/after ctr/dtr of global
1557// objects (which are assigned a priorority of 32)
1558//
1559void __initOWL()
1560{
1561 TlsAddRefs();
1562}
1563#pragma startup __initOWL 31
1564
1565//
1566void __termOWL()
1567{
1568 TlsRelease();
1569}
1570#pragma exit __termOWL 31
1571
1572//
1573#elif defined(BI_COMP_MSC)
1574
1575int __cdecl xnew_handler(size_t) { throw std::bad_alloc(); return 0;}
1576
1577static void init_new_handler(void)
1578{
1579//#ifdef __EDG__
1580// std::set_new_handler(&xnew_handler);
1581//#else
1583//#endif
1584}
1585
1586// force initialization early
1587#pragma warning(disable: 4073)
1588#pragma init_seg(lib)
1589
1590static void __initOWL()
1591{
1592 //_hInstance = GetModuleHandleA(NULL);
1593 TlsAddRefs();
1594
1596
1597#if defined(BI_DBCS_SUPPORT)
1598// _setmbcp(_MB_CP_ANSI); // check
1599#endif
1600}
1601
1602//
1603void _cdecl __termOWL()
1604{
1605 TlsRelease();
1606}
1607
1608static char __initOWLS = static_cast<char>(__initOWL(), atexit(&__termOWL));
1609
1610//
1611#elif defined(BI_COMP_GNUC)
1612
1613// //JJH
1614//#if defined(WINELIB)
1615//void __termOWL()
1616//#else
1617void _cdecl __termOWL()
1618//#endif
1619{
1620 TlsRelease();
1621}
1622
1623static void __initOWL()
1624{
1625 TlsAddRefs();
1626}
1627
1628// //JJH
1629//#if defined(WINELIB)
1630//typedef void (__attribute__((__stdcall__)) *STDCALL_FN)();
1631//static char __initOWLS = (char)(__initOWL(),atexit((STDCALL_FN)__termOWL));
1632//#else
1633static char __initOWLS = (char)(__initOWL(),atexit(__termOWL));
1634//#endif
1635
1636#else
1637#error Unknown compiler
1638#endif
1639
1640
1641#endif // defined(_BUILDOWLDLL)
1642
1643namespace owl {
1644//
1645// Inserter for formated output of instance handle
1646//
1647_OWLCFUNC(ostream&)
1648operator <<(ostream& os, const TModule& m)
1649{
1650 return os << static_cast<void*>(m.Handle);
1651}
1652} // OWL namespace
1653
1654
1655/* ========================================================================== */
1656
ULONG DeInitAllocCheck(void)
int InitAllocCheck(eAllocCheckOutput eOutput, BOOL bSetUnhandledExeptionFilter, ULONG ulShowStackAtAlloc)
@ ACOutput_XML
Definition Stackwalker.h:43
Definition of class TAppDictionary.
Definition of class TApplication.
#define CHECK(condition)
Definition checks.h:239
#define WARNX(group, condition, level, message)
Definition checks.h:277
#define WARN(condition, message)
Definition checks.h:273
#define PRECONDITION(condition)
Definition checks.h:227
#define CHECKX(condition, message)
Definition checks.h:245
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
#define TRACEX(group, level, message)
Definition checks.h:263
TApplication * GetApplication(uint pid=0)
Looks up and returns the application associated with a given process ID.
Definition appdict.cpp:192
Derived from TModule and TMsgThread and virtually derived from TEventHandler, TApplication acts as an...
Definition applicat.h:141
static tstring & GetCmdLine()
Return the command line of the application.
Definition applicat.h:644
Class wrapper for management of color values.
Definition color.h:245
Simple encapsulation of the SetErrorMode call.
Definition module.h:352
TFileTime is a class derived from the structure FILETIME.
Definition wsyscls.h:362
Multiple Read, Single Write section.
Definition thread.h:348
The TMenu class encapsulates window menus.
Definition menu.h:77
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TModuleProc(const TModule &module, TNarrowResId id)
Constructs a Module entry object given a narrow Windows resource identifier.
Definition module.cpp:1021
FARPROC Proc
Derived template classes perform type-safe parameter passing on call.
Definition module.h:542
static UINT SysStringLen(BSTR)
Definition module.cpp:1244
static TModule & GetModule()
Definition module.cpp:1223
static HRESULT SysFreeString(BSTR)
Definition module.cpp:1233
static BSTR SysAllocString(const OLECHAR *)
Definition module.cpp:1256
static HRESULT CoCreateInstance(REFCLSID, LPUNKNOWN, DWORD, REFIID, LPVOID *)
Definition module.cpp:1212
static TModule & GetModule()
Definition module.cpp:1202
TPointF is similar to TPoint, but uses floating variables rather than integers.
Definition geometry.h:181
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TPointL is similar to TPoint, but uses long rather than int variables.
Definition geometry.h:132
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
TResId encapsulates a Windows resource identifier.
Definition wsyscls.h:49
The tagSIZE struct is defined as.
Definition geometry.h:234
TSystemTime is a class derived from the structure SYSTEMTIME.
Definition wsyscls.h:420
TPtrArrayIterator< T, TTypedArray< T, T, TStandardAllocator > > Iterator
Definition template.h:854
static BOOL DestroyIcon(HICON)
Definition module.cpp:1078
static UINT GetMenuState(HMENU, UINT, UINT)
Definition module.cpp:1110
static HICON LoadIcon(HINSTANCE, LPCTSTR)
Definition module.cpp:1067
static BOOL GetClassInfo(HINSTANCE, LPCTSTR, LPWNDCLASS)
Definition module.cpp:1088
static int GetMenuString(HMENU, UINT, TCHAR *, int, UINT)
Definition module.cpp:1099
static TModule & GetModule()
Definition module.cpp:1057
static DWORD VerLanguageName(DWORD, TCHAR *, DWORD)
Definition module.cpp:1179
static BOOL VerQueryValue(const LPVOID, TCHAR *, LPVOID, uint *)
Definition module.cpp:1168
static BOOL GetFileVersionInfo(TCHAR *, DWORD, DWORD, LPVOID)
Definition module.cpp:1146
static DWORD GetFileVersionInfoSize(TCHAR *, LPDWORD)
Definition module.cpp:1157
static TModule & GetModule()
Definition module.cpp:1136
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
Definition module.h:47
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
int MessageBox(LPCTSTR text, LPCTSTR caption=0, uint flags=MB_OK) const
Creates and displays a message box that contains a message (text), a title (caption),...
Definition window.cpp:4284
Derived from xmsg, TXBase is the base class for ObjectWindows and ObjectComponents exception-handling...
Definition exbase.h:41
A nested class, TXInvalidModule describes an exception that results from an invalid module.
Definition module.h:302
TXOwl is root class of the ObjectWindows exception hierarchy.
Definition except.h:38
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
#define _tcsncpy
Definition cygwin.h:80
#define _MAX_PATH
Definition cygwin.h:97
#define MAX_PATH
Definition cygwin.h:98
#define _T(x)
Definition cygwin.h:51
Definition of class TFrameWindow.
#define IMPLEMENT_STREAMABLE1(cls, base1)
Definition objstrm.h:1725
#define IMPLEMENT_STREAMABLE(cls)
Definition objstrm.h:1724
#define DECLARE_STREAMABLE(exp, cls, ver)
Definition objstrm.h:1511
static void Raise(const tstring &msg, uint resId=0)
Definition except.cpp:186
static tstring MakeMessage(uint resId, const tstring &infoStr, TModule *module=&GetGlobalModule())
Definition except.cpp:242
auto GetString() const -> tstring
Returns the class name in string form.
Definition module.cpp:74
void Throw()
Throws the exception.
Definition module.cpp:1291
TXInvalidModule(const tstring &name=tstring())
Creates the Invalid Module exception.
Definition module.cpp:1271
HACCEL LoadAccelerators(TResId id) const
Wrapper for the Windows API.
Definition module.cpp:812
auto GetClassInfo(TWindowClassName, WNDCLASS *wndclass) const -> bool
Retrieves information about the given window class.
Definition module.h:1394
HCURSOR LoadCursor(TResId id) const
Wrapper for the Windows API.
Definition module.cpp:892
HICON LoadIcon(TResId name) const
Wrapper for the Windows API.
Definition module.cpp:933
int LoadString(uint id, TCHAR *buf, int maxChars) const
Loads a string resource identified by id into the buffer pointed to by buff.
Definition module.cpp:586
HGLOBAL LoadResource(HRSRC hRsrc) const
Wrapper for the Windows API.
Definition module.h:1352
tstring GetModuleFileName() const
String-aware overload.
Definition module.cpp:555
HRSRC FindResource(TResId id, TResId type) const
Wrapper for the Windows API to find a particular resource.
Definition module.h:1308
TModule(const tstring &name, bool shouldLoad=true, bool mustLoad=true, bool addToList=true)
Constructs a TModule object that is used as an alias for a DLL.
Definition module.cpp:308
virtual ~TModule()
Destructs a TModule, freeing the instance if appropriate, and deleting new'd strings.
Definition module.cpp:414
void InitModule(THandle handle, const tstring &cmdLine)
Finish-up initialization of a module.
Definition module.cpp:470
auto IsString() const -> bool
Definition module.h:54
auto GetAtom() const -> ATOM
Definition module.h:57
HINSTANCE THandle
TModule encapsulates an HINSTANCE.
Definition module.h:79
static TModule * FindResModule(TResId id, TResId type)
Global search for resources.
Definition module.cpp:429
auto GetPointerRepresentation() const -> LPCTSTR
Definition module.h:53
HMENU LoadMenu(TResId id) const
Wrapper for the Windows API.
Definition module.cpp:854
auto IsRegisteredClass(TWindowClassName) const -> bool
Returns true if the given window class has been registered.
Definition module.cpp:1008
uint32 SizeofResource(HRSRC hRsrc) const
Wrapper for the Windows API.
Definition module.h:1369
void SetHandle(THandle handle)
Set the module instance handle.
Definition module.cpp:565
static void Raise(const tstring &name=tstring())
Throws the exception.
Definition module.cpp:1300
HRSRC FindResourceEx(TResId id, TResId type, TLangId langId=LangNeutral) const
Wrapper for the Windows API to find a particular resource.
Definition module.h:1334
static TModule * NextModule(TModule *module=nullptr)
Definition module.cpp:290
void SetName(LPCTSTR name)
Accessor function that sets the name of the module.
Definition module.cpp:439
std::string LoadHtml(TResId) const
Loads the given HTML resource and returns it as a narrow string.
Definition module.cpp:971
TSystemMessage()
default errorId, def language
Definition module.cpp:91
HBITMAP LoadBitmap(TResId id) const
Wrapper for the Windows API.
Definition module.cpp:776
virtual int Error(TXBase &x, uint captionResId, uint promptResId=0)
Replaceable exception handler; may be redefined to process OWL exceptions if canResume is false,...
Definition module.cpp:522
int MessageBox(TWindow *wnd, const tstring &msg, const tstring &title, uint flags=MB_OK) const
Definition module.cpp:110
TXInvalidModule * Clone()
Creates a copy of the exception.
Definition module.cpp:1281
void Init(TLangId langId)
Definition module.cpp:127
int WINAPI DllEntryPoint(HINSTANCE hInstance, uint32 reason, LPVOID)
Definition libmain.cpp:51
long TlsAddRefs()
Definition thread.cpp:761
#define LOCKLIST(s)
Definition module.cpp:175
long TlsRelease()
Definition thread.cpp:766
Definition of class TModule.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
WCHAR * TResCount
Definition module.cpp:575
owl::opstream & operator<<(owl::opstream &os, const TColor &c)
Insert the color value into a persistent output stream.
Definition color.h:498
unsigned long uint32
Definition number.h:34
owl::uint16 TLangId
Holds a language ID, a predefined number that represents a base language and dialect.
Definition lclstrng.h:26
char tchar
Definition defs.h:77
tstring CopyText(int size, TGetText get_text)
Copies text from a C-string (null-terminated character array) into a string object,...
Definition defs.h:317
const TLangId LangNeutral
Definition lclstrng.h:32
TModule * Module
Definition global.cpp:34
TAppDictionary & OWLGetAppDictionary()
Global exported TAppDictionary in Owl.
Definition appdict.cpp:35
OWL_DIAGINFO
Definition animctrl.cpp:14
int HandleGlobalException(owl::TXBase &x, LPCTSTR caption, LPCTSTR canResume=nullptr)
Definition except.cpp:29
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
void InitGlobalModule(HINSTANCE hInstance)
Definition global.cpp:36
TModule & GetGlobalModule()
Definition global.cpp:48
WCHAR * TResText
Definition module.cpp:574
General definitions used by all ObjectWindows programs.
#define _OWLCFUNC(p)
Definition defs.h:342
#define _OWLCLASS
Definition defs.h:338
#define _OWLDATA(p)
Definition defs.h:340
#define COUNTOF(s)
Array element count Important: Only use this with an argument of array type.
Definition defs.h:376
Various types of smart pointer templatized classes.
Definition of container classes used and made available by OWL.
Base window class TWindow definition, including HWND encapsulation.