source: dev/branches/egtra/ab5.0/abdev/ab_common/src/Environment.cpp@ 774

Last change on this file since 774 was 773, checked in by イグトランス (egtra), 13 years ago

セキュリティ対策の機能を有効化

File size: 2.6 KB
Line 
1#include "stdafx.h"
2#include <uxtheme.h>
3
4std::string ActiveBasic::Common::Environment::rootPath;
5bool ActiveBasic::Common::Environment::isRemoveExternal = false;
6
7using namespace ActiveBasic::Common;
8
9void Environment::SetAbdevRootPath( const std::string &rootPath )
10{
11 Environment::rootPath = Jenga::Common::Path::MakeFullPath( rootPath, Jenga::Common::Environment::GetAppDir() );
12}
13const std::string Environment::GetAbdevRootPath()
14{
15 if( rootPath.empty() )
16 {
17 SetAbdevRootPath( "" );
18 }
19 return rootPath;
20}
21
22const std::string Environment::GetUserAppDir()
23{
24 return Jenga::Common::Environment::GetUserAppDir() + "\\ActiveBasic";
25}
26
27const 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
39void* 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
49void* operator new[]( std::size_t n )
50{
51 return ::operator new( n );
52}
53
54void operator delete( void* p )
55{
56 dlfree( p );
57}
58
59void operator delete[]( void* p )
60{
61 ::operator delete( p );
62}
63
64typedef HRESULT (WINAPI* PFN_EnableThemeDialogTexture)(HWND, DWORD);
65
66HMODULE hmodUxTheme = LoadLibrary("uxtheme");
67
68HRESULT 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
81BOOL 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
96void 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}
Note: See TracBrowser for help on using the repository browser.