function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
yao yaoyao yao 

How to integrate ActiveX control in visualforce page

I upload an ActiveX control to static resource, and I write a visualforce page to embed this activex control.
But when i visit the page with IE browser, the browser can not prompt me to download the control.
I do not know why.
pconpcon
Can you please provide the visualforce you currently have and what the rendered HTML looks like?  If you can, please keep the code only to the relevant information.

NOTE: When adding code, please use the "Add a code sample" button (icon <>) to increase readability and make it easier to reference.
yao yaoyao yao
<apex:page>
<head>
    <title>CFCA Ultimate CryptoKit Demo</title>
    
    <!--<object id="CryptoAgent" codebase="CryptoKit.Ultimate.x86.cab" classid="clsid:4C588282-7792-4E16-93CB-9744402E4E98"></object>-->
    <script language="javascript" type="text/javascript">

        var CryptoAgent = "";
        // Create ActiveX object according to the platform
        function OnLoad() {
            try {
                var eDiv = document.createElement("div");
                if (navigator.appName.indexOf("Internet") >= 0 || navigator.appVersion.indexOf("Trident") >= 0) {
                    if (window.navigator.cpuClass == "x86") {
                        eDiv.innerHTML = "<object id=\"CryptoAgent\" codebase=\"CryptoKit.Ultimate.x86.cab\" classid=\"clsid:4C588282-7792-4E16-93CB-9744402E4E98\" ></object>";
                    }
                    else {
                        eDiv.innerHTML = "<object id=\"CryptoAgent\" codebase=\"CryptoKit.Ultimate.x64.cab\" classid=\"clsid:B2F2D4D4-D808-43B3-B355-B671C0DE15D4\" ></object>";
                    }
                }
                else {
                    eDiv.innerHTML = "<embed id=\"CryptoAgent\" type=\"application/npCryptoKit.Ultimate.x86\" style=\"height: 0px; width: 0px\">";
                }
                document.body.appendChild(eDiv);
            }
            catch (e) {
                alert(e);
                return;
            }
            CryptoAgent = document.getElementById("CryptoAgent");
        }
...
</head>
<body>
...
</body>
</apex:page>
pconpcon
Part of your problem may be that using apex:page and including the body tag you will have duplicate body tags and it can confuse the DOM.  I would suggest using the apex:page attributes [1] to set the title and anything else you need to do in the head.  Then I would just have your script tag and drop your head and body tags.

Additionally, it does not look like you are using the Resource URL to point to your CryptoKit.Ulitmate.x64.cab file.  I'm assuming this is what you added as a static resource?  If so you'll want ot use the Resource methods [2] to include your file.

Do you have any errors in the browsers console?  (like seeing a 404 for your cab file)  Do you see the object tag in your rendered HTML?

[1] https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_page.htm
[2] https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_resources_reference.htm
yao yaoyao yao
<apex:page standardController="Account" extensions="DataSupportController" docType="html-5.0">
<head>
<script type="text/javascript">
    var CryptoAgent = "";
    
    
        // Select certificate
        function SelectCertificateOnClick() {
            CryptoAgent = document.getElementById("CryptoAgent");
            alert('CryptoAgent ready!!!');
            
            try {                  
                    document.getElementById("SelectCertResult").value = "";

                    var subjectDNFilter = "";
                    var issuerDNFilter = "";
                    var serialNumFilter = "";
                    var bSelectCertResult = "";
                    subjectDNFilter = document.getElementById("SubjectDNFilter").value;
                    issuerDNFilter = document.getElementById("IssuerDNFilter").value;
                    serialNumFilter = document.getElementById("SerialNumFilter").value;

                    bSelectCertResult = CryptoAgent.SelectCertificate(subjectDNFilter, issuerDNFilter, serialNumFilter);                        
                    // Opera浏览器,NPAPI函数执行结果为false时,不能触发异常,需要自己判断返回值。
                    if (!bSelectCertResult) 
                    {
                        var errorDesc = CryptoAgent.GetLastErrorDesc();
                        alert(errorDesc);
                        return;
                    }
                    document.getElementById("SelectCertResult").value = bSelectCertResult;
                 }                  
         
            catch (e) {
                var errorDesc = CryptoAgent.GetLastErrorDesc();
                alert(errorDesc);
            }
        }

