Browse Subversion Repository
Contents of /trunk/teraterm/common/compat_w95.h
Parent Directory
| Revision Log
Revision 3227 -
( show annotations)
( download)
( as text)
Tue Mar 24 15:10:33 2009 UTC
(4 years, 1 month ago)
by maya
File MIME type: text/x-chdr
File size: 2194 byte(s)
CVS から SVN へ移行: 改行コードを LF から CR+LF へ変換
| 1 |
// VS2005でビルドされたバイナリが Windows95 でも起動できるようにするために、
|
| 2 |
// IsDebuggerPresent()のシンボル定義を追加する。
|
| 3 |
//
|
| 4 |
// cf.http://jet2.u-abel.net/program/tips/forceimp.htm
|
| 5 |
|
| 6 |
// 装飾された名前のアドレスを作るための仮定義
|
| 7 |
// (これだけでインポートを横取りしている)
|
| 8 |
#ifdef __cplusplus
|
| 9 |
extern "C" {
|
| 10 |
#endif
|
| 11 |
int WINAPI _imp__IsDebuggerPresent()
|
| 12 |
{ return PtrToInt((void*) &_imp__IsDebuggerPresent); }
|
| 13 |
#ifdef __cplusplus
|
| 14 |
}
|
| 15 |
#endif
|
| 16 |
|
| 17 |
// 実際に横取り処理を行う関数
|
| 18 |
#ifdef __cplusplus
|
| 19 |
extern "C" {
|
| 20 |
#endif
|
| 21 |
BOOL WINAPI Cover_IsDebuggerPresent()
|
| 22 |
{ return FALSE; }
|
| 23 |
#ifdef __cplusplus
|
| 24 |
}
|
| 25 |
#endif
|
| 26 |
|
| 27 |
// 関数が実際に呼び出されたときに備えて
|
| 28 |
// 横取り処理関数を呼び出させるための下準備
|
| 29 |
#ifdef __cplusplus
|
| 30 |
extern "C" {
|
| 31 |
#endif
|
| 32 |
void __stdcall DoCover_IsDebuggerPresent()
|
| 33 |
{
|
| 34 |
DWORD dw;
|
| 35 |
DWORD_PTR FAR* lpdw;
|
| 36 |
OSVERSIONINFO osvi;
|
| 37 |
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
| 38 |
// Windows95 でなければここでおわり
|
| 39 |
GetVersionEx(&osvi);
|
| 40 |
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT ||
|
| 41 |
// VER_PLATFORM_WIN32_WINDOWS なら、あとは Minor だけで判定できる
|
| 42 |
// osvi.dwMajorVersion > 4 ||
|
| 43 |
osvi.dwMinorVersion > 0) {
|
| 44 |
return;
|
| 45 |
}
|
| 46 |
// 横取り関数を設定するアドレスを取得
|
| 47 |
lpdw = (DWORD_PTR FAR*) &_imp__IsDebuggerPresent;
|
| 48 |
// このアドレスを書き込めるように設定
|
| 49 |
// (同じプログラム内なので障害なく行える)
|
| 50 |
VirtualProtect(lpdw, sizeof(DWORD_PTR), PAGE_READWRITE, &dw);
|
| 51 |
// 横取り関数を設定
|
| 52 |
*lpdw = (DWORD_PTR)(FARPROC) Cover_IsDebuggerPresent;
|
| 53 |
// 読み書きの状態を元に戻す
|
| 54 |
VirtualProtect(lpdw, sizeof(DWORD_PTR), dw, NULL);
|
| 55 |
}
|
| 56 |
#ifdef __cplusplus
|
| 57 |
}
|
| 58 |
#endif
|
| 59 |
|
| 60 |
// アプリケーションが初期化される前に下準備を呼び出す
|
| 61 |
// ※ かなり早くに初期化したいときは、このコードを
|
| 62 |
// ファイルの末尾に書いて「#pragma init_seg(lib)」を、
|
| 63 |
// この変数宣言の手前に書きます。
|
| 64 |
// 初期化を急ぐ必要が無い場合は WinMain 内から
|
| 65 |
// DoCover_IsDebuggerPresent を呼び出して構いません。
|
| 66 |
/* C言語では以下のコードは、コンパイルエラーとなるので、WinMain, DllMain から呼ぶ。*/
|
| 67 |
#ifdef __cplusplus
|
| 68 |
extern "C" {
|
| 69 |
int s_DoCover_IsDebuggerPresent
|
| 70 |
= (int) (DoCover_IsDebuggerPresent(), 0);
|
| 71 |
}
|
| 72 |
#endif
|
|