Solved

OCX detect develop environment

Posted on 2001-07-12
17
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
  • +3
17 Comments
 
LVL 143

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 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