Author |
Message |
Richar #1 / 10
|
 determining if VB application is running in development mode
Hi, how can I tell if a VB application/DLL is currently only being run in the development environment or stand-alone? Richard
|
Wed, 18 Jun 1902 08:00:00 GMT |
|
 |
Kurt Barla #2 / 10
|
 determining if VB application is running in development mode
Richard In VB go to your Project properties and click on the Make tab in the box labeled "Command Line Arguments" type anything you like, for example put "DEBUG" in there. Then in your code use something like this. If Command = "DEBUG" then..... Hope this helps! Kurt
Quote: > Hi, how can I tell if a VB application/DLL is currently only being run in > the development environment or stand-alone? > Richard
|
Wed, 18 Jun 1902 08:00:00 GMT |
|
 |
Ken Halte #3 / 10
|
 determining if VB application is running in development mode
I do basically the same thing except..... Instead of the word "DEBUG" which is easily passed as a command line argument to the compiled exe, I use "D|GN M?d?" with all of those funky characters. It just makes it a little harder for someone to pass. Another way is.... '========== Option Explicit Private Sub Form_Load() Show Print DesignMode End Sub Public Function DesignMode() As Boolean 'Place this function in a bas module or wherever. On Error Resume Next Debug.Print 1 / 0 DesignMode = (Err.Number <> 0) End Function '========== DesignMode will be True for the IDE and False for the EXE (since VB doesn't include Debug.Print in a compiled program) Quote:
> Richard > In VB go to your Project properties and click on the Make tab in the box > labeled "Command Line Arguments" type anything you like, for example put > "DEBUG" in there. Then in your code use something like this. > If Command = "DEBUG" then..... > Hope this helps! > Kurt
> > Hi, how can I tell if a VB application/DLL is currently only being run in > > the development environment or stand-alone? > > Richard
|
Wed, 18 Jun 1902 08:00:00 GMT |
|
 |
Thunder Scientific Corporatio #4 / 10
|
 determining if VB application is running in development mode
This works in a VB6 standard exe: On Error Resume Next Debug.Print 1 \ 0 If Err Then 'in IDE Err.Clear mnuTest.Visible = True Else 'not in IDE mnuTest.Visible = False End If Quote:
>Hi, how can I tell if a VB application/DLL is currently only being run in >the development environment or stand-alone? >Richard
|
Wed, 18 Jun 1902 08:00:00 GMT |
|
 |
RobSmit #5 / 10
|
 determining if VB application is running in development mode
If you don't mind raising and trapping an error: On Error Resume Next Debug.Print 1/0 bWeAreInTheIDE = (Err.Number <> 0) Or a more complex function that avoids errors: Public Function IsCompiled() As Boolean Static s_iState As Integer Static s_bCompiled As Boolean If s_iState = 0 Then ' first time we've called this function s_bCompiled = True s_iState = 1 ' call IsCompiled() recursively, ONLY if run from the IDE... Debug.Assert Not IsCompiled() s_iState = 2 ElseIf s_iState = 1 Then ' only get to here if called recursively, in which case we are NOT compiled s_bCompiled = False End If IsCompiled = s_bCompiled End Function Both use the fact that methods of the Debug object are only executed in the IDE, and not in a compiled EXE. -- RobSmith
: : Hi, how can I tell if a VB application/DLL is currently only being run in : the development environment or stand-alone? : : Richard : : :
|
Wed, 18 Jun 1902 08:00:00 GMT |
|
 |
Jeff Gosli #6 / 10
|
 determining if VB application is running in development mode
