OCX Package CAB with JS call specific tutorial

Source: Internet
Author: User
Tags try catch

Recently working on a WEB project. You need to call OCX to connect the card Reader. Didn't want to use OCX technology. Because the ActiveX technology is produced by microsoft. This causes the entire system to use only IE browser (other browsers can support OCX calls via plugins). But trying a very many method calls client DLL discovery is not going to make Sense.    Finally helpless under, only then intends to study the OCX technology. The internet says that ActiveX technology is very troublesome and there are various Errors. Do not know when not to do, really need to study time, only to find that this is True.

The main problem is that the error and the real cause of the problem is not related or not very related. Even very often there is no error. Just keep trying.

Let's talk about how to fix the OCX.

First Declare. This tutorial is just about OCX packaging CAB and JS calling Ocx. This does not discuss how to write OCX through C + +. Because I just do Java development. There is no research for C + +.

Development system: win8.1 64-bit test via system: win7 64-bit, win8.1 64-bit, xp 32-bit

The relationship between OCX and CAB. you know. After getting the OCX, suppose you want to call, first of all to Register.

In the case of no Registration.    There is no way to invoke OCX. The simplest way to register is to manually register the Booklet. Manual registration needs to be done at the command line. For Developers. You have to deal with the command line more or less. There may be no problem. It's just not appropriate for a customer who uses our system to make command-line operations. No matter how specific our documents are Written. This is unfriendly to customers, and manual registration is designed to be a safety Issue.

So it is necessary to the customer without the knowledge of their own initiative to the OCX Manual.

This is the function of the CAB.

    manual booklet OCX     if We. The folder where OCX is located is: d:/ocx/xpbutton/xpbutton.ocx
          through regsvr32 xpbutton.ocx, so we manually register the Ocx.       false assumption Uninstall OCX. We are able to counter-register: regsvr32/u xpbutton.ocx.         Register and uninstall, we all need to execute the CMD console as an Administrator. --special attention is needed here!       Assume that the following error occurred at the time of the registration:  
         1. first, See if you are executing CMD as an Administrator.      2. If not, consider putting the corresponding OCX into the system folder               a). 32-bit system to  C:\Windows\System32          b). 64-bit system put to  C:\Windows\SysWOW64     3. let's say it's an Error. That can be determined to be the result of a missing DLL.

You can download a tool:Dependency Walker. look at the tutorials here. See which DLLs are Missing. To download these DLLs on the internet, these DLLs are what you will need to package with OCX into the CAB compressed package.

Since your own computer is less, it may be that the client computer is the Same. it is important to note that the first choice is the same number of DLLs as your system, and certainly not wrong. I can't find 64-bit, just consider the 32-bit version number. Once you have downloaded the dll, store the DLL below the system directory mentioned in the second step Above. Then register Again.

OCX Package CAB First download the OCX packaging signature tool:OCX Packaging Signature tool , visit password ddb4.

Put the OCX and commands that need to be signed and packaged in the same directory.

to create a signing Certificate: execute the following command at the command line: 1. To run the Command:

Makecert.exe-ss xpbutton-n "cn= here casually"-sv. \xpbutton.pvk-r. \xpbutton.cer

Enter three times, Password. Viewing the console appears succeeded indicates success.

The makefile is Now: Xpbutton.cert and xpbutton.pvk

2. Execute the Command:

Cert2Spc.exe. \xpbutton.cer. \XPBUTTON.SPC

Viewing the console, a succeeded appears to indicate SUCCESS.

the file is generated at this time: xpbutton.spc

Two orders ended, we got three files: xpbutton.cer, xpbutton.pvk, xpbutton.spc

to sign the OCXbefore you package the CAB. The first step is to perform a signature operation on the OCX itself, which is very important. If you don't do it, you may make a mistake. 3. Execution Command: SignTool Signwizard

If you want to fill in a timestamp, you can fill in the following address: Http://timestamp.verisign.com/scripts/timstamp.dll

Wait a Moment. The following prompt indicates that the OCX signature is Complete.

the console appears: successfully completed signing wizard:<> indicates success.

writing an INF fileINF file is also a priority, assuming that writing errors are not properly packaged. ( you can download the INF file I wrote, based on this change.) Ensure the correctness of the INF file )INF file: OCX inf file,Interview Password 49de. If the package CAB is not a problem, ocx, DLL will be downloaded to the c:/windows/ocx/folder, easy to uninstall ocx, Delete DLL Files.

Signature= "$CHICAGO $"



1 =%diskname%, "xpbutton.cab", 1



files=30, Windows\ocx





Diskname= "windows\ocx"
The above is my INF File.           Explain several parts. 1. There are 3 DLLs added to This. Let's say you don't need to package your DLL into a cab, you can take a look at the blue section Above. Suppose there is no mcfo42d.dll, then all the blue parts are removed and the rest is Fixed.

