• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

OCX detect develop environment

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
Carlos_Rodrigues
Asked:
Carlos_Rodrigues
  • 6
  • 5
  • 3
  • +3
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Check  out this:
App.StartMode

Not sure as value, but should be ok most of the time...
Cheers
0
 
Éric MoreauSenior .Net ConsultantCommented:
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
 
vikleleCommented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
KDivadCommented:
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
 
Dave_GreeneCommented:
I'm with KDivad on this one!
0
 
KDivadCommented:
Thanks! <grin>
0
 
vikleleCommented:
KDidav, thanks.

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

0
 
KDivadCommented:
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
 
Dave_GreeneCommented:
Give the points to KDivad

If Ambient.UserMode = true then err.raise 999, "Cannot use my control without purchasing it!"
0
 
KDivadCommented:
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
 
Dave_GreeneCommented:
Flase then...  I think they needed an example.  And yes a license is better, but that wasn't the question.
0
 
Dave_GreeneCommented:
Grade Me  :)
0
 
KDivadCommented:
It'd be nice... Just grade someone!!!!!
0
 
Dave_GreeneCommented:
What I meant by "Me" was the Question...  Here let me be more specific!

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

:)
0
 
KDivadCommented:
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
 
vikleleCommented:
It appears that Carlos has forgotten about this Q :(
0
 
costelloCommented:
Rejecting proposed answer.

FOrce accepting KDivad's comment.


costello
Community Support Moderator @ Experts-Exchange
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 5
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now