Quote:
> Hi, how can I tell if a VB application/DLL is currently only being run in > the development environment or stand-alone?
While the other ways will show you if you are in the IDE *FROM* the ide, the following code can be used internally to the program to tell you if you are running VB at the same time as your program. It checks the task list for VB5 or VB6. This sort of code is most often used to check for registered versions of code in a compiled run. What most people want to do is check to to see if their control is registered ONLY when not running in the IDE(ie only show the annoying boxes if the person decides to compile and distribute the program). here goes...(BTW this is 32 bit only code, ie vb5 and vb6) Add it to a new module, and call it like so if DevelopmentEnvironment(myForm.hWnd) then 'working in IDE else 'running standalone endif ===cut=== Option Explicit Declare Function apiGetModuleFileName Lib "kernel32" Alias _ "GetModuleFileNameA" (ByVal hModule As Long, ByVal _ lpFileName As String, ByVal nSize As Long) As Long Declare Function apiGetWindowWord Lib "user32" Alias _ "GetWindowWord" (ByVal hwnd As Long, ByVal nIndex As _ Long) As Integer Global Const GWW_HINSTANCE = (-6) Function DevelopmentEnvironment(my_hwnd As Long) As Boolean Dim ModuleName As String Dim FileName As String Dim hInst, ret As Integer ModuleName = String$(128, Chr$(0)) ' Get the hInstance application: hInst = apiGetWindowWord(my_hwnd, GWW_HINSTANCE) ' Get the ModuleFileName: ' Enter the following two lines as one, single line: ModuleName = Left$(ModuleName, apiGetModuleFileName(hInst, ModuleName, Len(ModuleName))) If (Len(ModuleName)) > 0 Then ' Get the "." in the file name. Then go back three characters. ' FileName should = \VB.EXE, so check for the backslash (\) ' because FileName could be GVB.EXE, which isn't the ' VB executable name: FileName = Mid$(ModuleName, InStr(ModuleName, ".") - 4) If FileName = "\VB6.EXE" Or FileName = "\VB5.EXE" Then DevelopmentEnvironment = True Else DevelopmentEnvironment = False End If End If End Function ===cut=== -- ---------------------------------------------------------------------------- | Jeff Goslin - MCSD,MCP | "Oh Bentson, you are so mercifully free from the |
---------------------------------------------------------------------------- | how come everyone elses religion is a cult but your cult is a religion | ---------------------------------------------------------------------------- | XGenetic, the ActiveX Artificial Intelligence Genetic Algorithm | | http://www.winsite.com/info/pc/win95/demo/xgen-sw.zip/ | ----------------------------------------------------------------------------
|
Wed, 18 Jun 1902 08:00:00 GMT |
|
 |
Alex. Nitulesc #7 / 10
|
 determining if VB application is running in development mode
I'm using this: Private Sub Command1_Click() Dim lpClassName As String * 255 Dim strClassName As String 'At runtime VB class names have the prefix "ThunderRT," for example: ThunderCheckBox becomes ThunderRTCheckBox at runtime. GetClassName Me.hwnd, lpClassName, 256 strClassName = Left(lpClassName, InStr(lpClassName, Chr(0)) - 1) 'In run time, it will contain the string "RT": If InStr(1, strClassName, "ThunderRT", vbTextCompare) > 0 Then MsgBox "Run Time" Else MsgBox "Design Time" End If End Sub
Quote: > Hi, how can I tell if a VB application/DLL is currently only being run in > the development environment or stand-alone? > Richard
|
Wed, 18 Jun 1902 08:00:00 GMT |
|
 |
Richar #8 / 10
|
 determining if VB application is running in development mode
Thank you to all who took the time to reply, your suggestions were varied and I will give each one a try to see which one works best for me, I think Jeff Goslin was the closest to what I was looking for, I need to be able to disable a DLL when running stand-alone, and only allow it to run in the IDE for demonstration purposes Thanks again to everyone ;o) Richard -- ...
Quote: > Hi, how can I tell if a VB application/DLL is currently only being run in > the development environment or stand-alone? > Richard
|
Wed, 18 Jun 1902 08:00:00 GMT |
|
 |
Bob Butle #9 / 10
|
 determining if VB application is running in development mode
<cut> Quote: > Debug.Assert Not IsCompiled() <cut> > Both use the fact that methods of the Debug object are only executed in the > IDE, and not in a compiled EXE.
<cut> Just a minor clarification: not all methods of the Debug object are totally discarded during compilation. If you change your code above to use "Debug.Print Not IsCompiled()" then the routine fails when compiled. This is because although the Debug.Print is ignored, any function calls in the line are still done. Apparently this is not true for Debug.Assert since that does work. -- Please reply via the newsgroup only Sent via Deja.com http://www.deja.com/ Before you buy.
|
Wed, 18 Jun 1902 08:00:00 GMT |
|
 |
David Allsop #10 / 10
|
 determining if VB application is running in development mode
The reason for this lies in what Assertions actually are. Debug.Print is designed for where you are actually evaluating something and might want to see the results at debugging time. Debug.Assert is Microsofts notion of an assertion language in VB. Assertion languages (for example Eiffel) allow to specify Preconditions and Postconditions as well as Invariant clauses on classes and routines. Such assertions are only tests and so would not need to be evaluated at runtime. The method used here takes advantage of this - really, the Not IsCompiled() function should be evaluated at runtime because it's not a pure function, but let's not get into a discussion of state machines!!!!! David Allsopp
Quote:
> <cut> > > Debug.Assert Not IsCompiled() > <cut> > > Both use the fact that methods of the Debug object are only executed > in the > > IDE, and not in a compiled EXE. > <cut> > Just a minor clarification: not all methods of the Debug object are > totally discarded during compilation. If you change your code above to > use "Debug.Print Not IsCompiled()" then the routine fails when > compiled. This is because although the Debug.Print is ignored, any > function calls in the line are still done. Apparently this is not true > for Debug.Assert since that does work. > -- > Please reply via the newsgroup only > Sent via Deja.com http://www.deja.com/ > Before you buy.
|
Wed, 18 Jun 1902 08:00:00 GMT |
|
|