码迷,mamicode.com
首页 > Web开发 > 详细

js+dll+ocx

时间:2016-01-06 17:54:42      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

test.h

class ATL_NO_VTABLE CZNActiveXATL :
//安全提示解除
public IObjectSafetyImpl< CZNActiveXATL, INTERFACESAFE_FOR_UNTRUSTED_CALLER| INTERFACESAFE_FOR_UNTRUSTED_DATA>, 
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CZNActiveXATL, &CLSID_ZNActiveXATL>,
public IConnectionPointContainerImpl<CZNActiveXATL>,
public CProxy_IZNActiveXATLEvents<CZNActiveXATL>,
public IObjectWithSiteImpl<CZNActiveXATL>,
public IDispatchImpl<IZNActiveXATL, &IID_IZNActiveXATL, &LIBID_ZNActiveXLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:

//对应DLL中的函数
typedef int (*ZNinit)(char *appname,char *PIN);
typedef int (*ZNterminate)();
//初始,并调用DLL中的函数
HINSTANCE hInstlib;
    //函数映射句柄声明
ZNinit ZN_Init;
ZNterminate ZN_Terminate;
CZNActiveXATL()
{
  //加载已写好的DLL文件
  hInstlib = LoadLibrary(L"znapi.dll");
  //是否加载成功
  if (hInstlib == NULL) {
   MessageBox(NULL, L"加载失败!", L"demo", MB_OK);
      FreeLibrary(hInstlib);
  }else{
   MessageBox(NULL, L"加载成功!", L"demo", MB_OK);
   //调用方法,并返回方法句柄
   ZN_Init = (ZNinit)GetProcAddress(hInstlib,"ZN_init");
   ZN_Terminate = (ZNterminate)GetProcAddress(hInstlib,"ZN_terminate");
}
}
DECLARE_REGISTRY_RESOURCEID(IDR_ZNACTIVEXATL)

BEGIN_COM_MAP(CZNActiveXATL)
COM_INTERFACE_ENTRY(IZNActiveXATL)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IConnectionPointContainer)
COM_INTERFACE_ENTRY(IObjectWithSite)
COM_INTERFACE_ENTRY(IObjectSafety)//解除安全提示
END_COM_MAP()
BEGIN_CONNECTION_POINT_MAP(CZNActiveXATL)
CONNECTION_POINT_ENTRY(__uuidof(_IZNActiveXATLEvents))
END_CONNECTION_POINT_MAP()

DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
  return S_OK;
}
void FinalRelease()
{
  //释放资源 
  FreeLibrary(hInstlib);
}
public:
STDMETHOD(ZN_init)(CHAR* appname, CHAR* PIN, LONG* rc);
STDMETHOD(ZN_terminate)(LONG* rc); 
};
OBJECT_ENTRY_AUTO(__uuidof(ZNActiveXATL), CZNActiveXATL)

 

 

//\\\\==============================test.cpp

STDMETHODIMP CZNActiveXATL::ZN_init(CHAR* appname, CHAR* PIN, LONG* rc)
{
// TODO: 在此添加实现代码
int ret = 0;
ret = this->ZN_Init(static_cast<char*>(appname),static_cast<char*>(PIN));
*rc = static_cast<long>(ret);
this->_AtlFinalRelease();
return S_OK;
}
STDMETHODIMP CZNActiveXATL::ZN_terminate(LONG* rc)
{
// TODO: 在此添加实现代码
int ret = 0;
ret = this->ZN_Terminate();
*rc = static_cast<long>(ret);
this->_AtlFinalRelease();
return S_OK;
}

js+dll+ocx

标签:

原文地址:http://www.cnblogs.com/laoying111/p/5106174.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!