Hi every one...
This code simply show if your project running from VB6 IDE or running as single exe file, because visual basic 6.0 run your project within VB6.exe process and it doesn't create new exe file for you like VB.NET, this situation make some problems as when you try to use resource with API call, all your functions will get failed.
Program: Check whether project is running VB IDE
Language: VB
(1) Build new project, add a form
(2) Add a command button, namely Command1
(3) Insert the entire code elsewhere
(4) Insert MsgBox IfUsingVB6IDE under Command1
TIP: If Message box reports True, you are indeed running VB IDE
Heads up: The remaining code should be added at the very top of your code pane, or else you may get an error stating code cannot be added after Sub.
[CODE=vb]
Private Declare Function GetModuleBaseNa meA Lib "Psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Private Declare Function GetCurrentProce ss Lib "kernel32" () As Long
Private Const PROCESS_NAME_MA X_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_MA X_BYTES
ProcessHandle = GetCurrentProce ss() 'Get Current Process pseudo handle
ProcessNameLen = GetModuleBaseNa meA(ProcessHand le, App.hInstance, NameBuffer, PROCESS_NAME_MA X_BYTES) 'Get current Process Base module name (file name)
ProcessName = Left$(NameBuffe r, ProcessNameLen) 'clear remaining unused buffer bytes and get only file name
If (UCase$(Process Name) = "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
[/CODE]
Kudos to OP for posting this...
This code simply show if your project running from VB6 IDE or running as single exe file, because visual basic 6.0 run your project within VB6.exe process and it doesn't create new exe file for you like VB.NET, this situation make some problems as when you try to use resource with API call, all your functions will get failed.
Program: Check whether project is running VB IDE
Language: VB
(1) Build new project, add a form
(2) Add a command button, namely Command1
(3) Insert the entire code elsewhere
(4) Insert MsgBox IfUsingVB6IDE under Command1
TIP: If Message box reports True, you are indeed running VB IDE
Heads up: The remaining code should be added at the very top of your code pane, or else you may get an error stating code cannot be added after Sub.
[CODE=vb]
Private Declare Function GetModuleBaseNa meA Lib "Psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Private Declare Function GetCurrentProce ss Lib "kernel32" () As Long
Private Const PROCESS_NAME_MA X_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_MA X_BYTES
ProcessHandle = GetCurrentProce ss() 'Get Current Process pseudo handle
ProcessNameLen = GetModuleBaseNa meA(ProcessHand le, App.hInstance, NameBuffer, PROCESS_NAME_MA X_BYTES) 'Get current Process Base module name (file name)
ProcessName = Left$(NameBuffe r, ProcessNameLen) 'clear remaining unused buffer bytes and get only file name
If (UCase$(Process Name) = "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
[/CODE]
Kudos to OP for posting this...
Comment