不通过注册表使用ActiveX对象
2015-10-25 16:23
239 查看
为了弄清楚COM库的运行原理,特意做了这个实验:
#include "stdafx.h" #include "objbase.h" #include "atlcomcli.h" #include "limits" //#include "commctrl.h" #import "msscript.ocx" no_namespace extern "C"{ typedef HRESULT (__stdcall *FuncDllGetClassObject)(REFCLSID rclsid,REFIID riid,LPVOID * ppv);} struct IScriptControl; int _tmain(int argc, _TCHAR* argv[]) { try { ::CoInitialize (NULL); HMODULE h=::LoadLibrary("msscript.ocx"); if(h==NULL)return 0; FuncDllGetClassObject func=(FuncDllGetClassObject)::GetProcAddress(h,"DllGetClassObject"); if(func==NULL)return 0; IClassFactory *pFactory=NULL; func(__uuidof ( ScriptControl ),IID_IClassFactory,(void**)&pFactory); if(pFactory==NULL)return 0; IScriptControl *pScript=NULL; //pFactory->QueryInterface(__uuidof(IScriptControl) , (void**)&pScript); //0e59f1d3-1fbe-11d0-8ff2-00a0d10038bc //IID id;//=__uuidof(IScriptControl); IID id; id.Data1=0x0e59f1d3; id.Data2=0X1fbe; id.Data3=0X11d0; id.Data4[0]=0X8f; id.Data4[1]=0Xf2; id.Data4[2]=0X00; id.Data4[3]=0Xa0; id.Data4[4]=0Xd1; id.Data4[5]=0X00; id.Data4[6]=0X38; id.Data4[7]=0Xbc; //pFactory->CreateInstance(NULL,__uuidof(IScriptControl) , (void**)&pScript); pFactory->CreateInstance(NULL,id , (void**)&pScript); pFactory->Release(); pScript->put_AllowUI(VARIANT_FALSE); pScript->PutLanguage(L"JScript"); _variant_t v=pScript->Eval("1+2+3+4+5"); int i=pScript->Release(); ::FreeLibrary(h); ::CoUninitialize(); return 0; } catch(...) { //::FreeLibrary(h); ::CoUninitialize(); } }
相关文章推荐
- BNU 13064 Dice (I) 前缀和优化DP
- 存储器层次结构
- Android 抽屉菜单的实现
- Redis持久化之大数据服务暂停问题
- 多线程(守护线程、join方法、线程优先级、线程组)
- page、request、session和application的区别
- iOS开发中 常用枚举和常用的一些运算符(易错总结)
- 使用Charles进行网络请求抓包解析
- The Differences Between Data, Information and Knowledge
- each()的用法
- iOS开发中 常用枚举和常用的一些运算符(易错总结)
- IT笔试面试智力题
- Android TextView文字滚动
- PopupWindow学习笔记
- unity 已知cosA和sinA,求A
- strstr函数与KMP算法比较
- 使用CSDN Markdown写博客
- C/C++各种数据类型转换汇总
- 第八周-项目2 - 建立链串的算法库
- C/C++各种数据类型转换汇总