1 | #include "stdafx.h"
|
---|
2 | #include <uxtheme.h>
|
---|
3 |
|
---|
4 | DWORD const PROCESS_DEP_ENABLE = 0x00000001;
|
---|
5 |
|
---|
6 | std::string ActiveBasic::Common::Environment::rootPath;
|
---|
7 | bool ActiveBasic::Common::Environment::isRemoveExternal = false;
|
---|
8 |
|
---|
9 | using namespace ActiveBasic::Common;
|
---|
10 |
|
---|
11 | void Environment::SetAbdevRootPath( const std::string &rootPath )
|
---|
12 | {
|
---|
13 | Environment::rootPath = Jenga::Common::Path::MakeFullPath( rootPath, Jenga::Common::Environment::GetAppDir() );
|
---|
14 | }
|
---|
15 | const std::string Environment::GetAbdevRootPath()
|
---|
16 | {
|
---|
17 | if( rootPath.empty() )
|
---|
18 | {
|
---|
19 | SetAbdevRootPath( "" );
|
---|
20 | }
|
---|
21 | return rootPath;
|
---|
22 | }
|
---|
23 |
|
---|
24 | const std::string Environment::GetUserAppDir()
|
---|
25 | {
|
---|
26 | return Jenga::Common::Environment::GetUserAppDir() + "\\ActiveBasic";
|
---|
27 | }
|
---|
28 |
|
---|
29 | const std::string Environment::GetCompilerExePath( Platform::EnumType platform )
|
---|
30 | {
|
---|
31 | switch( platform )
|
---|
32 | {
|
---|
33 | case Platform::X86:
|
---|
34 | return rootPath + "\\bin\\x86\\abc.exe";
|
---|
35 | case Platform::X64:
|
---|
36 | return rootPath + "\\bin\\x64\\abc.exe";
|
---|
37 | }
|
---|
38 | throw;
|
---|
39 | }
|
---|
40 |
|
---|
41 | void* operator new( std::size_t n )
|
---|
42 | {
|
---|
43 | if ( void* p = dlmalloc(n) ){
|
---|
44 | return p;
|
---|
45 | }
|
---|
46 | else{
|
---|
47 | throw std::bad_alloc();
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | void* operator new[]( std::size_t n )
|
---|
52 | {
|
---|
53 | return ::operator new( n );
|
---|
54 | }
|
---|
55 |
|
---|
56 | void operator delete( void* p )
|
---|
57 | {
|
---|
58 | dlfree( p );
|
---|
59 | }
|
---|
60 |
|
---|
61 | void operator delete[]( void* p )
|
---|
62 | {
|
---|
63 | ::operator delete( p );
|
---|
64 | }
|
---|
65 |
|
---|
66 | typedef HRESULT (WINAPI* PFN_EnableThemeDialogTexture)(HWND, DWORD);
|
---|
67 |
|
---|
68 | HMODULE hmodUxTheme = LoadLibrary("uxtheme");
|
---|
69 |
|
---|
70 | HRESULT ApplyDialogTexture( HWND hwnd )
|
---|
71 | {
|
---|
72 | if( hmodUxTheme )
|
---|
73 | {
|
---|
74 | if( PFN_EnableThemeDialogTexture pfn = reinterpret_cast<PFN_EnableThemeDialogTexture>(
|
---|
75 | GetProcAddress(hmodUxTheme, "EnableThemeDialogTexture")) )
|
---|
76 | {
|
---|
77 | return pfn(hwnd, ETDT_ENABLETAB);
|
---|
78 | }
|
---|
79 | }
|
---|
80 | return E_NOTIMPL;
|
---|
81 | }
|
---|
82 |
|
---|
83 | BOOL ActiveBasic::Common::EnableNX()
|
---|
84 | {
|
---|
85 | typedef BOOL (WINAPI* PFNSETDEP)(DWORD);
|
---|
86 |
|
---|
87 | HMODULE hmodKernel = GetModuleHandle(TEXT("KERNEL32.DLL"));
|
---|
88 | if (PFNSETDEP pfnSetDEP = reinterpret_cast<PFNSETDEP>(GetProcAddress(hmodKernel, "SetProcessDEPPolicy")))
|
---|
89 | {
|
---|
90 | return pfnSetDEP(PROCESS_DEP_ENABLE);
|
---|
91 | }
|
---|
92 | else
|
---|
93 | {
|
---|
94 | return FALSE;
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | void ActiveBasic::Common::SetHeapOptions()
|
---|
99 | {
|
---|
100 | // SetDllDirectory(_T(""));
|
---|
101 | HMODULE hmodKernel = GetModuleHandle(TEXT("KERNEL32.DLL"));
|
---|
102 |
|
---|
103 | typedef BOOL (WINAPI* HSI)(HANDLE, HEAP_INFORMATION_CLASS ,PVOID, SIZE_T);
|
---|
104 | HSI pHsi = reinterpret_cast<HSI>(GetProcAddress(hmodKernel, "HeapSetInformation"));
|
---|
105 | if (!pHsi)
|
---|
106 | {
|
---|
107 | return;
|
---|
108 | }
|
---|
109 |
|
---|
110 | ULONG enableLFH = 2;
|
---|
111 | pHsi(GetProcessHeap(), HeapCompatibilityInformation, &enableLFH, sizeof enableLFH);
|
---|
112 |
|
---|
113 | #ifndef HeapEnableTerminationOnCorruption
|
---|
114 | # define HeapEnableTerminationOnCorruption (HEAP_INFORMATION_CLASS)1
|
---|
115 | #endif
|
---|
116 |
|
---|
117 | pHsi(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
|
---|
118 | }
|
---|