On the ActiveX control Project menu, click References, and added VB
IObjectSafety Interface (c:\windows\sys tem32\Objsafe.t lb) -> I did not
create this .tlb file myself, it's already there in c:\windows\syst em32.
In the ActiveX control project, I have a module called basSafectl.bas:
Option Explicit
Public Const IID_IDispatch = "{00020400-0000-0000-C000-000000000046}"
Public Const IID_IPersistSto rage =
"{0000010A-0000-0000-C000-000000000046}"
Public Const IID_IPersistStr eam =
"{00000109-0000-0000-C000-000000000046}"
Public Const IID_IPersistPro pertyBag =
"{37D84F60-42CB-11CE-8135-00AA004BB851}"
Public Const INTERFACESAFE_F OR_UNTRUSTED_CA LLER = &H1
Public Const INTERFACESAFE_F OR_UNTRUSTED_DA TA = &H2
Public Const E_NOINTERFACE = &H80004002
Public Const E_FAIL = &H80004005
Public Const MAX_GUIDLEN = 40
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMem ory" _
(pDest As Any, pSource As Any, ByVal ByteLen As Long)
Public Declare Function StringFromGUID2 Lib "ole32.dll" (rguid As _
Any, ByVal lpstrClsId As Long, ByVal cbMax As Integer) As Long
Public Type udtGUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Public m_fSafeForScrip ting As Boolean
Public m_fSafeForIniti alizing As Boolean
Sub Main()
m_fSafeForScrip ting = True
m_fSafeForIniti alizing = True
End Sub
In the ActiveX control project, in the control:
Option Explicit
Implements IObjectSafety
Private Sub IObjectSafety_G etInterfaceSafe tyOptions(ByVal riid As _
Long, pdwSupportedOpt ions As Long, pdwEnabledOptio ns As Long)
Dim rc As Long
Dim rClsId As udtGUID
Dim IID As String
Dim bIID() As Byte
pdwSupportedOpt ions = INTERFACESAFE_F OR_UNTRUSTED_CA LLER Or _
INTERFACESAFE_F OR_UNTRUSTED_DA TA
If (riid <> 0) Then
CopyMemory rClsId, ByVal riid, Len(rClsId)
bIID = String$(MAX_GUI DLEN, 0)
rc = StringFromGUID2 (rClsId, VarPtr(bIID(0)) , MAX_GUIDLEN)
rc = InStr(1, bIID, vbNullChar) - 1
IID = Left$(UCase(bII D), rc)
Select Case IID
Case IID_IDispatch
pdwEnabledOptio ns = IIf(m_fSafeForS cripting, _
INTERFACESAFE_F OR_UNTRUSTED_CA LLER, 0)
Exit Sub
Case IID_IPersistSto rage, IID_IPersistStr eam, _
IID_IPersistPro pertyBag
pdwEnabledOptio ns = IIf(m_fSafeForI nitializing, _
INTERFACESAFE_F OR_UNTRUSTED_DA TA, 0)
Exit Sub
Case Else
Err.Raise E_NOINTERFACE
Exit Sub
End Select
End If
End Sub
Private Sub IObjectSafety_S etInterfaceSafe tyOptions(ByVal riid As _
Long, ByVal dwOptionsSetMas k As Long, ByVal dwEnabledOption s As Long)
Dim rc As Long
Dim rClsId As udtGUID
Dim IID As String
Dim bIID() As Byte
If (riid <> 0) Then
CopyMemory rClsId, ByVal riid, Len(rClsId)
bIID = String$(MAX_GUI DLEN, 0)
rc = StringFromGUID2 (rClsId, VarPtr(bIID(0)) , MAX_GUIDLEN)
rc = InStr(1, bIID, vbNullChar) - 1
IID = Left$(UCase(bII D), rc)
Select Case IID
Case IID_IDispatch
If ((dwEnabledOpti ons And dwOptionsSetMas k) <> _
INTERFACESAFE_F OR_UNTRUSTED_CA LLER) Then
Err.Raise E_FAIL
Exit Sub
Else
If Not m_fSafeForScrip ting Then
Err.Raise E_FAIL
End If
Exit Sub
End If
Case IID_IPersistSto rage, IID_IPersistStr eam, _
IID_IPersistPro pertyBag
If ((dwEnabledOpti ons And dwOptionsSetMas k) <> _
INTERFACESAFE_F OR_UNTRUSTED_DA TA) Then
Err.Raise E_FAIL
Exit Sub
Else
If Not m_fSafeForIniti alizing Then
Err.Raise E_FAIL
End If
Exit Sub
End If
Case Else
Err.Raise E_NOINTERFACE
Exit Sub
End Select
End If
End Sub
Thank you.
"Igor Tandetnik" <it********@mvp s.org> wrote in message
news:u4******** ******@TK2MSFTN GP09.phx.gbl...
"fniles" <fn****@pfmail. com> wrote in message
news:en******** ******@tk2msftn gp13.phx.gbl I have an ActiveX control in my web page that I tried to access using
intranet.
I have implemented IObjectSafety in the ActiveX control, and when I
created the CAB file using VB Pakage and Deployment Wizard, under
"Safety Settings" I selected "Yes" for "Safe for Scripting" and "Yes"
for "Safe for Initialization" . I also have signed the CAB file.
In IE, the option 'Script ActiveX controls marked Safe for Scripting'
is already set to 'Enable' (I use Security setting "Medium-Low").
I get a warning message 'An ActiveX control might be unsafe to
interact with other parts of the page. Do you want to allow this
interaction?'
Show how you implement IObjectSafety. It looks like you do it incorrectly.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925