Solved

OCX detect develop environment

Posted on 2001-07-12
17
244 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 69

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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

919 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

13 Experts available now in Live!

Get 1:1 Help Now