</script>
</head>
<apex:form >
    <object id="CryptoAgent" codebase="{!URLFOR($Resource.CryptoKit32,'CryptoKit.Ultimate.x86.cab')}" classid="clsid:4C588282-7792-4E16-93CB-9744402E4E98"></object>
    
    <table id="no1" >
           <tr>
            <td height="30"> 证书主题DN:</td>
        </tr>
        <tr>
            <td><input type="text" id="SubjectDNFilter" style="width: 650px"/></td>
        </tr>
        <tr>
            <td height="30"> 颁发者主题DN:</td>
        </tr>
        <tr>
            <td><input type="text" id="IssuerDNFilter" style="width: 650px"/></td>
        </tr>
        <tr>
        <td height="30">
        证书序列号:
        </td>
        </tr>
        <tr>
        <td>
        <input type="text" id="SerialNumFilter" style="width: 650px"/>
        </td>
        </tr>
        <tr>
        <td height="30">
        <input type="button" name="SelectCertificateButton" value="Select certificate [选择证书]"
        onclick="SelectCertificateOnClick()"/>
        </td> 
        </tr>
        <tr>
        <td height="30">
        选择证书结果(返回值):
        </td>
        </tr>
        <tr>
        <td> 
        <input type="text" id="SelectCertResult" style="width: 650px"/>
        </td>        
        </tr>    
        <tr> 
        <td height="30">
        <h3>
            获取选定证书的信息</h3>
        </td>
        </tr>
        <tr>
        <td height="30">
            信息类型标识:
        </td>
        </tr>
        <tr>
        <td height="30">
            <input type="radio" name="InfoTypeID" value="SubjectDN" checked="checked" />SubjectDN
            <input type="radio" name="InfoTypeID" value="SubjectCN" />SubjectCN
            <input type="radio" name="InfoTypeID" value="IssuerDN" />IssuerDN
            <input type="radio" name="InfoTypeID" value="SerialNumber" />SerialNumber
            <input type="radio" name="InfoTypeID" value="CSPName" />CSPName
            <input type="radio" name="InfoTypeID" value="CertType" />CertType
        </td>
        </tr>        
        <tr>
        <td height="30">
            <input type="button" name="GetCertInfoButton" value="Get Cert Information [获取证书信息]" onclick="GetCertInfoOnClick()"/>
        </td>
        </tr>
        <tr>
        <td height="30">
        证书信息(返回值):
        </td>
        </tr>      
        <tr>
        <td >
        <input type="text" id="CertInfoContent"  style="width: 650px"/>
        </td>
        </tr>  
        </table>

</apex:form>
</apex:page>
in the sample code, i put a activex into visualforce page:

<object id="CryptoAgent" codebase="{!URLFOR($Resource.CryptoKit32,'CryptoKit.Ultimate.x86.cab')}" classid="clsid:4C588282-7792-4E16-93CB-9744402E4E98"></object>

when i click the button:

<input type="button" name="SelectCertificateButton" value="Select certificate [选择证书]" onclick="SelectCertificateOnClick()"/>

the call CryptoAgent.SelectCertificate in the javascript throw exception, when i debugged, i find that the inner object of CryptoAgent is null.

 
pconpcon
Can you please include the rendered HTML generated by the Visualforce page?
yao yaoyao yao
<head>
<meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE" />
<meta HTTP-EQUIV="Expires" content="Mon, 01 Jan 1990 12:00:00 GMT" />

<script type="text/javascript">
 var CryptoAgent = "";
 
 
  // Select certificate
        function SelectCertificateOnClick() {
         CryptoAgent = document.getElementById("CryptoAgent");
         alert('CryptoAgent ready!!!');
         
            try {                  
                    document.getElementById("SelectCertResult").value = "";

                    var subjectDNFilter = "";
                    var issuerDNFilter = "";
                    var serialNumFilter = "";
                    var bSelectCertResult = "";
                    subjectDNFilter = document.getElementById("SubjectDNFilter").value;
                    issuerDNFilter = document.getElementById("IssuerDNFilter").value;
                    serialNumFilter = document.getElementById("SerialNumFilter").value;

                    bSelectCertResult = CryptoAgent.SelectCertificate(subjectDNFilter, issuerDNFilter, serialNumFilter);                        
                    // Opera浏览器,NPAPI函数执行结果为false时,不能触发异常,需要自己判断返回值。
                    if (!bSelectCertResult) 
                    {
                        var errorDesc = CryptoAgent.GetLastErrorDesc();
                        alert(errorDesc);
                        return;
                    }
                    document.getElementById("SelectCertResult").value = bSelectCertResult;
                 }                  
         
            catch (e) {
                var errorDesc = CryptoAgent.GetLastErrorDesc();
                alert(errorDesc);
            }
        }

