@@ -276,9 +276,11 @@ End Type
276276Private Declare Function CloseHandle Lib "kernel32 " (ByVal Handle As Long ) As Long
277277Private Declare Function CreateToolhelp32Snapshot Lib "kernel32 " (ByVal lFlags As Long , ByVal lProcessID As Long ) As Long
278278Private Declare Function GetAsyncKeyState Lib "user32 " (ByVal vKey As Long ) As Integer
279- Private Declare Function GetKeyState Lib "user32 " (ByVal vKey As Long ) As Integer
280279Private Declare Function GetCommandLineW Lib "kernel32 " () As Long
280+ Private Declare Function GetKeyState Lib "user32 " (ByVal vKey As Long ) As Integer
281281Private Declare Function GetModuleFileNameW Lib "kernel32 " (ByVal hModule As Long , ByVal ptrToFileNameBuffer As Long , ByVal nSize As Long ) As Long
282+ Private Declare Function GetModuleHandleW Lib "kernel32 " (ByVal lpModuleName As Long ) As Long
283+ Private Declare Function GetProcAddress Lib "kernel32 " (ByVal hModule As Long , ByVal lpProcName As String ) As Long
282284Private Declare Sub GetNativeSystemInfo Lib "kernel32 " (ByRef lpSystemInfo As OS_SystemInfo )
283285Private Declare Sub GetSystemTimeAsFileTime Lib "kernel32 " (ByRef dstTime As Currency )
284286Private Declare Function GetTempPathW Lib "kernel32 " (ByVal nBufferLength As Long , ByVal lpStrBuffer As Long ) As Long
@@ -347,6 +349,9 @@ End Enum
347349
348350Private m_ThemingAvailable As PD_ThemingAvailable
349351
352+ 'Used to detect if we're running under Wine or not. (Added in 2024-05 to try and solve Wine-specific problems.)
353+ Private m_InsideWine As Boolean , m_LookedForWineAlready As Boolean
354+
350355'Function for returning this application's current memory usage. Note that this function will return warped
351356' values inside the IDE (because the reported total is for *all* of VB6, including the IDE itself).
352357Public Function AppMemoryUsage (Optional returnPeakValue As Boolean = False ) As Long
@@ -635,7 +640,7 @@ End Function
635640'PD will attempt to forcibly enable DEP on Win 7+ (when compiled, obviously).
636641' This may decrease issues with garbage 3rd-party virus and malware scanners.
637642Public Function EnableProcessDEP () As Boolean
638- If (OS.IsWin7OrLater And OS.IsProgramCompiled) Then
643+ If (OS.IsWin7OrLater And OS.IsProgramCompiled And ( Not OS.IsWinActuallyWine) ) Then
639644 Const PROCESS_DEP_ENABLE As Long = &H1 &
640645 SetProcessDEPPolicy PROCESS_DEP_ENABLE
641646 End If
@@ -757,36 +762,88 @@ End Function
757762'Check for a version >= the specified version.
758763Public Function IsVistaOrLater () As Boolean
759764 If (Not m_VersionInfoCached) Then CacheOSVersion
760- IsVistaOrLater = (m_OSVI.dwMajorVersion >= 6 )
765+ If OS.IsWinActuallyWine Then
766+ IsVistaOrLater = False
767+ Else
768+ IsVistaOrLater = (m_OSVI.dwMajorVersion >= 6 )
769+ End If
761770End Function
762771
763772Public Function IsWin7OrLater () As Boolean
764773 If (Not m_VersionInfoCached) Then CacheOSVersion
765- IsWin7OrLater = (m_OSVI.dwMajorVersion > 6 ) Or ((m_OSVI.dwMajorVersion = 6 ) And (m_OSVI.dwMinorVersion >= 1 ))
774+ If OS.IsWinActuallyWine Then
775+ IsWin7OrLater = False
776+ Else
777+ IsWin7OrLater = (m_OSVI.dwMajorVersion > 6 ) Or ((m_OSVI.dwMajorVersion = 6 ) And (m_OSVI.dwMinorVersion >= 1 ))
778+ End If
766779End Function
767780
768781Public Function IsWin8OrLater () As Boolean
769782 If (Not m_VersionInfoCached) Then CacheOSVersion
770- IsWin8OrLater = (m_OSVI.dwMajorVersion > 6 ) Or ((m_OSVI.dwMajorVersion = 6 ) And (m_OSVI.dwMinorVersion >= 2 ))
783+ If OS.IsWinActuallyWine Then
784+ IsWin8OrLater = False
785+ Else
786+ IsWin8OrLater = (m_OSVI.dwMajorVersion > 6 ) Or ((m_OSVI.dwMajorVersion = 6 ) And (m_OSVI.dwMinorVersion >= 2 ))
787+ End If
771788End Function
772789
773790Public Function IsWin81OrLater () As Boolean
774791 If (Not m_VersionInfoCached) Then CacheOSVersion
775- IsWin81OrLater = (m_OSVI.dwMajorVersion > 6 ) Or ((m_OSVI.dwMajorVersion = 6 ) And (m_OSVI.dwMinorVersion >= 3 ))
792+ If OS.IsWinActuallyWine Then
793+ IsWin81OrLater = False
794+ Else
795+ IsWin81OrLater = (m_OSVI.dwMajorVersion > 6 ) Or ((m_OSVI.dwMajorVersion = 6 ) And (m_OSVI.dwMinorVersion >= 3 ))
796+ End If
776797End Function
777798
778799' (NOTE: the Win-10 check requires a manifest, so don't rely on it in the IDE. Also, MS doesn't guarantee that this
779800' check will remain valid forever, though it does work as of Windows 10-1703.)
780801Public Function IsWin10OrLater () As Boolean
781802 If (Not m_VersionInfoCached) Then CacheOSVersion
782- IsWin10OrLater = (m_OSVI.dwMajorVersion > 6 ) Or ((m_OSVI.dwMajorVersion = 6 ) And (m_OSVI.dwMinorVersion >= 4 ))
803+ If OS.IsWinActuallyWine Then
804+ IsWin10OrLater = False
805+ Else
806+ IsWin10OrLater = (m_OSVI.dwMajorVersion > 6 ) Or ((m_OSVI.dwMajorVersion = 6 ) And (m_OSVI.dwMinorVersion >= 4 ))
807+ End If
783808End Function
784809
785810Public Function GetWin10Build () As Long
786811 If (Not m_VersionInfoCached) Then CacheOSVersion
787812 GetWin10Build = m_OSVI.dwBuildNumber
788813End Function
789814
815+ 'Are we running inside Wine? Thanks to StackOverflow for the implementation idea:
816+ ' https://stackoverflow.com/questions/7372388/determine-whether-a-program-is-running-under-wine-at-runtime
817+ '
818+ 'PD doesn't officially support Wine, but I've found that lying to PD and claiming that Wine is actually XP
819+ ' produces a reasonably usable version of the app.
820+ Public Function IsWinActuallyWine () As Boolean
821+
822+ 'Cache check once, on first call
823+ If (Not m_LookedForWineAlready) Then
824+
825+ m_LookedForWineAlready = True
826+
827+ Dim modName As String
828+ modName = "ntdll.dll"
829+
830+ Dim hMod As Long
831+ hMod = GetModuleHandleW(StrPtr(modName))
832+ If (hMod <> 0 ) Then
833+ Dim hProc As Long
834+ hProc = GetProcAddress(hMod, "wine_get_version" )
835+ m_InsideWine = (hProc <> 0 )
836+ Else
837+ PDDebug.LogAction "WARNING: couldn't find ntdll?"
838+ m_InsideWine = False
839+ End If
840+
841+ End If
842+
843+ IsWinActuallyWine = m_InsideWine
844+
845+ End Function
846+
790847'Return the number of logical cores on this system
791848Public Function LogicalCoreCount () As Long
792849 Dim tmpSysInfo As OS_SystemInfo
0 commit comments