maomingchao

VC 中引用js文件

#include "comutil.h"
using namespace MSScriptControl;
#include <MsHTML.h> 
#include <fstream>

CString CHXXCDlg::Encrypt(CString stringData) {
//m_WebBrowser是一个WebBrowser的Activex控件对象。 
HRESULT hr = CoInitialize(NULL);
IScriptControlPtr pScriptControl(__uuidof(ScriptControl));
pScriptControl->Language = "JavaScript";
//pScriptControl->AllowUI = TRUE;
fstream file;
file.open("FunToJS.js");
string strFileContent, strTemp;
char szTemp[20024] = "";

do
{
file.read(szTemp, 20024);
strFileContent.append(szTemp);
memset(szTemp, 0, 20024);
} while (!file.fail());
file.close();
pScriptControl->AddCode(strFileContent.c_str());

string stringFun("FunToJS('");
string stringOp = stringFun+ (LPCSTR)(CStringA)(stringData) + "','" + (LPCSTR)(CStringA)(m_strJSBaseKey) + "');";

_bstr_t bstr;
bstr = (_bstr_t)stringOp.c_str();
VARIANT variant_str = pScriptControl->Eval(bstr);    
string strEncryped = (const char*)_bstr_t(variant_str);

CString cstrEncryped(strEncryped.c_str());

Decrypt(cstrEncryped);
return cstrEncryped;
};

CString CHXXCDlg::Decrypt(CString stringData) {
//m_WebBrowser是一个WebBrowser的Activex控件对象。 
HRESULT hr = CoInitialize(NULL);
IScriptControlPtr pScriptControl(__uuidof(ScriptControl));
pScriptControl->Language = "JavaScript";
//pScriptControl->AllowUI = TRUE;
fstream file;
file.open("FUNBackJS.js");
string strFileContent, strTemp;
char szTemp[20024] = "";

do
{
file.read(szTemp, 20024);
strFileContent.append(szTemp);
memset(szTemp, 0, 20024);
} while (!file.fail());
file.close();
pScriptControl->AddCode(strFileContent.c_str());

string stringFun("FUNBackJS('");
string stringOp = stringFun + (LPCSTR)(CStringA)(stringData)+"','" + (LPCSTR)(CStringA)(m_strJSBaseKey)+"');";

_bstr_t bstr;
bstr = (_bstr_t)stringOp.c_str();
VARIANT variant_str = pScriptControl->Eval(bstr);
string strDecryped = (const char*)_bstr_t(variant_str);

CString cstrDecryped(strDecryped.c_str());

return cstrDecryped;
}

#include <atlbase.h>
#include <atlstr.h>
#import "C:\\Windows\\SysWOW64\\msscript.ocx" // msscript.ocx 

stdafx.h

posted on 2017-10-30 13:07  maomingchao  阅读(464)  评论(0)    收藏  举报

导航