2012-08-10 47 views
0

已經試過了好幾天,現在無法弄清楚。我已經爲Intranet應用程序編寫了一個C#類文件來控制本地串行端口。當我使用regasm手動註冊dll時,它很好用,但是,我需要從網頁部署此控件,而無需手動註冊它。我試圖在Visual Studio 2010中創建一個安裝項目,它編譯得很好,但我無法打開網頁中的對象。如何從網頁部署ActiveX dll

這裏是代碼的相關行從我的C#類:

namespace wmsSerialPorts 
{ 
[Guid("55D31498-12A5-4FF0-942D-3B0BA449CA7B")] 
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] 
    [ComVisible(true)] 
     public interface iAxDevices 
    { 
     [DispId(1)] 
     int OpenPort(string sComPort); 
     [DispId(2)] 
     int ClosePort(); 
     [DispId(3)] 
     int SendCmd(string sCmd); 
     [DispId(4)] 
     string GetLastError(); 
     //[DispId(5)] 
     //string ReadLine(); 
     [DispId(6)] 
     string ReadWeight(); 
     [DispId(7)] 
     Microsoft.JScript.ArrayObject GetJsPorts(); 
     [DispId(8)] 
     void prtLabel(string sItemNum, string sQty, string sDesc, string sWoNum, string sBoxID, string sBoxIDBarCode, string sBoxIDorig); 
     [DispId(9)] 
     void prtLabelQC(string sItemNum, string sQty, string sDesc, string sWoNum, string sBoxID, string sBoxIDBarCode, string sBoxIDorig, string sNeedDate, string sRecOverride); 
     [DispId(10)] 
     void prtReset(); 
    } 

[Guid("E59C5B7E-EF1F-4241-A9FD-191EF8FCC167")] 
    [ClassInterface(ClassInterfaceType.None)] 
    [ComVisible(true)] 
    [ProgId("AxDevices")] 
    public class AXDevices : wmsSerialPorts.SerialCom, iAxDevices, wmsSerialPorts.IObjectSafety 

正如我所說,如果我使用regasm wmsSerialPorts.dll,對象的偉大工程從JavaScript調用時是這樣的:

myAx = new ActiveXObject("AXDevices"); 

我安裝項目中包含一個wmsSerialPorts.inf文件:

[version] 

signature="$CHICAGO$" 

AdvancedINF=2.0 

[Setup Hooks] 

install=install 

[install] 

run=msiexec.exe /package """%EXTRACT_DIR%\ActiveXSetup.msi""" /qn 

....和ActiveXBuild.ddf文件:

.Set DiskDirectoryTemplate=cab 

.Set CabinetNameTemplate=ActiveXSetup.cab 

Debug\ActiveXSetup.msi 

wmsSerialPorts.inf 

我wmsSerialPorts.dll文件被正確引用作爲asseembly分離和建築安裝項目創建的ActiveXSetup.cab和ActiveXSetup.msi文件預期。

然後我創建了這個HTML頁面加載對象:

<!DOCTYPE> 
<html> 
<head> 
    <title>Test</title> 
</head> 
<body> 
<!-- <object id="AXDevices" classid="clsid:E59C5B7E-EF1F-4241-A9FD-191EF8FCC167" codebase="https://10.0.2.53/BIDWMS/ActiveXSetup.cab"> 
    </object>--> 
     <object id="AXDevices" classid="clsid:E59C5B7E-EF1F-4241-A9FD-191EF8FCC167" codebase="ActiveXSetup.cab"> 
    </object> 
    <script type="text/javascript"> 
     try { 
      var obj = document.AXDevices; 
      if (obj) { 
       alert(obj.SayHello()); 
      } else { 
       alert("Object is not created!"); 
      } 
     } catch (ex) { 
      alert("Error message is: " + ex.Description); 
     } 
    </script> 
</body> 
</html> 

...但是當我運行的頁面,它會生成「未定義」(從捕捉(EX)塊)的錯誤。有任何想法嗎?在此先感謝....... Bob

+0

哎呀,粘貼錯誤代碼。這裏的頁面: 測試 <對象ID = 「wmsSerialPorts」 的classid = 「clsid中:E59C5B7E-EF1F-4241-A9FD-191EF8FCC167」 的codebase = 「ActiveXSetup.cab」> Bob 2012-08-10 01:21:31

回答

0

您的代碼庫必須是網址,而不僅僅是文件名。如果你的文件是在C:\的Inetpub \ myCabFiles \ ActiveXSetup.cab,和你的網站是在C:\的Inetpub,那麼基本代碼應該像

codebase="www.mywebsite.com\myCabFiles\ActiveXSetup.cab"