|
|
От: |
Odi$$ey
|
http://malgarr.blogspot.com/ |
| Дата: | 22.05.04 18:36 | ||
| Оценка: | 9 (1) | ||
| #Имя: | FAQ.com.wsc.earlybind | ||
#import "C:\Scripts\scriptlet.tlb" no_namespace, named_guids AutomationPtr pMyScriptPtr = NULL;
HRESULT hr;
hr = pScriptPtr.CreateInstance( "MyScript.WSC" ); // ProgID как он есть в скрипте и в OleView You *can't* early bind to a WSC instance. The problem is that the IID of a WSC instance is dynamic and is determined at runtime by the scrobj.dll wrapper. The IID embedded in the typelib for a WSC that VB (or any other early bound language) looks for with QueryInterface will never match the dynamic IID of the instance at runtime.
The WSC documentation that implies that WSC early binding is supported is simply wrong.
IDispatchPtr pDispatch;
HRESULT hr = pDispatch.CreateInstance( "MyScript.WSC" );
if ( SUCCEEDED( hr ) )
{
CComDispatchDriver pDd( pDispatch );
_variant_t result;
_variant_t param("123456");
hr = pDd.Invoke1(OLESTR("MethodName"), ¶m, &result);
...