dynamically import functions from ntdll on startup Modified: trunk/reactos/subsys/system/cmd/cmd.c _____
Modified: trunk/reactos/subsys/system/cmd/cmd.c --- trunk/reactos/subsys/system/cmd/cmd.c 2005-07-29 17:35:22 UTC (rev 16877) +++ trunk/reactos/subsys/system/cmd/cmd.c 2005-07-29 18:01:01 UTC (rev 16878) @@ -164,10 +164,10 @@
HANDLE hOut; HANDLE hConsole; HANDLE CMD_ModuleHandle; +HMODULE NtDllModule;
-static NtQueryInformationProcessProc NtQueryInformationProcessPtr; -static NtReadVirtualMemoryProc NtReadVirtualMemoryPtr; -static BOOL NtDllChecked = FALSE; +static NtQueryInformationProcessProc NtQueryInformationProcessPtr = NULL; +static NtReadVirtualMemoryProc NtReadVirtualMemoryPtr = NULL;
#ifdef INCLUDE_CMD_COLOR WORD wColor; /* current color */ @@ -193,29 +193,7 @@ PROCESS_BASIC_INFORMATION Info; PEB ProcessPeb; ULONG BytesRead; - HMODULE NtDllModule;
- /* Some people like to run ReactOS cmd.exe on Win98, it helps in the - build process. So don't link implicitly against ntdll.dll, load it - dynamically instead */ - if (! NtDllChecked) - { - NtDllChecked = TRUE; - NtDllModule = LoadLibrary(_T("ntdll.dll")); - if (NULL == NtDllModule) - { - /* Probably non-WinNT system. Just wait for the commands - to finish. */ - NtQueryInformationProcessPtr = NULL; - NtReadVirtualMemoryPtr = NULL; - return TRUE; - } - NtQueryInformationProcessPtr = (NtQueryInformationProcessProc) - GetProcAddress(NtDllModule, "NtQueryInformationProcess"); - NtReadVirtualMemoryPtr = (NtReadVirtualMemoryProc) - GetProcAddress(NtDllModule, "NtReadVirtualMemory"); - } - if (NULL == NtQueryInformationProcessPtr || NULL == NtReadVirtualMemoryPtr) { return TRUE; @@ -1258,8 +1236,33 @@
//INT len; //TCHAR *ptr, *cmdLine; + + /* get version information */ + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx (&osvi);
+ /* Some people like to run ReactOS cmd.exe on Win98, it helps in the + build process. So don't link implicitly against ntdll.dll, load it + dynamically instead */
+ if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) + { + /* ntdll is always present on NT */ + NtDllModule = GetModuleHandle(TEXT("ntdll.dll")); + } + else + { + /* not all 9x versions have a ntdll.dll, try to load it */ + NtDllModule = LoadLibrary(TEXT("ntdll.dll")); + } + + if (NtDllModule != NULL) + { + NtQueryInformationProcessPtr = (NtQueryInformationProcessProc)GetProcAddress(NtDllModule, "NtQueryInformationProcess"); + NtReadVirtualMemoryPtr = (NtReadVirtualMemoryProc)GetProcAddress(NtDllModule, "NtReadVirtualMemory"); + } + + #ifdef _DEBUG INT x;
@@ -1271,10 +1274,6 @@ DebugPrintf (_T("]\n")); #endif
- /* get version information */ - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx (&osvi); - InitLocale ();
/* get default input and output console handles */ @@ -1478,6 +1477,11 @@ RemoveBreakHandler (); SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE ), ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT ); + + if (NtDllModule != NULL) + { + FreeLibrary(NtDllModule); + } }
#ifdef __REACTOS__