嗨,大家好...
这段代码只是显示您的项目是从VB6 IDE运行还是作为单个exe文件运行,因为Visual Basic 6.0在VB6.exe进程中运行了您的项目,并且它不会像VB.NET那样为您创建新的exe文件。当您尝试通过API调用使用资源时,所有功能都会失败。
程序:检查项目是否正在运行VB IDE 语言: VB(1)新建工程,添加表格
(2)添加命令按钮,即Command1
(3)将整个代码插入其他位置
(4)插入
MsgBox IfUsingVB6IDE在Command1 提示下:如果消息框报告为True,则说明您确实在运行VB IDE 抬头:剩余的代码应添加在代码窗格的最顶部,否则您可能会收到错误消息,表明无法在Sub之后添加代码。
Private Declare Function GetModuleBaseNameA Lib "Psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Const PROCESS_NAME_MAX_BYTES As Long = 255
Private Property Get IfUsingVB6IDE() As Boolean
Dim ProcessHandle As Long
Dim ProcessName As String
Dim ProcessNameLen As Long
Dim NameBuffer As String * PROCESS_NAME_MAX_BYTES
ProcessHandle = GetCurrentProcess() 'Get Current Process pseudo handle
ProcessNameLen = GetModuleBaseNameA(ProcessHandle, App.hInstance, NameBuffer, PROCESS_NAME_MAX_BYTES) 'Get current Process Base module name (file name)
ProcessName = Left$(NameBuffer, ProcessNameLen) 'clear remaining unused buffer bytes and get only file name
If (UCase$(ProcessName) = "VB6.EXE") Then IfUsingVB6IDE = True 'if current process VB6.exe then we are in VB6 IDE, if else we running as separated process
End Property
Private Sub Command1_Click()
MsgBox IfUsingVB6IDE
End Sub
致敬OP发布此...
From: https://bytes.com/topic/visual-basic/insights/739681-check-whether-project-running-vb-ide