none
[求助]免注册com组件,怎么在脚本语言上实现.例如 vbs RRS feed

  • 问题

  • int Reg_Com2(LPCSTR lpDll,LPCSTR strrclsid,LPCSTR strriid,LPVOID * ppv)
    {
    	HINSTANCE hinstLib; 
    	MYPROC ProcAdd;  
    	BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; 
    	int rtn=0;
    	// Get a handle to the DLL module.
    	hinstLib = LoadLibraryA(lpDll); 
    	// If the handle is valid, try to get the function address.
    	if (hinstLib != NULL) 	
    	{   
    		ProcAdd =(MYPROC)GetProcAddress(hinstLib, "DllGetClassObject"); 
    		// If the function address is valid, call the function.
    		if (fRunTimeLinkSuccess = (ProcAdd != NULL))
    		{  
    			CLSID rclsid;
    			IID riid;
    			if(strrclsid==NULL)
    			{
    				FreeLibrary(hinstLib);
    				return (int)GetLastError;
    			}
    			CLSIDFromString((LPOLESTR)strrclsid,&rclsid);
    			if(strriid!=NULL)
    				CLSIDFromString((LPOLESTR)strriid,&riid);
    			else
    				riid=IID_IUnknown;
    			IClassFactory *pIf=NULL;
    			if(ProcAdd(rclsid,IID_IClassFactory,(void **)&pIf)==S_OK && pIf!=NULL)
    			{
    				if(pIf->CreateInstance(NULL,riid,ppv)==S_OK)
    					rtn=(int)hinstLib;    
    				pIf->Release();
    				pIf=NULL;
    			}
    		}
    		// Free the DLL module.
    		if(!rtn)
    		{
    			fFreeResult = FreeLibrary(hinstLib);
    			rtn=(int)GetLastError;
    		}
    	} 
    	return rtn;
    }
    

    这是完整的代码,参数1是com 完整路径 ,参数2 是 CLSID 参数3 是返回的 对象指针

    以下是测试代码,测试发现  tobj  , an 都必须指定类型.如果是变体型就创建不了对象.像vbs定义变量都无法指定类型的,想知道有没有办法解决,不然这个免注册调用,用途就不大了

    Dim ClsId_Obj As UUID, hlib As Long
    Dim tobj As IUnknown
    Dim ClsStr_Obj As String
    Dim an As Object
       ClsStr_Obj = "{20A7E5B1-6EB1-46CC-9EAC-6A407357481D}"
        dllpath = "D:\按键精灵9\按键精灵9\plugin\Aniu.dll"
        hlib = CrComObj2(dllpath, StrPtr(ClsStr_Obj), 0, tobj)
        Set an = tobj

    2015年8月4日 13:40

全部回复

  • 这个好像是VBS的问题?

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2015年8月27日 7:13