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.
Expand|Select|Wrap|Line Numbers
- 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