</script>
</head>
<form id="j_id0:j_id2" name="j_id0:j_id2" method="post" action="https://sso-ad-test-dev-ed--c.ap1.visual.force.com/apex/usbkey?core.apexpages.devmode.url=1" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_id0:j_id2" value="j_id0:j_id2" />

	<object classid="clsid:4C588282-7792-4E16-93CB-9744402E4E98" codebase="/resource/1448502182000/CryptoKit32/CryptoKit.Ultimate.x86.cab" id="CryptoAgent"></object>
	
    <table id="no1">
       	<tr>
        	<td height="30"> &#35777;&#20070;&#20027;&#39064;DN&#65306;</td>
        </tr>
        <tr>
        	<td><input id="SubjectDNFilter" style="width: 650px" type="text" /></td>
        </tr>
        <tr>
        	<td height="30"> &#39041;&#21457;&#32773;&#20027;&#39064;DN&#65306;</td>
        </tr>
        <tr>
        	<td><input id="IssuerDNFilter" style="width: 650px" type="text" /></td>
        </tr>
        <tr>
        <td height="30">
        &#35777;&#20070;&#24207;&#21015;&#21495;&#65306;
        </td>
        </tr>
        <tr>
        <td>
        <input id="SerialNumFilter" style="width: 650px" type="text" />
        </td>
        </tr>
        <tr>
        <td height="30">
        <input name="SelectCertificateButton" onclick="SelectCertificateOnClick()" type="button" value="Select certificate [&#36873;&#25321;&#35777;&#20070;]" />
        </td> 
        </tr>
        <tr>
        <td height="30">
        &#36873;&#25321;&#35777;&#20070;&#32467;&#26524;(&#36820;&#22238;&#20540;)&#65306;
        </td>
        </tr>
        <tr>
        <td> 
        <input id="SelectCertResult" style="width: 650px" type="text" />
        </td>        
        </tr>    
        <tr> 
        <td height="30">
        <h3>
            &#33719;&#21462;&#36873;&#23450;&#35777;&#20070;&#30340;&#20449;&#24687;</h3>
        </td>
        </tr>
        <tr>
        <td height="30">
            &#20449;&#24687;&#31867;&#22411;&#26631;&#35782;&#65306;
        </td>
        </tr>
        <tr>
        <td height="30">
            <input checked="checked" name="InfoTypeID" type="radio" value="SubjectDN" />SubjectDN
            <input name="InfoTypeID" type="radio" value="SubjectCN" />SubjectCN
            <input name="InfoTypeID" type="radio" value="IssuerDN" />IssuerDN
            <input name="InfoTypeID" type="radio" value="SerialNumber" />SerialNumber
            <input name="InfoTypeID" type="radio" value="CSPName" />CSPName
            <input name="InfoTypeID" type="radio" value="CertType" />CertType
        </td>
        </tr>        
        <tr>
        <td height="30">
            <input name="GetCertInfoButton" onclick="GetCertInfoOnClick()" type="button" value="Get Cert Information [&#33719;&#21462;&#35777;&#20070;&#20449;&#24687;]" />
        </td>
        </tr>
        <tr>
        <td height="30">
        &#35777;&#20070;&#20449;&#24687;(&#36820;&#22238;&#20540;)&#65306;
        </td>
        </tr>      
        <tr>
        <td>
        <input id="CertInfoContent" style="width: 650px" type="text" />
        </td>
        </tr>  
        </table><div id="j_id0:j_id2:j_id4"></div>
</form>
pconpcon
Are you able to download the cab file from the URL below?
 
/resource/1448502182000/CryptoKit32/CryptoKit.Ultimate.x86.cab

If you open the javascript console and run the following do you get the expected object back?
 
CryptoAgent = document.getElementById("CryptoAgent");
yao yaoyao yao
First question:
I tried https://sso-ad-test-dev-ed.my.salesforce.com/resource/1448502182000/CryptoKit32/CryptoKit.Ultimate.x86.cab in my dev org, it return "http 404 not found" . but:
<object classid="clsid:4C588282-7792-4E16-93CB-9744402E4E98"codebase="/resource/1448502182000/CryptoKit32/CryptoKit.Ultimate.x86.cab" id="CryptoAgent"></object>
is automatic generate by salesforce and my original code is:
<object id="CryptoAgent" codebase="{!URLFOR($Resource.CryptoKit32,'CryptoKit.Ultimate.x86.cab')}" classid="clsid:4C588282-7792-4E16-93CB-9744402E4E98"></object> 

second question:
as i mentioned on last post, i can get CryptoAgent object normally, but for activex control, the inner object of CryptoAgent is null. This is my question, i do not know why.
when i run the demo(pure html page) provided by the activex control's vendor, ie prompt me to download the activex control and when i debugged,the inner object of CryptoAgent is not null.
pconpcon
Just because the URLFOR was generated does not mean that the resource contains the requested file.  The getElementById will return an object and then anything you reference under it will be null.  The reason your CryptoAgent variable is not null is because it is able to find the object in the page.  Can you provide a tree of the contents of your CryptoKit32 static resource?
yao yaoyao yao
The CryptoKit32 static resource is a .cab file.
User-added image

the .cab file is:
User-added image

you can give me your mailbox, i will send you the cab file.

 
pconpcon
So the problem is that when you try to include the cab file that way it will fail because Salesforce expands the cab file and is trying to get the specificed cab file from inside your cab file.  So you will need to create a .zip file that contains your .cab file.  Then include that .zip file as your static resource and point to the .cab file inside.
yao yaoyao yao
yes, i tried yesterday, i uploaded a zip file contains the .cab file, but ie did not prompt me too.
<object id="CryptoAgent" codebase="{!URLFOR($Resource.CryptoKit32zip,'CryptoKit.Ultimate.x86.cab')}" classid="clsid:4C588282-7792-4E16-93CB-9744402E4E98"></object>
    
pconpcon
And if you goto the link in the rendered HTML do you get a 404 for that resource as well?
yao yaoyao yao
Thank you very much @pcon, It is the security setting which blocked my control.