2011-05-05 82 views
0

我正在創建一個發送郵件的程序。我想使用Javascript驗證電子郵件ID。任何人都可以說如何從MFC調用Javascript函數?如何在MFC中調用Javascript函數?

+1

爲什麼你需要使用Javascript而不是直接在C++中進行驗證?這和VB6有什麼關係? – casablanca 2011-05-05 04:03:30

+1

這是一個非常糟糕的主意。 – 2011-05-05 12:33:15

回答

2

將Javascript包裝到Windows Script Component中,然後通過COM調用它。

<?xml version="1.0"?> 

<package> 
    <component id="Lovesall.Com.EmailValidator"> 

    <comment> 
     Descriptive comment goes here. 
    </comment> 

    <?component error="true" debug="true"?> 

    <registration 
     description="WSC Component for Email Validation" 
     progid="Lovesall.Com.EmailValidator" 
     version="1.00" 
     classid="{a5ddfaa2-53de-40db-83f3-467914b4aeac}" 
     remotable="False"> 

     <!-- boilerplate registration/unregistration logic --> 
     <script language="VBScript"> 
     <![CDATA[ 

strComponent = "MyComponent" 

Function Register 
MsgBox strComponent & " - Script Component registered." 
End Function 

Function Unregister 
MsgBox strComponent & " - Script Component unregistered." 
End Function 

     ]]> 
     </script> 
    </registration> 


    <public> 
     <method name="ValidateEmail"> 
     <parameter name="emailAddress"/> 
     </method> 
    </public> 

    <script language="Javascript"> 
     <![CDATA[ 

     function ValidateEmail(emailAddress) { 
      .... implementation here ... 
     } 

     ]]> 
    </script> 
    </component> 
</package>