Solved

OCX detect develop environment

Posted on 2001-07-12
17
247 Views
Last Modified: 2006-11-17
How can I detect if my VB OCX is placed in a develop environment ( as VB, C++, Delphi, etc) ?

Thanks in advance,

Carlos Rodrigues
0
Comment
Question by:Carlos_Rodrigues
  • 6
  • 5
  • 3
  • +3
17 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6276453
Check  out this:
App.StartMode

Not sure as value, but should be ok most of the time...
Cheers
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6276680
If you don't want other programmer using your control into their projects, you should check "Require License Key" box from the project properties.

Cut from the VB-Help file:

Require License Key

Enables licensing for ActiveX Control projects (projects that compile to .ocx files), not to .exe or .dll files. A Visual Basic license file (*.vbl) will be created when you build the project. The *.vbl must be registered on the user?s machine for the components to be used in the design environment. The SetUp Wizard will build a setup program that properly registers the information in the *.vbl file on the end user's machine when that setup program is run.
0
 

Expert Comment

by:viklele
ID: 6284695
Here is a small function that tells you if your application is executing from within VB IDE. I had written this a while ago for one of my projects.

I have put code of VB6 IDE, you can easily add appropriate class names for other IDEs.

<CODE>
<PRE>
'----------------------------------------------------------
' IsDesignMode :
'
' Returns true if program is in VB design mode.
'
' Returns false if the program is being executed either
' through the VB IDE or otherwise (compiled execution)
'
' Use this for stopping subclassing duing design mode
' Subclassing during design mode has a potential of causing
' crashes.
'----------------------------------------------------------
Public Function IsDesignMode(hParent As Long) As Boolean
Dim lRet As Long, hTopWindow As Long
Dim bRet As Boolean
Dim sClassName As String

   While (hParent <> 0)
      hTopWindow = hParent
      hParent = GetParent(hParent)
   Wend
   
   sClassName = Space(255)
   lRet = GetClassName(hTopWindow, sClassName, Len(sClassName) - 1)
   sClassName = Left(sClassName, lRet)
   
   Select Case sClassName
      '-- for supporting other IDEs, add class name here --
      Case "wndclass_desked_gsk" 'VB6 IDE
         bRet = True

      Case Else
         bRet = False
   End Select
     
   IsDesignMode = bRet
End Function
</PRE>
</CODE>

Hope this helps.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 5

Accepted Solution

by:
KDivad earned 100 total points
ID: 6284705
To check to see if your (compiled) ocx is being used in the VB IDE or in a compiled exe, then use:

Ambient.UserMode

True indicates either an exe or VB in run mode. False indicates VB in design mode.


To check to see if your project is in the IDE or is an exe then use this: (Same result as viklele, but with a LOT less code and is version independent)

Public Function InIDE() As Boolean

On Error Resume Next
    Debug.Print 1 / 0
    InIDE = (Err.Number <> 0)

End Sub
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6290630
I'm with KDivad on this one!
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6291046
Thanks! <grin>
0
 

Expert Comment

by:viklele
ID: 6292251
KDidav, thanks.

Much better solution than mine. I will update my code library too.

0
 
LVL 5

Expert Comment

by:KDivad
ID: 6292390
You're welcome.
I got the idea when I heard somewhere that Debug statements aren't included in the final exe. I started wondering if I could somehow use that to determine EXE/IDE status...

Now I wonder if Carlos is coming back.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6295145
Give the points to KDivad

If Ambient.UserMode = true then err.raise 999, "Cannot use my control without purchasing it!"
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6295216
Umm... That would prevent a compiled exe from using it! You want False.

<< True indicates ... an exe ...>>

I'd suggest using a license for that anyway...
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6295260
Flase then...  I think they needed an example.  And yes a license is better, but that wasn't the question.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6357464
Grade Me  :)
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6357735
It'd be nice... Just grade someone!!!!!
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6357756
What I meant by "Me" was the Question...  Here let me be more specific!

GIVE KDIVAD AN A GRADE!!!  PLEASE!!!

:)
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6357859
LOL! I won't argue with that!

It's Q's like this that landed me in an arguement with the moderators over cleaning up abandoned questions...
0
 

Expert Comment

by:viklele
ID: 6358108
It appears that Carlos has forgotten about this Q :(
0
 

Expert Comment

by:costello
ID: 6400422
Rejecting proposed answer.

FOrce accepting KDivad's comment.


costello
Community Support Moderator @ Experts-Exchange
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Opening Remote & Local Data Connection 2 57
Excel object stays open 19 73
VB error "Type mismatch" 2 53
MS Access Search and Replace Using VBA 6 69
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now