wscript: Implemented Host_get_Path.

This commit is contained in:
Michał Ziętek 2011-07-20 21:47:29 +02:00 committed by Alexandre Julliard
parent d6fd86e8ec
commit 6afb5f0782
3 changed files with 48 additions and 2 deletions

View file

@ -28,6 +28,7 @@
#include "wscript.h"
#include <wine/debug.h>
#include <wine/unicode.h>
#define BUILDVERSION 16535
@ -127,8 +128,19 @@ static HRESULT WINAPI Host_get_FullName(IHost *iface, BSTR *out_Path)
static HRESULT WINAPI Host_get_Path(IHost *iface, BSTR *out_Path)
{
WINE_FIXME("(%p)\n", out_Path);
return E_NOTIMPL;
WCHAR path[MAX_PATH];
int howMany;
WCHAR *pos;
WINE_TRACE("(%p)\n", out_Path);
if(GetModuleFileNameW(NULL, path, sizeof(path)/sizeof(WCHAR)) == 0)
return E_FAIL;
pos = strrchrW(path, '\\');
howMany = pos - path;
if(!(*out_Path = SysAllocStringLen(path, howMany)))
return E_OUTOFMEMORY;
return S_OK;
}
static HRESULT WINAPI Host_get_Interactive(IHost *iface, VARIANT_BOOL *out_Interactive)

View file

@ -60,6 +60,7 @@ DEFINE_EXPECT(reportSuccess);
#define DISPID_TESTOBJ_TRACE 10001
#define DISPID_TESTOBJ_REPORTSUCCESS 10002
#define DISPID_TESTOBJ_WSCRIPTFULLNAME 10003
#define DISPID_TESTOBJ_WSCRIPTPATH 10004
#define TESTOBJ_CLSID "{178fc166-f585-4e24-9c13-4bb7faf80646}"
@ -75,6 +76,17 @@ static int strcmp_wa(LPCWSTR strw, const char *stra)
return lstrcmpW(strw, buf);
}
static const WCHAR* mystrrchr(const WCHAR *str, WCHAR ch)
{
const WCHAR *pos = NULL, *current = str;
while(*current != 0) {
if(*current == ch)
pos = current;
++current;
}
return pos;
}
static HRESULT WINAPI Dispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
{
if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IDispatch)) {
@ -123,6 +135,8 @@ static HRESULT WINAPI Dispatch_GetIDsOfNames(IDispatch *iface, REFIID riid,
rgDispId[i] = DISPID_TESTOBJ_REPORTSUCCESS;
}else if(!strcmp_wa(rgszNames[i], "wscriptFullName")) {
rgDispId[i] = DISPID_TESTOBJ_WSCRIPTFULLNAME;
}else if(!strcmp_wa(rgszNames[i], "wscriptPath")) {
rgDispId[i] = DISPID_TESTOBJ_WSCRIPTPATH;
}else {
ok(0, "unexpected name %s\n", wine_dbgstr_w(rgszNames[i]));
return DISP_E_UNKNOWNNAME;
@ -181,6 +195,25 @@ static HRESULT WINAPI Dispatch_Invoke(IDispatch *iface, DISPID dispIdMember, REF
return E_OUTOFMEMORY;
break;
}
case DISPID_TESTOBJ_WSCRIPTPATH:
{
WCHAR fullPath[MAX_PATH];
const WCHAR wscriptexe[] = {'w','s','c','r','i','p','t','.','e','x','e',0};
DWORD res;
const WCHAR *pos;
ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
V_VT(pVarResult) = VT_BSTR;
res = SearchPathW(NULL, wscriptexe, NULL, sizeof(fullPath)/sizeof(WCHAR), fullPath, NULL);
if(res == 0)
return E_FAIL;
pos = mystrrchr(fullPath, '\\');
if(!(V_BSTR(pVarResult) = SysAllocStringLen(fullPath, pos-fullPath)))
return E_OUTOFMEMORY;
break;
}
default:
ok(0, "unexpected dispIdMember %d\n", dispIdMember);
return E_NOTIMPL;

View file

@ -29,5 +29,6 @@ ok(WScript.Name === "Windows Script Host", "WScript.Name = " + WScript.Name);
ok(typeof(WScript.Version) === "string", "typeof(WScript.Version) = " + typeof(WScript.Version));
ok(typeof(WScript.BuildVersion) === "number", "typeof(WScript.BuldVersion) = " + typeof(WScript.BuldVersion));
ok(WScript.FullName === winetest.wscriptFullName, "WScript.FullName = ", WScript.FullName);
ok(WScript.Path === winetest.wscriptPath, "WScript.Path = ", WScript.Path);
winetest.reportSuccess();