oleview: Added CreateInstanceOn functionality.

This commit is contained in:
Piotr Caban 2006-06-22 19:58:37 +02:00 committed by Alexandre Julliard
parent 566beb788b
commit b2d91368e5
5 changed files with 69 additions and 5 deletions

View File

@ -117,3 +117,14 @@ STRINGTABLE
IDS_CGCOFAIL, "CoGetClassObject failed."
IDS_ERROR_UNKN, "Unknown error"
}
DLG_CREATEINSTON DIALOG DISCARDABLE 0, 0, 250, 41
STYLE DS_MODALFRAME | DS_NOIDLEMSG | WS_CAPTION | WS_SYSMENU
CAPTION "Connect to another machine"
FONT 8, "MS Shell Dlg"
{
LTEXT "&Machine name:", IDIGNORE, 5, 6, 190, 8
EDITTEXT IDC_MACHINE, 5, 16, 190, 12, WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL
DEFPUSHBUTTON "&OK", IDOK, 200, 5, 45, 14
PUSHBUTTON "&Cancel", IDCANCEL, 200, 22, 45, 14
}

View File

@ -51,6 +51,7 @@ typedef struct
HINSTANCE hMainInst;
BOOL bExpert;
DWORD dwClsCtx;
WCHAR wszMachineName[MAX_LOAD_STRING];
}GLOBALS;
typedef struct
@ -115,5 +116,5 @@ void AddTreeEx(void);
void AddTree(void);
HWND CreateTreeWindow(HINSTANCE hInst);
BOOL CreateRegPath(HTREEITEM item, WCHAR *buffer, int bufSize);
void CreateInst(HTREEITEM item);
void CreateInst(HTREEITEM item, WCHAR *wszMachineName);
void ReleaseInst(HTREEITEM item);

View File

@ -23,6 +23,32 @@
GLOBALS globals;
static WCHAR wszRegEdit[] = { 'r','e','g','e','d','i','t','.','e','x','e','\0' };
INT_PTR CALLBACK CreateInstOnProc(HWND hDlgWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND hEdit;
switch(uMsg)
{
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDOK:
memset(globals.wszMachineName, 0, sizeof(WCHAR[MAX_LOAD_STRING]));
hEdit = GetDlgItem(hDlgWnd, IDC_MACHINE);
if (GetWindowTextLength(hEdit)>0)
GetWindowText(hEdit, globals.wszMachineName, MAX_LOAD_STRING);
EndDialog(hDlgWnd, IDOK);
return TRUE;
case IDCANCEL:
EndDialog(hDlgWnd, IDCANCEL);
return TRUE;
}
}
return FALSE;
}
void ResizeChild(void)
{
RECT client, stat, tool;
@ -125,7 +151,14 @@ int MenuCommand(WPARAM wParam, HWND hWnd)
break;
case IDM_CREATEINST:
hSelect = TreeView_GetSelection(globals.hTree);
CreateInst(hSelect);
CreateInst(hSelect, NULL);
SendMessage(globals.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)hSelect);
break;
case IDM_CREATEINSTON:
if(DialogBox(0, MAKEINTRESOURCE(DLG_CREATEINSTON),
hWnd, CreateInstOnProc) == IDCANCEL) break;
hSelect = TreeView_GetSelection(globals.hTree);
CreateInst(hSelect, globals.wszMachineName);
SendMessage(globals.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)hSelect);
break;
case IDM_RELEASEINST:

View File

@ -67,3 +67,6 @@
#define IDS_CGCOFAIL 300
#define IDS_ERROR_UNKN 301
#define DLG_CREATEINSTON 1000
#define IDC_MACHINE 1001

View File

@ -50,7 +50,7 @@ LPARAM CreateITEM_INFO(INT flag, const WCHAR *info, const WCHAR *clsid)
return (LPARAM)reg;
}
void CreateInst(HTREEITEM item)
void CreateInst(HTREEITEM item, WCHAR *wszMachineName)
{
TVITEM tvi;
HTREEITEM hCur;
@ -62,6 +62,8 @@ void CreateInst(HTREEITEM item)
WCHAR wszRegPath[MAX_LOAD_STRING];
const WCHAR wszFormat[] = { '\n','%','s',' ','(','$','%','x',')','\n','\0' };
CLSID clsid;
COSERVERINFO remoteInfo;
MULTI_QI qi;
IUnknown *obj, *unk;
HRESULT hRes;
@ -86,7 +88,21 @@ void CreateInst(HTREEITEM item)
if(FAILED(CLSIDFromString(((ITEM_INFO *)tvi.lParam)->clsid, &clsid))) return;
hRes = CoCreateInstance(&clsid, NULL, globals.dwClsCtx,
if(wszMachineName)
{
remoteInfo.dwReserved1 = 0;
remoteInfo.dwReserved2 = 0;
remoteInfo.pAuthInfo = NULL;
remoteInfo.pwszName = wszMachineName;
qi.pIID = &IID_IUnknown;
CoCreateInstanceEx(&clsid, NULL, globals.dwClsCtx|CLSCTX_REMOTE_SERVER,
&remoteInfo, 1, &qi);
hRes = qi.hr;
obj = qi.pItf;
}
else hRes = CoCreateInstance(&clsid, NULL, globals.dwClsCtx,
&IID_IUnknown, (void **)&obj);
if(FAILED(hRes))
@ -637,7 +653,7 @@ LRESULT CALLBACK TreeProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
switch(((LPNMHDR)lParam)->code)
{
case TVN_ITEMEXPANDING:
CreateInst(((NMTREEVIEW *)lParam)->itemNew.hItem);
CreateInst(((NMTREEVIEW *)lParam)->itemNew.hItem, NULL);
break;
case TVN_SELCHANGED:
RefreshMenu(((NMTREEVIEW *)lParam)->itemNew.hItem);