And so on

for a simple explanation:File=thiscab copy copy, do not explain.

Because it is a 64-bit system, I test this to write no Problem.

              32-bit Systems can also write this:  file-win32-x86=thiscab 
              CLSID Here. The easiest way is to find the source of the ocx, ask the author of the ocx, they know what should be filled out here.               Suppose you can't find a producer. There is a way. Refer to the manual OCX in the previous article and view the search register: Xpbutton
           Find the structure of a similar register on the left, and then &NBSP;134EE1CC-4B8A-4E74-8C41-F4990065E2E1 will be the CLSID we Need.            note: I am in  c:\windows Xpbutton.ocx file for \ocx\  folder betting Booklet. So the upper right of the address will be   C:\Windows\ocx\xpbutton.ocx              FileVersion is the same, the best way to find the source of OCX (developer). Determine the version number, when you write ocx, the code will have the corresponding version number Ocx. When I first communicated with C. Read the OCX C + + Code. There is the corresponding version number Information. The version number information here must match the OCX version number Information.

Registerserver=yes said that after downloading, he volunteered to register this ocx. Everyone can see me the following DLL file in the code does not have this sentence, meaning that DLL download is not required after the registration, assuming that you have to register the dll, the corresponding DLL region also need to join this Statement.

3. The green part of the INF file is interpreted in the green section, which represents the version of the DLL and how to determine the DLL Version. actually very easy.

Locate the appropriate DLL and right-click to view the Properties. Here's the file version number, which is the version number we need, please Note. is not a product version number .
OCX Package CAB file 4. Execute the command:

Cabarc. Exe-s 6144 n xpbutton.cab xpbutton.ocx xpbutton.inf
It is necessary to explain this command: to package the Xpbutton.ocx Xpbutton.inf file into a xpbutton.cab file, assuming we need to package the additional DLLs into the CAB. So write: cabarc.exe-s 6144 n xpbutton.cab xpbutton.ocx msvcrtd.dll xpbutton.inf and so On.

signing the CAB file

The process of signing a CAB file allows you to see the process of signing the OCX file above, except for the first step where the CAB file is Selected. The rest of the steps are exactly the Same.

So far, we've packaged the OCX into a CAB. But it's not going to work NOW.

A lot of tutorials end Here. In fact, the complexity of OCX is far from Over.

JS calls OCX (CAB) to introduce the OCX control to create a new HTML file, we introduce the OCX through, for example:
An explanation: id= "xpbutton" indicates that the ID of this object is Xpbutton. Names can be anything.         Maybe it will be used. Classid= "clsid:134ee1cc-4b8a-4e74-8c41-f4990065e2e1" See this, should be very familiar with. Classid= "clsid: This Part copy, do not modify.

Just modify the Colon: the back part is Ready. (i accidentally put the clsid: this part of the missing, written as a classid= "134ee1cc-4b8a-4e74-8c41-f4990065e2e1", the result CAB file download not down). Note: Don't miss the Clsid.

codebase= "./xpbutton.cab#version=1,0,0,1" This part of the code is to tell the browser, assuming that the CLSID is not found for 134ee1cc-4b8a-4e74-8c41-f4990065e2e 1 register, that is, the system is not registered in this Xpbutton.ocx. Then find the appropriate Xpbutton.cab File. Here "./xpbutton.cab" means the Xpbutton.cab file that is stored in the same folder as the current Html. "./" indicates the current path, which is the path where the HTML resides.

The following "#version =1,0,0,1" represents the current OCX Version. This is the OCX version (fileversion) that is written in the INF file in the CAB compression package. Note version: 1,0,0,1 is separated by a comma ",". Not the dot ".", assuming you used the dot ".". well, congratulations, you're Wrong again. Additional note: We have encountered three versions of 1. OCX when Writing.                              The OCX version is specified in the C + + Code. 2. When OCX packages a CAB file, The INF file specifies the current OCX Version.

3. When the HTML calls ocx, CODEBASE indicates the OCX version that needs to be called. These three versions need to be Consistent. interestingly, Suppose you want to upgrade ocx, in fact very easy, let the OCX writers upgrade ocx, and then we upgrade the version of the INF file, and then the corresponding HTML version also upgraded. When the browser calls this HTML, it is assumed that the version in CODEBASE has been upgraded. Will download the CAB file on its own initiative and once Again.

Before. In order to test whether the OCX upgrade after the problem itself, manual registration of this OCX, not once again packaged CAB, the results of each visit found that the register is the CAB in the previous version of the Ocx. Note that the browser will download the cab again and once again, only to find that the OCX version number and the CAB version number are Inconsistent. Here's One more thing to Note. After the OCX is written Out.

