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