Solved

OCX detect develop environment

Posted on 2001-07-12
17
250 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 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

809 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