BCX COM Interface
CREATEOBJECT function
Purpose: CREATEOBJECT creates an
instance of specified COM object.
Syntax: COMObj = CREATEOBJECT(ComObjectName$) Parameters:
Return Value:
|
Remarks: If the function fails, BCX_COM_ERROR flag is set to TRUE. To get extended error
information, call BCX_GET_COM_ERROR_CODE or
BCX_GET_COM_ERROR_DESC.
Example 1:
CLS DIM app AS OBJECT app = CREATEOBJECT("Excel.Application") IF BCX_COM_ERROR THEN PRINT BCX_GET_COM_ERROR_DESC$ END END IF app.visible = true Sleep(2000) ' Excel will be visible for 2 sec, and than it will close. app.activeworkbook.saved = true ' don't prompt to save workbook app.quit SET app = NOTHING ' remmember to call Set xxx = Nothing to release resources used by COM object!!! KEYPRESS
Example 2:
DIMLink$ Link$=Startup_Folder$()+"GnotePad.lnk"CreateLink("c:\windows\notepad.exe",Link$,"","MS Notepad")FUNCTIONStartup_Folder$()DIMA$DIMWshellASOBJECTSETWshell=CreateObject("Wscript.Shell")A$=Wshell.SpecialFolders("Startup")SETWshell=NOTHINGFUNCTION=A$+"\"ENDFUNCTIONFUNCTIONCreateLink(Exe$, Link$, Args$, Desc$)ASHRESULTDIMhresASHRESULTDIMpslASIShellLinkPTRDIMw[MAX_PATH]ASWORDCoInitialize(NULL)hres=CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, _ IID_IShellLink,(LPVOID*)&psl)IF(SUCCEEDED(hres))THENDIMppfASIPersistFilePTRpsl->lpVtbl->SetPath(psl, Exe)psl->lpVtbl->SetDescription(psl, Desc)psl->lpVtbl->SetShowCmd(psl, SW_SHOWMAXIMIZED)psl->lpVtbl->SetArguments(psl, Args$)hres=psl->lpVtbl->QueryInterface(psl, IID_IPersistFile,(LPVOID*)&ppf)IF(SUCCEEDED(hres))THENMultiByteToWideChar(CP_ACP,0, Link,-1,(LPWSTR)w, MAX_PATH)hres=ppf->lpVtbl->Save(ppf,(LPCOLESTR)w, TRUE)ppf->lpVtbl->Release(ppf)ENDIFpsl->lpVtbl->Release(psl)ENDIFCoUninitialize()FUNCTION=hresENDFUNCTION
For other examples of the CREATEOBJECT
function see the COM folder in the Files section of the BCX Group
on Yahoo.
Related topics: Object data type definition | SET ... NOTHING | List of all COM Interface Functions