Connecting Tech Pros Worldwide Help | Site Map

Check whether project is running VB IDE

AHMEDYO's Avatar
Member
 
Join Date: Nov 2007
Location: Cairo,Egypt
Posts: 112
#1   Nov 21 '07
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. 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
  4. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
  5.  
  6. Private Const PROCESS_NAME_MAX_BYTES As Long = 255 
  7.  
  8. Private Property Get IfUsingVB6IDE() As Boolean
  9. Dim ProcessHandle As Long
  10. Dim ProcessName As String
  11. Dim ProcessNameLen As Long
  12. Dim NameBuffer As String * PROCESS_NAME_MAX_BYTES
  13. ProcessHandle = GetCurrentProcess() 'Get Current Process pseudo handle
  14. ProcessNameLen = GetModuleBaseNameA(ProcessHandle, App.hInstance, NameBuffer, PROCESS_NAME_MAX_BYTES) 'Get current Process Base module name (file name)
  15. ProcessName = Left$(NameBuffer, ProcessNameLen) 'clear remaining unused buffer bytes and get only file name
  16. 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
  17. End Property
  18.  
  19. Private Sub Command1_Click()
  20. MsgBox IfUsingVB6IDE
  21. End Sub
  22.  
  23.  
Kudos to OP for posting this...

Last edited by Dököll; Nov 27 '07 at 02:27 AM. Reason: Added info



Reply