Go Premium for a chance to win a PS4. Enter to Win


OCX in web page

Posted on 2001-07-13
Medium Priority
Last Modified: 2008-03-04
when i creat my own ocx by Vb and compilet it
than i use it in wab page and when i try to brows my
page appear to me (there is activex with be running are you sure you want to contino).
how i can make my own ocx or activex safty.
Question by:issamtaher

Expert Comment

ID: 6281964
hello issamtaher,
    First you need to create a .cab file by including your Ocx file by using Package and Deployment Wizard or by using Wise Set up, then write your code to display that ActiveX control in Html page or ASP page by using Object tag. So what will this do is when ever you are about to view your ASP page or HTML page which has your ocx Control first your browser will see whether you have that particular ocx in the client system if not it will download that ocx file from the WebServer and it will register in the system then that ocx control will be shown to the user over the browser.
    I have tried this for the Scroll bar control. Here i am sending you the code it may help you
<OBJECT CLASSID="clsid:79176FB0-B7F2-11CE-97EF-00AA006D2776" ID="spnTest" CODEBASE="../controls/ActivxCtr.cab" VIEWASTEXT>


Expert Comment

ID: 6282149
There are several ways to fix this problem.  All of them have their short commings:

1) You can change the browser security settings to allow the .ocx to load without issueing a warning.

2) You can register the control as Web Safe (but should be done if it is truely websafe!) See MSDN for details.

3) You can build a distribution .cab file marking it websafe as previously mentioned.

4) You can use code in the .ocx to mark it safe for scripting and initialization.

5) You can licience your control and reference the licience directly in your HTML.

My suggestion - search MSDN and pick from the various options that best meet your needs.

I ran into this very problem a couple months ago and ended up writing my control in C++ using ATL.  Admittedly, it was a pretty radical solution but I chose it because it was so well documented by Microsoft.

Good luck.

Accepted Solution

Dave_Greene earned 400 total points
ID: 6296228
Ok, here is the step by step example.

1) Create an OCX Project (ActiveX Control)
2) right click your control, select add UserControl, then when you get into the VB dialog where you

normally select a usercontrol, select the wizard.
3) Add the Property you want to expose eg (Message) "My Custom Members" in the wizard
4) doesn't map to a control
5) When you get to the set attributes page, set Message to a string.

Your New Control Should Look Like this


'Default Property Values:
Const m_def_Message = "Empty Message"
'Property Variables:
Dim m_Message As String
'Event Declarations:

'MemberInfo=13,0,0,Empty Message
Public Property Get Message() As String
Message = m_Message
End Property

Public Property Let Message(ByVal New_Message As String)
m_Message = New_Message
PropertyChanged "Message"
MsgBox "Here is the Message you passed [" & m_Message & "]"
End Property

'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
m_Message = m_def_Message
End Sub

'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
m_Message = PropBag.ReadProperty("Message", m_def_Message)
End Sub

'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("Message", m_Message, m_def_Message)
End Sub


6) Build your OCX
7) set binary compatibility on the control in the projects properties.
8) Add a standard EXE to your project group
9) Place the Control onto form1.
10) Check to see if the value you set in the controls property page (on form1) actually change the value,

if so proceed.

If not, it's time to write a comment on EE stating so. (listing the control code)
11) it worked!  yahoo!  Now build your OCX again just to be certain you have any changes
12) Use the Package and Deployment wizard to build the deployment
- Using the "Internet Package" option
- Take the defaults until you get to the "Safety Settings" tab, you will select "NO" for Safe for

Scripting, and

"YES" for safe for initialization.
- Now you are finished... with this step
13) now look into the directory where you built the package. you should see projectName.htm, open it

It should look something like this


<!--     If any of the controls on this page require licensing, you must
 create a license package file. Run LPK_TOOL.EXE to create the
 required LPK file. LPK_TOOL.EXE can be found on the ActiveX SDK,
 http://www.microsoft.com/intdev/sdk/sdk.htm. If you have the Visual
 Basic 6.0 CD, it can also be found in the \Tools\LPK_TOOL directory.

 The following is an example of the Object tag:

<OBJECT CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331">

<OBJECT ID="UserControl1"


14) Make the following changes (per this example)
   <OBJECT ID="UserControl1" Height="400" Width="400"  <--however big the control is
    param name="Message" value="Your New Message here!"
15) Save your changes and run the projectname.htm
16) If it works great, if not... time to comment again  :)
LVL 49

Expert Comment

ID: 7153421
Hi issamtaher,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept Dave_Greene's comment(s) as an answer.

issamtaher, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer

Expert Comment

ID: 7182143
Comment from expert accepted as answer

E-E Moderator

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Suggested Courses

885 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