The CLSID is Fixed. This OCX no matter which computer you register to, check the Brochure. The CLSID is the same and will not change. This is why we can write the CLSID directly in HTML. Since the customer downloads the CAB, after their own initiative, the OCX CLSID is the CLSID that we wrote in C + +.

         js Call OCX Method
          Explain the above code           1.   Xpbutton . AboutBox ();                    Xpbutton In fact it's not out of nowhere, Xpbutton is <o The ID of the bject> tag. You see above can see, <object id= "xpbutton" >......</object>.           2. Xpbutton. AboutBox ()   ;                    AboutBox () is actually a way of OCX. The false idea to know this OCX what methods, the preferred is to find the OCX Developers. In the case of not found, through the tstcon32 software, you can download here:   tstcon32 ActiveX container    interview Password 904d. If you can not use, according to the error prompt to download the corresponding DLL.

(study the Sequela left by OCX.) Always think that some software will be missing DLL) 3. Why try catch OCX is cumbersome and confusing, it is very important that even if the call fails it will not cause an Error.

So. We must manually eject the error message here in the try Catch. But the problem is actually not that simple, even if there is an error message, the hint also let a person can not touch the Mind.

Note that you must remember try catch, or no error will be Prompted. The following summarizes I encountered the error message and the true cause of the corresponding relationship, in order to prevent you all kinds of baidu, Google finally found the wrong way to Solve. OCX error, under normal circumstances, are the local test pass, deployed to the server or use other People's computer, found that the call Failed.
1. [object error], error: member not found

Suppose you encounter the error above: [object error], error: member 1 not found. first determine C:\Windows\ocx folder to download the OCX file (assuming that you have downloaded the INF file in this tutorial, thenC:\Windows\ocx folder below), Assuming that there are no files or folders under the folder, compare the Above.                    To see if the INF file is writing a problem, or if the HTML introduces an OCX object with an error, causing the download to Fail. 2. Assuming that the OCX file has been downloaded, it means that the CAB file is not a Problem. however, OCX is not a register or a registration Failure. The reason for the failure of the register is that we first need to verify that the DLL is Missing. How to Confirm. Can use the above mentionedDependency WalkerSoftware. Assuming that the DLL is really missing, we should pack the CAB again. Package The missing DLL files together in the CAB. Most of the time, we use the CAB to actively register the OCX, in most cases will not report no matter what the Wrong. Even because the missing DLL is not registered Successfully. And no matter what the Hint. I test on very many computers the result is that there is only one Win7, there is a lack of DLL error shows, all other computers do not have any Errors.in particular, It is important to note that after you have packaged the CAB file, test it with more than one computer, preferably testing a different system. Also try to be able to select the Company's non-developer's computer.

Do not test on your own computer, or some of the OCX developers on the computer test passed after it felt that there is no problem.

2. The object does not support this property or method for this error. In the process of development, is bound to Encounter. Just started, always thought it was a problem with the calling Method. After trying all the other different calling methods that can be found on the Internet. Not So. Assuming that the correctness of the OCX can be guaranteed, the root cause of this problem is because the browser does not trust Ocx. Intercepted the method call inside the OCX .

The fundamental way to solve this problem is to change the browser settings.


                             3. Change browser security settings                   and nbsp;  can find a lot of browser changes on the web, in fact, most of them do not need to be changed, but instead reduce security, add Risk.

                      &NBSP;&NBSP ; Uncheck "require Server verification (https) for all sites in this area", fill in the server address, for example: then join, after the addition, check Again " Server Authentication (https) is required for all sites in this Zone. This step is done to ensure that the browser trusts this Site.

                         Here to change the security level of the trust site, the figure on the two, from the original prohibition, changed to prompt or Enable.

in fact, before the first visit to the CAB Web page, we should first change the browser security policy, after the changes have been made to visit, there is generally no problem.

At this point, the relevant knowledge of OCX has been all introduced, This tutorial should be able to help you take a few detours. This is the result of the recent two weeks of Research.

2015.08.26 Supplement 1. Note: If Java development is used, Spring is used in the Background. You should add the following code to the Web. xml.

  <servlet-mapping>    <servlet-name>default</servlet-name>    <url-pattern>*.cab</ Url-pattern>  

The above code tells Spring not to intercept *.cab static Files.

2.JSP Introducing a CAB file
<div style= "display:none;" > <object id= "readcardocx" width=400 height=100                classid= "clsid:f6f2b22e-fc89-489f-967b-9676eb269f55"                 codebase= "${pagecontext.request.contextpath}/cab/readcard.cab#version=1,0,0,1"                ></object> </div>

To introduce a CAB file in project, we need to write
Codebase= "${pagecontext.request.contextpath}/cab/readcard.cab#version=1,0,0,1"
${pagecontext.request.contextpath} indicates project name
CAB files are stored below Webapp/cab

OCX Package CAB with JS call specific tutorial

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.