/* StgCreateDocFile seems to refuse readonly access, despite MSDN */ /* if no share mode given then DENY_NONE is the default */ if (STGM_SHARE_MODE(grfMode) == 0) grfMode |= STGM_SHARE_DENY_NONE; /* must have at least one access mode */ if (STGM_ACCESS_MODE(grfMode) == 0) goto end; /* in direct mode, can only use SHARE_EXCLUSIVE */ if (!(grfMode & STGM_TRANSACTED) && (STGM_SHARE_MODE(grfMode) != STGM_SHARE_EXCLUSIVE)) /* but in transacted mode, any share mode is valid */ /* check what happens if the file already exists (which is how it's meant to be used) */ ok(r==STG_E_FILEALREADYEXISTS, "StgCreateDocfile wrong error\n"); /* FAILIFTHERE is default */ ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n"); /* need at least readmode and sharemode */ r = StgCreateDocfile( filename, STGM_TRANSACTED | STGM_SHARE_DENY_WRITE | STGM_READ, 0, &stg); ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile wrong error\n"); /* and the way windows media uses it ... */ r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_DENY_NONE | STGM_READWRITE | STGM_TRANSACTED, 0, &stg); ok(r==S_OK, "StgCreateDocfile the windows media way failed\n"); if (r == S_OK) { r = IStorage_Release(stg); ok(r == 0, "storage not released\n"); ok(DeleteFileW(filename), "failed to delete file\n"); } /* skip over the ACE we are deleting */ dwAceIndex++; /* calculate the length of the rest */ /* slide them all backwards */ memmove(pAce, ((BYTE*)pAce)+pAce->AceSize, len); pAcl->AceCount--; if (longpath[0] != '/' && longpath[1] == ':' ) if (!bmihc) goto ret1; if (!hbmColor) { WARN("failed to read bitmap from stream\n"); } if (!enhHeader) return 0; * path [I] Path to search (NULL means default) WCHAR *pathW = NULL, *nameW = NULL, *extW = NULL; if (!name || !(nameW = FILE_name_AtoW( name, FALSE ))) return 0; if (path && !(pathW = FILE_name_AtoW( path, TRUE ))) return 0; if(iIntID < TMT_FIRSTINT || iIntID > TMT_LASTINT) { WARN("Unknown IntID: %d\n", iIntID); if (GetVersion() & 0x80000000) access = PROCESS_ALL_ACCESS; #include "winternl.h" #include "winnt.h" BOOL do_escape; Wine_GLContext *curctx = (Wine_GLContext *) NtCurrentTeb()->glContext; if (curctx && curctx->do_escape) { enum x11drv_escape_codes escape = X11DRV_SYNC_PIXMAP; ExtEscape(curctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape, 0, NULL); } NtCurrentTeb()->glContext = NULL; NtCurrentTeb()->glContext = ctx; { ctx->do_escape = TRUE; } FIXME("unsupported on this platform\n"); #endif static WORD winver = WIN98; pRpcMessage->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION; sizeof(INTERNET_PROXY_INFOW)); { pPI->lpszProxy = (LPWSTR)((LPBYTE)lpBuffer + sizeof(INTERNET_PROXY_INFOW)); *((LPWSTR)(pPI->lpszProxy)) = 0; } sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired); { pPI->lpszProxyBypass = (LPWSTR)((LPBYTE)lpBuffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired); *((LPWSTR)(pPI->lpszProxyBypass)) = 0; } sizeof(INTERNET_PROXY_INFOA)); { pPI->lpszProxy = (LPSTR)((LPBYTE)lpBuffer + sizeof(INTERNET_PROXY_INFOA)); *((LPSTR)(pPI->lpszProxy)) = '\0'; } { pPI->lpszProxyBypass = (LPSTR)((LPBYTE)lpBuffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired); *((LPSTR)(pPI->lpszProxyBypass)) = '\0'; } IRpcChannelBuffer_Release(This->chanbuf); This->chanbuf = NULL; TRACE("%p, %ld\n", iface, This->refs + 1); TRACE("%p, %ld\n", iface, ref); TRACE("%p, %p\n", iface, pRpcChannelBuffer); TRACE("%p, %p\n", iface, This->chan); /* should be a fixme, but this function is called a lot by the RPC * runtime, and it slows down InstallShield a fair bit. */ WARN("stub: %p %p/%ld %p %p\n", hNamedPipe, lpMode, lpMode ? *lpMode : 0, lpMaxCollectionCount, lpCollectDataTimeout); MESSAGE( "wine: Call from %p to unimplemented function %s.%s, aborting\n", MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n", PostMessageA(This->hwndOwner, WM_COMMAND, IDOK, 0L); hRes = S_OK; if (_ILIsDesktop(pidl) || _ILIsValue(pidl) || _ILIsFolder(pidl)) if (_ILIsDesktop(pidl) ||_ILIsValue(pidl) || _ILIsFolder(pidl)) static const char *command_to_string(UINT command) { #define X(x) case x: return #x switch (command) { X( HH_DISPLAY_TOPIC ); X( HH_DISPLAY_TOC ); X( HH_DISPLAY_INDEX ); X( HH_DISPLAY_SEARCH ); X( HH_SET_WIN_TYPE ); X( HH_GET_WIN_TYPE ); X( HH_GET_WIN_HANDLE ); X( HH_ENUM_INFO_TYPE ); X( HH_SET_INFO_TYPE ); X( HH_SYNC ); X( HH_RESERVED1 ); X( HH_RESERVED2 ); X( HH_RESERVED3 ); X( HH_KEYWORD_LOOKUP ); X( HH_DISPLAY_TEXT_POPUP ); X( HH_HELP_CONTEXT ); X( HH_TP_HELP_CONTEXTMENU ); X( HH_TP_HELP_WM_HELP ); X( HH_CLOSE_ALL ); X( HH_ALINK_LOOKUP ); X( HH_GET_LAST_ERROR ); X( HH_ENUM_CATEGORY ); X( HH_ENUM_CATEGORY_IT ); X( HH_RESET_IT_FILTER ); X( HH_SET_INCLUSIVE_FILTER ); X( HH_SET_EXCLUSIVE_FILTER ); X( HH_INITIALIZE ); X( HH_UNINITIALIZE ); X( HH_PRETRANSLATEMESSAGE ); X( HH_SET_GLOBAL_PROPERTY ); default: return "???"; } #undef X } FIXME("(%p, %s, command=%s, data=%ld): stub\n", caller, debugstr_w( filename ), command_to_string( command ), data); switch (command) { case HH_DISPLAY_TOPIC: case HH_DISPLAY_TOC: case HH_DISPLAY_SEARCH: case HH_HELP_CONTEXT: MessageBoxA( NULL, "HTML Help functionality is currently unimplemented.\n\n" "Try installing Internet Explorer, or using a native hhctrl.ocx with the Mozilla ActiveX control.", "Wine", MB_OK | MB_ICONEXCLAMATION ); default: return 0; } FIXME("(%p, %s, command=%d, data=%ld): stub\n", caller, debugstr_w(filename), command, data); if (filename) { DWORD len = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 ); wfile = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR)); MultiByteToWideChar( CP_ACP, 0, filename, -1, wfile, len ); } if (*arg) TRACE_(olerelay)("%s",relaystr((WCHAR*)*arg)); if (!ptr) return TRUE; if (!ptr) return TRUE; if (!str) return TRUE; if (!str) return TRUE; elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN, WINE_DECLARE_DEBUG_CHANNEL(seh); __EXCEPT(page_fault) { TRACE_(seh)("%p caused page fault during read\n", ptr); return TRUE; } __EXCEPT(page_fault) { TRACE_(seh)("%p caused page fault during write\n", ptr); return TRUE; } __EXCEPT(page_fault) { TRACE_(seh)("%p caused page fault during read\n", str); return TRUE; } __EXCEPT(page_fault) { TRACE_(seh)("%p caused page fault during read\n", str); return TRUE; } { (void *)0x00110000, 0x1fef0000 }, /* PE exe range (may be set with WINEPRELOADRESERVE), defaults to 512mb */ WARN("Couldn't ConnectNamedPipe (error was %ld)\n", GetLastError()); WARN("connection failed, error=%lx\n", err); WARN("connection failed, error=%lx\n", err); if (!IsEqualIID(riid, &iid)) { TRACE("requested interface != marshalled interface, additional QI needed\n"); hr = IUnknown_QueryInterface(object, &iid, ppv); if (hr) ERR("Couldn't query for interface %s, hr = 0x%08lx\n", debugstr_guid(riid), hr); IUnknown_Release(object); } else { *ppv = object; } /* by default try and load using LoadLibrary (for builtin stdole32.tlb) */ memcpy(szPath, szFile, (strlenW(szFile)+1)*sizeof(WCHAR)); else { TRACE("not found, trying to load %s as library\n", debugstr_w(pszFileName)); } /* if the file is a DLL or not found, try loading it with LoadLibrary */ if (((WORD)dwSignature == IMAGE_DOS_SIGNATURE) || (dwSignature == 0)) if ((lpcf->Flags & CF_USESTYLE) && lpcf->lpszStyle) if((lpcfw->Flags & CF_USESTYLE) && lpcfw->lpszStyle) { if((lpcfa->Flags & CF_USESTYLE) && lpcfa->lpszStyle) { if((lpcfa->Flags & CF_ENABLETEMPLATE) && lpcfa->lpTemplateName) { case 4 : return WIN98; /* most apps will use this */ WARN("Unable to open .PDB file: %s\n", pdb_lookup->filename); FIXME("Version value not known yet. Please investigate it !\n"); return MAKELONG(0xffff, 40); /* for now return the same value as for w2k */ path = build_directory_name(2, package->folders[i].Property, NULL); fullname = build_directory_name(3, folder, filename, NULL); folder->Property = build_directory_name(2, szFolderPath, NULL); if (strcmpiW(path, folder->Property) == 0) dbg_printf("%*s%08x%*s %-17.17s %08lx %08lx %08lx %.14s\n", GetWindowLong(hWnd, GWL_WNDPROC), GetWindowThreadProcessId(hWnd, NULL), wndName); dbg_printf("%-20.20s %-17.17s %-8.8s %-8.8s %-8.8s %s\n", "Window handle", "Class Name", "Style", "WndProc", "Thread", "Text"); if (hres) { ERR("xbuf_get failed\n"); return hres; } ERR("Stream create failed %lx\n",hres); if (hres) { ERR("stream write %lx\n",hres); return hres; } if (hres) { ERR("Failed Seek %lx\n",hres); return hres; } ERR("Unmarshalling interface %s failed with %lx\n",debugstr_guid(riid),hres); LPUNKNOWN newiface = NULL; LPBYTE tempbuf = NULL; IStream *pStm = NULL; hres = E_FAIL; if (!pUnk) { ERR("pUnk is NULL?\n"); } hres = IUnknown_QueryInterface(pUnk,riid,(LPVOID*)&newiface); WARN("%p does not support iface %s\n",pUnk,debugstr_guid(riid)); ERR("Stream create failed %lx\n",hres); ERR("Marshalling interface %s failed with %lx\n", debugstr_guid(riid), hres); if (hres) { ERR("Stream stat failed\n"); goto fail; } if (hres) { ERR("Failed Seek %lx\n",hres); goto fail; } if (hres) { ERR("Failed Read %lx\n",hres); goto fail; } IUnknown_Release(newiface); IStream_Release(pStm); if (pStm) IUnknown_Release(pStm); if (newiface) IUnknown_Release(newiface); HeapFree(GetProcessHeap(), 0, tempbuf); ERR("No %s key found.\n",interfacekey); ERR("Getting typelib guid failed.\n"); ERR("Could not get version value?\n"); ERR("Could not get typelib fn?\n"); ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype); ERR("Could not get vardesc of %d\n",i); if (hres) ERR("Failed to read integer 4 byte\n"); ERR("failed to read bstr klen\n"); ERR("Failed to read BSTR.\n"); ERR("Failed to load pointer cookie.\n"); ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype); ERR("Could not get typeattr in VT_USERDEFINED.\n"); ERR("Could not get vardesc of %d\n",i); ERR("failed to stuballoc in TKIND_RECORD.\n"); ERR("GetTypeAttr failed with %lx\n",hres); ERR("Did not find a reftype for interface offset %d?\n",j); ERR("Did not find a typeinfo for reftype %ld?\n",href); ERR("Failed to serialize param, hres %lx\n",hres); ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres); ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres); ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres); ERR("Failed to unmarshall param, hres %lx\n",hres); ERR("No typeinfo for %s?\n",debugstr_guid(riid)); ERR("GetFuncDesc %lx should not fail here.\n",hres); ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres); ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres); ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names[i+1]),hres); ERR("Failed to stuballoc param, hres %lx\n",hres); ERR("No typeinfo for %s?\n",debugstr_guid(riid)); ERR("Connect to pUnkServer failed?\n"); FIXME("Unmarshalling interface %s failed with %lx\n",debugstr_guid(riid),hres); return hres; status = hres; * Copyright 2002 Marcus Meissner * Copyright 2005 Mike Hearn, Rob Shearman for CodeWeavers #define REQTYPE_RESPONSE 1 #define REQTYPE_DISCONNECT 2 struct request_header { }; struct response_header { }; struct disconnect_header { }; struct rpc { struct request_header reqh; struct response_header resph; }; static struct rpc **reqs = NULL; struct pipe { }; static struct pipe pipes[MAX_WINE_PIPES]; IRpcChannelBufferVtbl *lpVtbl; DWORD ref; wine_marshal_id mid; PIPE_RegisterPipe(wine_marshal_id *mid, HANDLE hPipe, BOOL startreader) { /* FIXME: this pipe caching code is commented out because it is breaks the * tests, causing them hang due to writing to or reading from the wrong pipe. */ int i; for (i=0;ioxid) return S_OK; if (nrofpipes + 1 >= MAX_WINE_PIPES) { FIXME("Out of pipes, please increase MAX_WINE_PIPES\n"); return E_OUTOFMEMORY; } memcpy(&(pipes[nrofpipes].mid),mid,sizeof(*mid)); pipes[nrofpipes].hPipe = hPipe; pipes[nrofpipes].apt = COM_CurrentApt(); assert( pipes[nrofpipes].apt ); InitializeCriticalSection(&(pipes[nrofpipes].crit)); nrofpipes++; if (startreader) { pipes[nrofpipes-1].hThread = CreateThread(NULL,0,stub_dispatch_thread,(LPVOID)(pipes+(nrofpipes-1)),0,&(pipes[nrofpipes-1].tid)); } else { pipes[nrofpipes-1].tid = GetCurrentThreadId(); } return S_OK; static struct pipe* RPC_GetRequest(struct rpc **req) { reqs = (struct rpc**)HeapReAlloc( sizeof(struct rpc*)*(nrofreqs+1) reqs = (struct rpc**)HeapAlloc( sizeof(struct rpc*) reqs[nrofreqs] = (struct rpc*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(struct rpc)); RPC_FreeRequest(struct rpc *req) { struct disconnect_header header; write_pipe(pipe, &header, sizeof(struct disconnect_header)); PipeBuf_GetBuffer(LPRPCCHANNELBUFFER iface,RPCOLEMESSAGE* msg,REFIID riid) { COM_InvokeAndRpcSend(struct rpc *req) { static HRESULT COM_RpcReceive(struct pipe *xpipe); RPC_QueueRequestAndWait(struct rpc *req) { int i; struct rpc *xreq; HRESULT hres; DWORD reqtype; struct pipe *xpipe = PIPE_GetFromMID(&(req->reqh.mid)); PipeBuf_SendReceive(LPRPCCHANNELBUFFER iface,RPCOLEMESSAGE* msg,ULONG *status) { struct rpc *req; PipeBuf_FreeBuffer(LPRPCCHANNELBUFFER iface,RPCOLEMESSAGE* msg) { PipeBuf_GetDestCtx(LPRPCCHANNELBUFFER iface,DWORD* pdwDestContext,void** ppvDestContext) { PipeBuf_IsConnected(LPRPCCHANNELBUFFER iface) { HRESULT PIPE_GetNewPipeBuf(wine_marshal_id *mid, IRpcChannelBuffer **pipebuf) { wine_marshal_id ourid; DWORD res; HANDLE hPipe; HRESULT hres; PipeBuf *pbuf; hPipe = PIPE_FindByMID(mid); if (hPipe == INVALID_HANDLE_VALUE) { char pipefn[200]; sprintf(pipefn,OLESTUBMGR"_%08lx%08lx",(DWORD)(mid->oxid >> 32),(DWORD)mid->oxid); hPipe = CreateFileA(pipefn, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0); if (hPipe == INVALID_HANDLE_VALUE) { FIXME("Could not open named pipe %s, le is %lx\n",pipefn,GetLastError()); return E_FAIL; } hres = PIPE_RegisterPipe(mid, hPipe, FALSE); if (hres) return hres; memset(&ourid,0,sizeof(ourid)); ourid.oxid = COM_CurrentApt()->oxid; if (!WriteFile(hPipe,&ourid,sizeof(ourid),&res,NULL)||(res!=sizeof(ourid))) { ERR("Failed writing startup mid!\n"); return E_FAIL; } } pbuf = (PipeBuf*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(PipeBuf)); pbuf->lpVtbl = &pipebufvt; pbuf->ref = 1; memcpy(&(pbuf->mid),mid,sizeof(*mid)); *pipebuf = (IRpcChannelBuffer*)pbuf; return S_OK; create_server(REFCLSID rclsid) { static const WCHAR embedding[] = { ' ', '-','E','m','b','e','d','d','i','n','g',0 }; HKEY key; char buf[200]; HRESULT hres = E_UNEXPECTED; char xclsid[80]; WCHAR exe[MAX_PATH+1]; DWORD exelen = sizeof(exe); WCHAR command[MAX_PATH+sizeof(embedding)/sizeof(WCHAR)]; STARTUPINFOW sinfo; PROCESS_INFORMATION pinfo; WINE_StringFromCLSID((LPCLSID)rclsid,xclsid); sprintf(buf,"CLSID\\%s\\LocalServer32",xclsid); hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, buf, 0, KEY_READ, &key); if (hres != ERROR_SUCCESS) { WARN("CLSID %s not registered as LocalServer32\n", xclsid); return REGDB_E_READREGDB; /* Probably */ } memset(exe,0,sizeof(exe)); hres= RegQueryValueExW(key, NULL, NULL, NULL, (LPBYTE)exe, &exelen); RegCloseKey(key); if (hres) { WARN("No default value for LocalServer32 key\n"); return REGDB_E_CLASSNOTREG; /* FIXME: check retval */ } memset(&sinfo,0,sizeof(sinfo)); sinfo.cb = sizeof(sinfo); /* EXE servers are started with the -Embedding switch. MSDN also claims /Embedding is used, * 9x does -Embedding, perhaps an 9x/NT difference? */ strcpyW(command, exe); strcatW(command, embedding); TRACE("activating local server '%s' for %s\n", debugstr_w(command), xclsid); if (!CreateProcessW(exe, command, NULL, NULL, FALSE, 0, NULL, NULL, &sinfo, &pinfo)) { WARN("failed to run local server %s\n", debugstr_w(exe)); return E_FAIL; } return S_OK; DWORD r = ERROR_FUNCTION_FAILED; if (r == ERROR_SERVICE_ALREADY_RUNNING) static const WCHAR szLocalService[] = { 'L','o','c','a','l','S','e','r','v','i','c','e',0 }; static const WCHAR szServiceParams[] = {'S','e','r','v','i','c','e','P','a','r','a','m','s',0}; HRESULT create_marshalled_proxy(REFCLSID rclsid, REFIID iid, LPVOID *ppv) { HRESULT hres; HANDLE hPipe; char pipefn[200]; DWORD res, bufferlen; char marshalbuffer[200]; IStream *pStm; LARGE_INTEGER seekto; ULARGE_INTEGER newpos; int tries = 0; static const int MAXTRIES = 10000; TRACE("rclsid=%s, iid=%s\n", debugstr_guid(rclsid), debugstr_guid(iid)); strcpy(pipefn,PIPEPREF); WINE_StringFromCLSID(rclsid,pipefn+strlen(PIPEPREF)); while (tries++ < MAXTRIES) { TRACE("waiting for %s\n", pipefn); WaitNamedPipeA( pipefn, NMPWAIT_WAIT_FOREVER ); hPipe = CreateFileA(pipefn, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0); if (hPipe == INVALID_HANDLE_VALUE) { if (tries == 1) { if ( (hres = create_server(rclsid)) && (hres = create_local_service(rclsid)) ) return hres; Sleep(1000); } else { WARN("Could not open named pipe to broker %s, le is %lx\n",pipefn,GetLastError()); Sleep(1000); } continue; } bufferlen = 0; if (!ReadFile(hPipe,marshalbuffer,sizeof(marshalbuffer),&bufferlen,NULL)) { FIXME("Failed to read marshal id from classfactory of %s.\n",debugstr_guid(rclsid)); Sleep(1000); continue; } TRACE("read marshal id from pipe\n"); CloseHandle(hPipe); break; } if (tries >= MAXTRIES) return E_NOINTERFACE; hres = CreateStreamOnHGlobal(0,TRUE,&pStm); if (hres) return hres; hres = IStream_Write(pStm,marshalbuffer,bufferlen,&res); if (hres) goto out; seekto.u.LowPart = 0;seekto.u.HighPart = 0; hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos); TRACE("unmarshalling classfactory\n"); hres = CoUnmarshalInterface(pStm,&IID_IClassFactory,ppv); IStream_Release(pStm); return hres; PIPE_StartRequestThread(HANDLE xhPipe) { wine_marshal_id remoteid; HRESULT hres; COM_RpcReceive(struct pipe *xpipe) { DWORD reqtype; HRESULT hres = S_OK; HANDLE xhPipe = xpipe->hPipe; /* only received by servers */ if (reqtype == REQTYPE_DISCONNECT) { struct disconnect_header header; struct rpc *xreq; struct response_header resph; struct rpc *xreq = reqs[i]; struct pipe *xpipe = (struct pipe*)param; HANDLE xhPipe = xpipe->hPipe; HRESULT hres = S_OK; struct rpc *xreq = reqs[i]; DWORD magic; /* prevent a disconnect race with the other side: this isn't * necessary for real dcom but the test suite needs it */ read_pipe(pipe, &magic, sizeof(magic)); if (magic != 0xcafebabe) ERR("bad disconnection magic: expecting 0xcafebabe but got 0x%lx", magic); DWORD magic = 0xcafebabe; write_pipe(xhPipe, &magic, sizeof(magic)); static WINE_MODREF *last_failed_modref; { } { /* point to the name so LdrInitializeThunk can print it */ last_failed_modref = wm; WARN("Initialization of %s failed\n", debugstr_w(wm->ldr.BaseDllName.Buffer)); } if ((status = process_attach( wm, (LPVOID)1 )) != STATUS_SUCCESS) { if (last_failed_modref) ERR( "%s failed to initialize, aborting\n", debugstr_w(last_failed_modref->ldr.BaseDllName.Buffer) + 1 ); goto error; } *(strrchr(msg, '\r')) = '\0'; char *cursor; /* correct the slashes in the path to be UNIX style */ while ((cursor = strchr(targetpath, '\\'))) *cursor = '/'; WINE_WARN("unable to set volume label for devicename of '%s', label of '%s'\n", HeapFree(GetProcessHeap(), 0, drives[i].unixpath); drives[i].unixpath = NULL; HeapFree(GetProcessHeap(), 0, drives[i].label); drives[i].label = NULL; HeapFree(GetProcessHeap(), 0, drives[i].serial); drives[i].serial = NULL; static void update_controls(HWND dialog); update_controls(dialog); update_controls(dialog); static void update_controls(HWND dialog) { * - Make the MTA dynamically allocated and refcounted * APARTMENT MTA; struct list apts = LIST_INIT( apts ); APARTMENT *apt = COM_CurrentApt(); if (!apt) if (model & COINIT_MULTITHREADED) { TRACE("thread 0x%lx is entering the multithreaded apartment\n", GetCurrentThreadId()); COM_CurrentInfo()->apt = &MTA; return apt; } TRACE("creating new apartment, model=%ld\n", model); list_init(&apt->proxies); list_init(&apt->stubmgrs); apt->oidc = 1; apt->refs = 1; InitializeCriticalSection(&apt->cs); apt->model = model; /* we don't ref the apartment as CoInitializeEx will do it for us */ if (model & COINIT_APARTMENTTHREADED) { /* FIXME: how does windoze create OXIDs? */ apt->oxid = MTA.oxid | GetCurrentThreadId(); apt->win = CreateWindowA(aptWinClass, NULL, 0, 0, 0, 0, 0, 0, 0, OLE32_hInstance, NULL); } EnterCriticalSection(&csApartment); list_add_head(&apts, &apt->entry); LeaveCriticalSection(&csApartment); COM_CurrentInfo()->apt = apt; DWORD COM_ApartmentAddRef(struct apartment *apt) { return InterlockedIncrement(&apt->refs); } DWORD COM_ApartmentRelease(struct apartment *apt) DWORD ret; ret = InterlockedDecrement(&apt->refs); if (ret == 0) { TRACE("destroying apartment %p, oxid %s\n", apt, wine_dbgstr_longlong(apt->oxid)); MARSHAL_Disconnect_Proxies(apt); list_remove(&apt->entry); if ((apt->model & COINIT_APARTMENTTHREADED) && apt->win) DestroyWindow(apt->win); if (!list_empty(&apt->stubmgrs)) { FIXME("PANIC: Apartment being destroyed with outstanding stubs, what do we do now?\n"); } if (apt->filter) IUnknown_Release(apt->filter); DeleteCriticalSection(&apt->cs); CloseHandle(apt->thread); HeapFree(GetProcessHeap(), 0, apt); apt = NULL; LeaveCriticalSection(&csApartment); return ret; } /* The given OXID must be local to this process: you cannot use * apartment windows to send RPCs to other processes. This all needs * to move to rpcrt4. * * The ref parameter is here mostly to ensure people remember that * they get one, you should normally take a ref for thread safety. */ APARTMENT *COM_ApartmentFromOXID(OXID oxid, BOOL ref) APARTMENT *result = NULL; struct list *cursor; LIST_FOR_EACH( cursor, &apts ) { struct apartment *apt = LIST_ENTRY( cursor, struct apartment, entry ); if (apt->oxid == oxid) { result = apt; if (ref) COM_ApartmentAddRef(result); break; } } return result; HWND COM_GetApartmentWin(OXID oxid, BOOL ref) APARTMENT *apt; apt = COM_ApartmentFromOXID(oxid, ref); if (!apt) return NULL; return apt->win; } LPVOID lpReserved, /* [in] pointer to win32 malloc interface (obsolete, should be NULL) */ /* we may need to defer this until after apartment initialisation */ if (!(apt = COM_CurrentInfo()->apt)) { apt = COM_CreateApartment(dwCoInit); } else { InterlockedIncrement(&apt->refs); } if (dwCoInit != apt->model) { /* Changing the threading model after it's been set is illegal. If this warning is triggered by Wine code then we are probably using the wrong threading model to implement that API. */ ERR("Attempt to change threading model of this apartment from 0x%lx to 0x%lx\n", apt->model, dwCoInit); return RPC_E_CHANGED_MODE; } APARTMENT *apt = COM_CurrentApt(); while (PeekMessageA(&message, NULL, 0, 0, PM_REMOVE)) { if (message.hwnd != apt->win) { WARN("discarding message 0x%x for window %p\n", message.message, message.hwnd); continue; } if (!COM_ApartmentRelease(COM_CurrentInfo()->apt)) COM_CurrentInfo()->apt = NULL; * * S_OK on success, * E_INVALIDARG if lpdwRegister or pUnk are NULL, hr = IUnknown_QueryInterface(newClass->classObject, &IID_IClassFactory, if (StdGlobalInterfaceTableInstance == NULL) HRESULT hr = E_FAIL; *ppv = NULL; if (COM_CurrentInfo()->state) { IUnknown_AddRef(COM_CurrentInfo()->state); *ppv = COM_CurrentInfo()->state; TRACE("apt->state=%p\n", COM_CurrentInfo()->state); hr = S_OK; } return hr; if (pv) IUnknown_AddRef(pv); if (COM_CurrentInfo()->state) { TRACE("-- release %p now\n", COM_CurrentInfo()->state); IUnknown_Release(COM_CurrentInfo()->state); } COM_CurrentInfo()->state = pv; return S_OK; struct apartment; struct apartment *parent; struct apartment *parent; /* this needs to become a COM object that implements IRemUnknown */ struct apartment { struct list entry; DWORD refs; /* refcount of the apartment */ }; typedef struct apartment APARTMENT; /* compobj.c */ APARTMENT *COM_CreateApartment(DWORD model); APARTMENT *COM_ApartmentFromOXID(OXID oxid, BOOL ref); DWORD COM_ApartmentAddRef(struct apartment *apt); DWORD COM_ApartmentRelease(struct apartment *apt); extern CRITICAL_SECTION csApartment; /* this is what is stored in TEB->ReservedForOle */ struct oletls { struct apartment *apt; IErrorInfo *errorinfo; /* see errorinfo.c */ IUnknown *state; /* see CoSetState */ }; /* will create if necessary */ static inline struct oletls *COM_CurrentInfo(void) if (!NtCurrentTeb()->ReservedForOle) NtCurrentTeb()->ReservedForOle = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct oletls)); return NtCurrentTeb()->ReservedForOle; { return COM_CurrentInfo()->apt; * TEB at offset 0xf80. TRACE("(%ld, %p, %p)\n", dwReserved, pperrinfo, COM_CurrentInfo()->errorinfo); if (!COM_CurrentInfo()->errorinfo) *pperrinfo = COM_CurrentInfo()->errorinfo; COM_CurrentInfo()->errorinfo = NULL; pei = COM_CurrentInfo()->errorinfo; if (pei) IErrorInfo_Release(pei); COM_CurrentInfo()->errorinfo = perrinfo; if (perrinfo) IErrorInfo_AddRef(perrinfo); struct apartment *apt; TRACE("constructing new stub manager\n"); apt = COM_ApartmentFromOXID(mid->oxid, TRUE); manager = new_stub_manager(apt, obj); COM_ApartmentRelease(apt); /* we must join the marshalling threads apartment. we already have a ref here */ /* this refs the apartment on success, otherwise there is no ref */ COM_ApartmentAddRef(apt); if (!(apt = COM_ApartmentFromOXID(oxid, TRUE))) COM_ApartmentRelease(apt); if (!(apt = COM_ApartmentFromOXID(oxid, TRUE))) COM_ApartmentRelease(apt); * * TODO list: (items bunched together depend on each other) * * - Switch wine_marshal_id to use IPIDs not IIDs * - Once that's done, replace wine_marshal_id with STDOBJREF * * - Rewrite the CoLockObjectExternal code, it does totally the wrong * thing currently (should be controlling the stub manager) * * - Implement the service control manager (in rpcss) to keep track * of registered class objects: ISCM::ServerRegisterClsid et al * - Implement the OXID resolver so we don't need magic pipe names for * clients and servers to meet up * - Flip our marshalling on top of the RPC runtime transport API, * so we no longer use named pipes to communicate * - Rework threading so re-entrant calls don't need to be sent on * the incoming pipe * - Implement RPC thread affinity (should fix InstallShield painting * problems) * * - Implement IRemUnknown and marshalling for it, then use that for * reffing/unreffing the stub manager from a proxy instead of our * current hack of simply reffing the stub manager once when it's * registered. * - Implement table marshalling, then use it to let us do the final * rework of the threading * * - Make our custom marshalling use NDR to be wire compatible with * native DCOM * * ERR("PANIC: Stub manager %s is being destroyed with outstanding interface stubs\n", wine_dbgstr_longlong(m->oid)); /* assert( FALSE ); */ /* fixme: this will happen sometimes until we do proper lifecycle management via IRemUnknown */ APARTMENT *apt; /* owning apartment */ list_init(&apt->stubmgrs); apt->oidc = 1; APARTMENT *COM_ApartmentFromOXID(OXID oxid) APARTMENT *apt = NULL; return apt; } HWND COM_GetApartmentWin(OXID oxid) { APARTMENT *apt = COM_ApartmentFromOXID(oxid); return apt ? apt->win : NULL; /* we need to enter the apartment of the thread which registered * the class object to perform the next stage */ assert( newClass->apt ); NtCurrentTeb()->ReservedForOle = newClass->apt; if (!COM_CurrentApt()) { ERR("COM was not initialized\n"); return CO_E_NOTINITIALIZED; } newClass->apt = COM_CurrentApt(); TRACE("pUnk=%p, fLock=%s, fLastUnlockReleases=%s\n", pUnk, fLock ? "TRUE" : "FALSE", fLastUnlockReleases ? "TRUE" : "FALSE"); * Copyright 2004 Mike Hearn, CodeWeavers Inc #include "wine/list.h" OID oidc; /* object ID counter, starts at 1, zero is invalid OID */ IOBJECT *proxies; /* imported objects */ struct list stubmgrs; /* stub managers for exported objects */ OXID oxid; /* id of apartment */ OID oid; /* id of stub manager */ IID iid; /* id of interface (NOT ifptr) */ /* an interface stub */ struct ifstub { struct list entry; IRpcStubBuffer *stubbuffer; IID iid; /* fixme: this should be an IPID not an IID */ IUnknown *iface; BOOL table; }; /* stub managers hold refs on the object and each interface stub */ struct stub_manager { struct list entry; struct list ifstubs; CRITICAL_SECTION lock; APARTMENT *apt; /* owning apt */ DWORD refcount; /* count of 'external' references */ OID oid; /* apartment-scoped unique identifier */ IUnknown *object; /* the object we are managing the stub for */ DWORD next_ipid; /* currently unused */ }; struct stub_manager *new_stub_manager(APARTMENT *apt, IUnknown *object); int stub_manager_ref(struct stub_manager *m, int refs); int stub_manager_unref(struct stub_manager *m, int refs); IRpcStubBuffer *stub_manager_iid_to_stubbuffer(struct stub_manager *m, IID *iid); struct ifstub *stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *sb, IUnknown *iptr, IID *iid, BOOL tablemarshal); struct stub_manager *get_stub_manager(OXID oxid, OID oid); struct stub_manager *get_stub_manager_from_object(OXID oxid, void *object); void stub_manager_delete_ifstub(struct stub_manager *m, IID *iid); /* fixme: should be ipid */ IRpcStubBuffer *mid_to_stubbuffer(wine_marshal_id *mid); APARTMENT *COM_CreateApartment(DWORD model); APARTMENT *COM_ApartmentFromOXID(OXID oxid); * Copyright 2002 Marcus Meissner * Copyright 2004 Mike Hearn, for CodeWeavers * Copyright 2004 Rob Shearman, for CodeWeavers * * In Windows, a different triple is used: OXID (apt id), OID (stub * manager id), IPID (interface ptr/stub id). * * OXIDs identify an apartment and are network scoped * OIDs identify a stub manager and are apartment scoped * IPIDs identify an interface stub and are apartment scoped IRpcStubBuffer *mid_to_stubbuffer(wine_marshal_id *mid) { struct stub_manager *m; if (!(m = get_stub_manager(mid->oxid, mid->oid))) { WARN("unknown OID %s\n", wine_dbgstr_longlong(mid->oid)); return NULL; return stub_manager_iid_to_stubbuffer(m, &mid->iid); } /* fixme: this should return an IPID */ /* creates a new stub manager and sets mid->oid when mid->oid == 0 */ static HRESULT register_ifstub(wine_marshal_id *mid, IUnknown *obj, IRpcStubBuffer *stub, BOOL tablemarshal) { struct stub_manager *manager = NULL; struct ifstub *ifstub; /* mid->oid of zero means create a new stub manager */ if (mid->oid && (manager = get_stub_manager(mid->oxid, mid->oid))) { TRACE("registering new ifstub on pre-existing manager\n"); else { TRACE("constructing new stub manager\n"); manager = new_stub_manager(COM_ApartmentFromOXID(mid->oxid), obj); if (!manager) return E_OUTOFMEMORY; if (!tablemarshal) stub_manager_ref(manager, 1); mid->oid = manager->oid; ifstub = stub_manager_new_ifstub(manager, stub, obj, &mid->iid, tablemarshal); return ifstub ? S_OK : E_OUTOFMEMORY; wine_marshal_id mid; wine_marshal_data md; IUnknown *pUnk; ULONG res; HRESULT hres; IRpcStubBuffer *stubbuffer; IPSFactoryBuffer *psfacbuf; BOOL tablemarshal; struct stub_manager *manager; hres = IPSFactoryBuffer_CreateStub(psfacbuf,riid,pv,&stubbuffer); FIXME("Failed to create an RpcStubBuffer from PSFactory for %s\n",debugstr_guid(riid)); tablemarshal = ((mshlflags & MSHLFLAGS_TABLESTRONG) || (mshlflags & MSHLFLAGS_TABLEWEAK)); if (tablemarshal) FIXME("table marshalling unimplemented\n"); /* now fill out the MID */ mid.oxid = COM_CurrentApt()->oxid; memcpy(&mid.iid,riid,sizeof(mid.iid)); IUnknown_QueryInterface((LPUNKNOWN)pv, riid, (LPVOID*)&pUnk); if ((manager = get_stub_manager_from_object(mid.oxid, pUnk))) { mid.oid = manager->oid; } else { mid.oid = 0; /* will be set by register_ifstub */ } hres = register_ifstub(&mid, pUnk, stubbuffer, tablemarshal); if (hres) { FIXME("Failed to create ifstub, hres=0x%lx\n", hres); return hres; } hres = IStream_Write(pStm,&mid,sizeof(mid),&res); if (hres) return hres; /* and then the marshal data */ md.dwDestContext = dwDestContext; md.mshlflags = mshlflags; hres = IStream_Write(pStm,&md,sizeof(md),&res); if (hres) return hres; StdMarshalImpl_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, void **ppv) { struct stub_manager *stubmgr; /* check if we're marshalling back to ourselves */ if ((stubmgr = get_stub_manager(mid.oxid, mid.oid))) TRACE("Unmarshalling object marshalled in same apartment for iid %s, returning original object %p\n", debugstr_guid(riid), stubmgr->object); hres = IUnknown_QueryInterface(stubmgr->object, riid, ppv); if ((md.mshlflags & MSHLFLAGS_TABLESTRONG) || (md.mshlflags & MSHLFLAGS_TABLEWEAK)) FIXME("table marshalling unimplemented\n"); /* clean up the stubs */ stub_manager_delete_ifstub(stubmgr, &mid.iid); stub_manager_unref(stubmgr, 1); return hres; wine_marshal_id mid; ULONG res; HRESULT hres; struct stub_manager *stubmgr; TRACE("iface=%p, pStm=%p\n", iface, pStm); hres = IStream_Read(pStm,&mid,sizeof(mid),&res); if (hres) return hres; if (!(stubmgr = get_stub_manager(mid.oxid, mid.oid))) { ERR("could not map MID to stub manager, oxid=%s, oid=%s\n", wine_dbgstr_longlong(mid.oxid), wine_dbgstr_longlong(mid.oid)); return RPC_E_INVALID_OBJREF; } /* currently, each marshal has its own interface stub. this might * not be correct. but, it means we don't need to refcount anything * here. */ stub_manager_delete_ifstub(stubmgr, &mid.iid); stub_manager_unref(stubmgr, 1); return S_OK; IRpcStubBuffer *stub; if (!(stub = mid_to_stubbuffer(&(req->reqh.mid)))) { return E_FAIL; IUnknown_AddRef(stub); struct stub_manager *stubmgr; if (!(stubmgr = get_stub_manager(header.mid.oxid, header.mid.oid))) { ERR("could not locate stub to disconnect, mid.oid=%s\n", wine_dbgstr_longlong(header.mid.oid)); /* this should destroy the stub manager in the case of only one connection to it */ stub_manager_unref(stubmgr, 1); /* * A stub manager is an object that controls interface stubs. It is * identified by an OID (object identifier) and acts as the network * identity of the object. There can be many stub managers in a * process or apartment. * * Copyright 2002 Marcus Meissner * Copyright 2004 Mike Hearn for CodeWeavers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #define COBJMACROS #define NONAMELESSUNION #define NONAMELESSSTRUCT #include #include #include "windef.h" #include "winbase.h" #include "winuser.h" #include "objbase.h" #include "ole2.h" #include "ole2ver.h" #include "rpc.h" #include "wine/debug.h" #include "compobj_private.h" WINE_DEFAULT_DEBUG_CHANNEL(ole); struct stub_manager *new_stub_manager(APARTMENT *apt, IUnknown *object) { struct stub_manager *sm; assert( apt ); sm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct stub_manager)); if (!sm) return NULL; list_init(&sm->ifstubs); InitializeCriticalSection(&sm->lock); IUnknown_AddRef(object); sm->object = object; sm->apt = apt; EnterCriticalSection(&apt->cs); sm->oid = apt->oidc++; LeaveCriticalSection(&apt->cs); /* yes, that's right, this starts at zero. that's zero EXTERNAL * refs, ie nobody has unmarshalled anything yet. we can't have * negative refs because the stub manager cannot be explicitly * killed, it has to die by somebody unmarshalling then releasing * the marshalled ifptr. */ sm->refcount = 0; EnterCriticalSection(&apt->cs); list_add_head(&apt->stubmgrs, &sm->entry); LeaveCriticalSection(&apt->cs); TRACE("Created new stub manager (oid=%s) at %p for object with IUnknown %p\n", wine_dbgstr_longlong(sm->oid), sm, object); return sm; } struct stub_manager *get_stub_manager_from_object(OXID oxid, void *object) { struct stub_manager *result = NULL; struct list *cursor; APARTMENT *apt; if (!(apt = COM_ApartmentFromOXID(oxid))) { WARN("Could not map OXID %s to apartment object\n", wine_dbgstr_longlong(oxid)); return NULL; } EnterCriticalSection(&apt->cs); LIST_FOR_EACH( cursor, &apt->stubmgrs ) { struct stub_manager *m = LIST_ENTRY( cursor, struct stub_manager, entry ); if (m->object == object) { result = m; break; } } LeaveCriticalSection(&apt->cs); TRACE("found %p from object %p\n", result, object); return result; } struct stub_manager *get_stub_manager(OXID oxid, OID oid) { struct stub_manager *result = NULL; struct list *cursor; APARTMENT *apt; if (!(apt = COM_ApartmentFromOXID(oxid))) { WARN("Could not map OXID %s to apartment object\n", wine_dbgstr_longlong(oxid)); return NULL; } EnterCriticalSection(&apt->cs); LIST_FOR_EACH( cursor, &apt->stubmgrs ) { struct stub_manager *m = LIST_ENTRY( cursor, struct stub_manager, entry ); if (m->oid == oid) { result = m; break; } } LeaveCriticalSection(&apt->cs); TRACE("found %p from oid %s\n", result, wine_dbgstr_longlong(oid)); return result; } /* add some external references (ie from a client that demarshalled an ifptr) */ int stub_manager_ref(struct stub_manager *m, int refs) { int rc = InterlockedExchangeAdd(&m->refcount, refs) + refs; TRACE("added %d refs to %p (oid %s), rc is now %d\n", refs, m, wine_dbgstr_longlong(m->oid), rc); return rc; } /* remove some external references */ int stub_manager_unref(struct stub_manager *m, int refs) { int rc = InterlockedExchangeAdd(&m->refcount, -refs) - refs; TRACE("removed %d refs from %p (oid %s), rc is now %d\n", refs, m, wine_dbgstr_longlong(m->oid), rc); if (rc == 0) { TRACE("destroying %p (oid=%s)\n", m, wine_dbgstr_longlong(m->oid)); EnterCriticalSection(&m->apt->cs); list_remove(&m->entry); LeaveCriticalSection(&m->apt->cs); /* table strong and normal marshals have a ref on us, so we * can't die while they are outstanding unless the app does * something weird like explicitly killing us (how?) */ EnterCriticalSection(&m->lock); if (!list_empty(&m->ifstubs)) { ERR("PANIC: Stub manager is being destroyed with outstanding interface stubs\n"); assert( FALSE ); } /* fixme: the lifecycle of table-weak marshals is not * currently understood. results of testing against dcom98 * appear to contradict Essential COM -m */ LeaveCriticalSection(&m->lock); IUnknown_Release(m->object); HeapFree(GetProcessHeap(), 0, m); } return refs; } static struct ifstub *stub_manager_iid_to_ifstub(struct stub_manager *m, IID *iid) { struct list *cursor; struct ifstub *result = NULL; EnterCriticalSection(&m->lock); LIST_FOR_EACH( cursor, &m->ifstubs ) { struct ifstub *ifstub = LIST_ENTRY( cursor, struct ifstub, entry ); if (IsEqualIID(iid, &ifstub->iid)) { result = ifstub; break; } } LeaveCriticalSection(&m->lock); return result; } IRpcStubBuffer *stub_manager_iid_to_stubbuffer(struct stub_manager *m, IID *iid) { struct ifstub *ifstub = stub_manager_iid_to_ifstub(m, iid); return ifstub ? ifstub->stubbuffer : NULL; } /* registers a new interface stub COM object with the stub manager and returns registration record */ struct ifstub *stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *sb, IUnknown *iptr, IID *iid, BOOL tablemarshal) { struct ifstub *stub; TRACE("oid=%s, stubbuffer=%p, iptr=%p, iid=%s, tablemarshal=%s\n", wine_dbgstr_longlong(m->oid), sb, iptr, debugstr_guid(iid), tablemarshal ? "TRUE" : "FALSE"); stub = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct ifstub)); if (!stub) return NULL; stub->stubbuffer = sb; IUnknown_AddRef(sb); /* no need to ref this, same object as sb */ stub->iface = iptr; stub->table = tablemarshal; stub->iid = *iid; EnterCriticalSection(&m->lock); list_add_head(&m->ifstubs, &stub->entry); LeaveCriticalSection(&m->lock); return stub; } /* fixme: should ifstubs be refcounted? iid should be ipid */ void stub_manager_delete_ifstub(struct stub_manager *m, IID *iid) { struct ifstub *ifstub; TRACE("m=%p, m->oid=%s, iid=%s\n", m, wine_dbgstr_longlong(m->oid), debugstr_guid(iid)); EnterCriticalSection(&m->lock); if ((ifstub = stub_manager_iid_to_ifstub(m, iid))) { list_remove(&ifstub->entry); IUnknown_Release(ifstub->stubbuffer); IUnknown_Release(ifstub->iface); HeapFree(GetProcessHeap(), 0, ifstub); } else { WARN("could not map iid %s to ifstub\n", debugstr_guid(iid)); } LeaveCriticalSection(&m->lock); } trace("releasing marshal data\n"); ok_no_locks(); ok_ole_success(hr, CoUnmarshalInterface); todo_wine { ok_no_locks(); } ok_ole_success(hr, CoUnmarshalInterface); ok_more_than_one_lock(); todo_wine { ok_no_locks(); } ok_no_locks(); VisualID visualid; visualid = XVisualIDFromVisual(visual); SetPropA( wndPtr->hwndSelf, "__wine_x11_visual_id", (HANDLE)visualid ); TRACE("Starting classfactory server thread for %s.\n",debugstr_guid(&newClass->classIdentifier)); start_apartment_listener_thread(); DWORD listenertid; /* id of apartment_listener_thread */ void start_apartment_listener_thread(void); /* this will happen if the program attempts to marshal two * objects that implement the same interface */ FIXME("need to use IPIDs, already have mid oxid=%s, oid=%s, iid=%s\n", wine_dbgstr_longlong(mid->oxid), wine_dbgstr_longlong(mid->oid), debugstr_guid(&mid->iid)); start_apartment_listener_thread(); /* just to be sure we have one running. */ * apartment (mid) has its own pipe. The same structure is used both * for outgoing and incoming RPCs. */ DWORD tid; /* thread which owns this pipe */ APARTMENT *apt; /* apartment of the marshalling thread for the stub dispatch case */ static DWORD WINAPI stub_dispatch_thread(LPVOID); pipes[nrofpipes].apt = COM_CurrentApt(); assert( pipes[nrofpipes].apt ); pipes[nrofpipes-1].hThread = CreateThread(NULL,0,stub_dispatch_thread,(LPVOID)(pipes+(nrofpipes-1)),0,&(pipes[nrofpipes-1].tid)); TRACE("waiting for %s\n", pipefn); TRACE("read marshal id from pipe\n"); TRACE("unmarshalling classfactory\n"); /* This thread listens on the given pipe for requests to a particular stub manager */ static DWORD WINAPI stub_dispatch_thread(LPVOID param) { TRACE("starting for apartment OXID %08lx%08lx\n", (DWORD)(xpipe->mid.oxid >> 32), (DWORD)(xpipe->mid.oxid)); /* join marshalling apartment. fixme: this stuff is all very wrong, threading needs to work like native */ NtCurrentTeb()->ReservedForOle = xpipe->apt; /* fixme: this thread never quits naturally */ WARN("exiting with hres %lx\n",hres); /* This thread listens on a named pipe for each apartment that exports * objects. It deals with incoming connection requests. Each time a * client connects a separate thread is spawned for that particular * connection. * * This architecture is different in native DCOM. static DWORD WINAPI apartment_listener_thread(LPVOID param) APARTMENT *apt = (APARTMENT *) param; /* we must join the marshalling threads apartment */ NtCurrentTeb()->ReservedForOle = apt; sprintf(pipefn,OLESTUBMGR"_%08lx%08lx", (DWORD)(apt->oxid >> 32), (DWORD)(apt->oxid)); TRACE("Apartment listener thread starting on (%s)\n",pipefn); FIXME("pipe creation failed for %s, error %lx\n",pipefn,GetLastError()); void start_apartment_listener_thread() APARTMENT *apt = COM_CurrentApt(); assert( apt ); TRACE("apt->listenertid=%ld\n", apt->listenertid); /* apt->listenertid is a hack which needs to die at some point, as * it leaks information into the apartment structure. in fact, * this thread isn't quite correct anyway as native RPC doesn't * use a thread per apartment at all, instead the dispatch thread * either enters the apartment to perform the RPC (for MTAs, RTAs) * or does a context switch into it for STAs. */ if (!apt->listenertid) { CreateThread(NULL, 0, apartment_listener_thread, apt, 0, &apt->listenertid); } start_listener_thread(); newClass->hThread = CreateThread(NULL,0,_LocalServerThread,newClass,0,&tid); void start_listener_thread(); start_listener_thread(); /* Just to be sure we have one running. */ /* This thread listens on a named pipe for the entire process. It * deals with incoming connection requests to objects. */ static DWORD WINAPI listener_thread(LPVOID param) { TRACE("Process listener thread starting on (%s)\n",pipefn); void start_listener_thread() { static BOOL running = FALSE; if (!running) { running = TRUE; CreateThread(NULL, 0, listener_thread, NULL, 0, &tid); TRACE("(%p): %s\n",This, debugstr_w(szSource)); TRACE("(%p): %s\n",This, debugstr_w(szDescription)); * COM_AptWndProc by the user's code from the apartment in which the interface * was unmarshalled. The algorithm Microsoft use is currently unknown. windows to send RPCs to other processes. This all needs to move to rpcrt4 */ * Initializes the COM libraries by calling CoInitializeEx with * COINIT_APARTMENTTHREADED, ie it enters a STA thread. * SEE ALSO * CoInitializeEx * Initializes the COM libraries. The behavior used to set the win32 * IMalloc used for memory management is obsolete. If * COINIT_APARTMENTTHREADED is specified this thread enters a new STA * (single threaded apartment), otherwise COINIT_MULTITHREADED should * be specified which indicates that the thread will enter the MTA. * * Currently STA threading is only partly implemented. * * SEE ALSO * CoUninitialize ERR("Attempt to change threading model of this apartment from 0x%lx to 0x%lx\n", apt->model, dwCoInit); * This method will decrement the refcount on the COM libraries, * potentially unloading them. The current thread leaves the apartment * it's currently in. If not in an apartment, the routine does * nothing. * If COM is to be shut down, any outstanding proxies are * disconnected, all registered class objects are unregistered and the * message queue for the thread is flushed (if native does * this or not is unknown). * * SEE ALSO * CoInitializeEx * Simply forwards to UuidCreate in RPCRT4. * * SEE ALSO * UuidCreate * * * In Windows, if idstr is not a valid CLSID string then it gets * treated as a ProgID. Wine currently doesn't do this. If idstr is * NULL it's treated as an all-zero GUID. * S_OK on success * CO_E_CLASSSTRING if idstr is not a valid CLSID /* Converts a GUID into the respective string representation. */ * * * S_OK * E_FAIL REFCLSID id, /* [in] the GUID to be converted */ if ((ret = CoGetMalloc(0,&mllc))) * Modified version of StringFromCLSID that allows you to specify max * buffer size. INT WINAPI StringFromGUID2( REFGUID id, /* [in] GUID to convert to string */ LPOLESTR str, /* [out] Unicode buffer to hold result */ INT cmax) * ProgIDFromCLSID [OLE32.@] * * Converts a class id into the respective Program ID. (By using a * registry lookup) * * RETURNS * S_OK * E_OUTOFMEMORY * REGDB_E_CLASSNOTREG if the given clsid has no associated ProgID * CLSIDFromProgID [COMPOBJ.61] * * Converts a program id into the respective GUID. (By using a * registry lookup) * * S_OK * CO_E_CLASSSTRING if the given ProgID cannot be found LPCOLESTR progid, /* [in] Unicode program id as found in registry */ * This function returns the CLSID of the proxy/stub factory that * implements IPSFactoryBuffer for the specified interface. * The standard marshaller activates the object with the CLSID * returned and uses the CreateProxy and CreateStub methods on its * IPSFactoryBuffer interface to construct the proxies and stubs for a * given object. * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32 * in the registry and any interface id registered by * CoRegisterPSClsid within the current process. * FIXME: We only search the registry, not ids registered with * CoRegisterPSClsid. * * RETURNS * S_OK * E_OUTOFMEMORY * E_INVALIDARG if no PSFactoryBuffer is associated with the IID, or it could not be parsed CLSID *pclsid ) /* [out] Where to store returned proxy/stub CLSID */ * * This method will register the class object for a given class * ID. Servers housed in EXE files use this method instead of * exporting DllGetClassObject to allow other code to connect to their * objects. * When a class object (an object which implements IClassFactory) is * registered in this way, a new thread is started which listens for * connections on a named pipe specific to the registered CLSID. When * something else connects to it, it writes out the marshalled * IClassFactory interface to the pipe. The code on the other end uses * this buffer to unmarshal the class factory, and can then call * methods on it. * In Windows, such objects are registered with the RPC endpoint * mapper, not with a unique named pipe. * MSDN claims that multiple interface registrations are legal, but we * can't do that with our current implementation. * RETURNS * S_OK on success, * E_INVALIDARG if lpdwRegister or pUnk are NULL, * CO_E_OBJISREG if the object is already registered. We should not return this. * * SEE ALSO * CoRevokeClassObject, CoGetClassObject REFCLSID rclsid, /* [in] CLSID of the object to register */ LPUNKNOWN pUnk, /* [in] IUnknown of the object */ DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */ DWORD flags, /* [in] REGCLS flags indicating how connections are made */ LPDWORD lpdwRegister) /* [out] A unique cookie that can be passed to CoRevokeClassObject */ HRESULT hres; LPCLASSFACTORY lpclf = 0; if (!COM_CurrentApt()) return CO_E_NOTINITIALIZED; if (current_app) add_listview_item(listview, appname, strdupA(appname)); char *oldapp = current_app; current_app = (char *) item.lParam; if (current_app) WINE_TRACE("current_app is now %s\n", current_app); WINE_TRACE("current_app=NULL, editing global settings\n"); if ((oldapp && !current_app) || (!oldapp && current_app)) if (current_app) HeapFree(GetProcessHeap(), 0, current_app); current_app = strdupA(filetitle); WINE_TRACE("adding %s\n", current_app); add_listview_item(listview, current_app, current_app); switch(HIWORD(wParam)) { switch(LOWORD(wParam)) { switch(LOWORD(wParam)) { * Drive management code * Copyright 2003-2004 Mike Hearn struct drive drives[26]; /* one for each drive letter */ static inline int letter_to_index(char letter) return (toupper(letter) - 'A'); } /* This function produces a mask for each drive letter that isn't * currently used. Each bit of the long result represents a letter, * with A being the least significant bit, and Z being the most * significant. * * To calculate this, we loop over each letter, and see if we can get * a drive entry for it. If so, we set the appropriate bit. At the * end, we flip each bit, to give the desired result. * * The letter parameter is always marked as being available. This is * so the edit dialog can display the currently used drive letter * alongside the available ones. */ long drive_available_mask(char letter) { long result = 0; int i; WINE_TRACE("\n"); for(i = 0; i < 26; i++) { if (!drives[i].in_use) continue; result |= (1 << (toupper(drives[i].letter) - 'A')); } result = ~result; if (letter) result |= DRIVE_MASK_BIT(letter); WINE_TRACE("finished drive letter loop with %lx\n", result); return result; BOOL add_drive(char letter, char *targetpath, char *label, char *serial, uint type) int driveIndex = letter_to_index(letter); drives[driveIndex].unixpath = strdupA(targetpath); drives[driveIndex].label = strdupA(label); drives[driveIndex].serial = strdupA(serial); /* deallocates the contents of the drive. does not free the drive itself */ void delete_drive(struct drive *d) HeapFree(GetProcessHeap(), 0, d->unixpath); HeapFree(GetProcessHeap(), 0, d->label); HeapFree(GetProcessHeap(), 0, d->serial); d->in_use = FALSE; #if 0 /* currently unused, but if users have this burning desire to be able to rename drives, we can put it back in. */ BOOL copyDrive(struct drive *pSrc, struct drive *pDst) pDst->unixpath = strdupA(pSrc->unixpath); pDst->label = strdupA(pSrc->label); pDst->serial = strdupA(pSrc->serial); BOOL moveDrive(struct drive *pSrc, struct drive *pDst) delete_drive(pSrc); #endif /* Load currently defined drives into the drives array */ void load_drives() char *devices, *dev; int len; int drivecount = 0, i; int retval; static const int arraysize = 512; WINE_TRACE("\n"); /* FIXME: broken symlinks in $WINEPREFIX/dosdevices will not be returned by this API, so we need to handle that */ /* setup the drives array */ dev = devices = HeapAlloc(GetProcessHeap(), 0, arraysize); len = GetLogicalDriveStrings(arraysize, devices); /* make all devices unused */ for (i = 0; i < 26; i++) drives[i].letter = 'A' + i; drives[i].in_use = FALSE; /* work backwards through the result of GetLogicalDriveStrings */ while (len) char volname[512]; /* volume name */ DWORD serial; char serialstr[256]; char rootpath[256]; char simplepath[3]; int pathlen; char targetpath[256]; char *c; *devices = toupper(*devices); WINE_TRACE("devices == '%s'\n", devices); volname[0] = 0; retval = GetVolumeInformation(devices, volname, sizeof(volname), &serial, NULL, NULL, NULL, 0); if(!retval) { WINE_ERR("GetVolumeInformation() for '%s' failed, setting serial to 0\n", devices); PRINTERROR(); serial = 0; } WINE_TRACE("serial: '0x%lX'\n", serial); /* build rootpath for GetDriveType() */ strncpy(rootpath, devices, sizeof(rootpath)); pathlen = strlen(rootpath); /* ensure that we have a backslash on the root path */ if ((rootpath[pathlen - 1] != '\\') && (pathlen < sizeof(rootpath))) { rootpath[pathlen] = '\\'; rootpath[pathlen + 1] = 0; } strncpy(simplepath, devices, 2); /* QueryDosDevice() requires no trailing backslash */ simplepath[2] = 0; QueryDosDevice(simplepath, targetpath, sizeof(targetpath)); /* targetpath may have forward slashes rather than backslashes, so correct */ c = targetpath; do if (*c == '\\') *c = '/'; while (*c++); snprintf(serialstr, sizeof(serialstr), "%lX", serial); WINE_TRACE("serialstr: '%s'\n", serialstr); add_drive(*devices, targetpath, volname, serialstr, GetDriveType(rootpath)); len -= strlen(devices); devices += strlen(devices); /* skip over any nulls */ while ((*devices == 0) && (len)) { len--; devices++; } drivecount++; WINE_TRACE("found %d drives\n", drivecount); HeapFree(GetProcessHeap(), 0, dev); /* some of this code appears to be broken by bugs in Wine: the label * setting code has no effect, for instance */ void apply_drive_changes() snprintf(devicename, sizeof(devicename), "%c:", 'A' + i); } else } else if(foundDrive && !drives[i].in_use) } else } else if(drives[i].in_use) /* foundDrive must be false from the above check */ snprintf(devicename, sizeof(devicename), "%c:", 'A' + i); } else } else } else } else if (hFile != INVALID_HANDLE_VALUE) NULL); NULL); } else delete_drive(&drives[i]); /* free up the string memory */ /* * Drive autodetection code * * Copyright 2004 Mike Hearn * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include #include #include "winecfg.h" #include #include #include #include #include #include WINE_DEFAULT_DEBUG_CHANNEL(winecfg); BOOL gui_mode = TRUE; static long working_mask = 0; static char *ignored_fstypes[] = { "devpts", "tmpfs", "proc", "sysfs", "swap", "usbdevfs", "rpc_pipefs", NULL }; static BOOL should_ignore_fstype(char *type) { char **s; for (s = ignored_fstypes; *s; s++) if (!strcmp(*s, type)) return TRUE; return FALSE; } static BOOL is_drive_defined(char *path) { int i; for (i = 0; i < 26; i++) if (drives[i].in_use && !strcmp(drives[i].unixpath, path)) return TRUE; return FALSE; } /* returns Z + 1 if there are no more available letters */ static char allocate_letter() { char letter; for (letter = 'C'; letter <= 'Z'; letter++) if ((DRIVE_MASK_BIT(letter) & working_mask) != 0) break; return letter; } #define FSTAB_OPEN 1 #define NO_MORE_LETTERS 2 #define NO_ROOT 3 #define NO_DRIVE_C 4 static void report_error(int code) { char *buffer; int len; switch (code) { case FSTAB_OPEN: if (gui_mode) { static const char *s = "Could not open your mountpoint description table.\n\nOpening of /etc/fstab failed: %s"; len = snprintf(NULL, 0, s, strerror(errno)); buffer = HeapAlloc(GetProcessHeap(), 0, len + 1); snprintf(buffer, len, s, strerror(errno)); MessageBox(NULL, s, "", MB_OK | MB_ICONEXCLAMATION); HeapFree(GetProcessHeap(), 0, buffer); } else { fprintf(stderr, "winecfg: could not open fstab: %s", strerror(errno)); } break; case NO_MORE_LETTERS: if (gui_mode) MessageBox(NULL, "No more letters are available to auto-detect available drives with.", "", MB_OK | MB_ICONEXCLAMATION); fprintf(stderr, "winecfg: no more available letters while scanning /etc/fstab"); break; case NO_ROOT: if (gui_mode) MessageBox(NULL, "Could not ensure that the root directory was mapped.\n\n" "This can happen if you run out of drive letters. " "It's important to have the root directory mapped, otherwise Wine" "will not be able to always find the programs you want to run. " "Try unmapping a drive letter then trying again.", "", MB_OK | MB_ICONEXCLAMATION); else fprintf(stderr, "winecfg: unable to map root drive\n"); break; case NO_DRIVE_C: if (gui_mode) MessageBox(NULL, "No virtual drive C mapped\n\nTry running wineprefixcreate", "", MB_OK | MB_ICONEXCLAMATION); else fprintf(stderr, "winecfg: no drive_c directory\n"); } } static void ensure_root_is_mapped() { int i; BOOL mapped = FALSE; for (i = 0; i < 26; i++) if (drives[i].in_use && !strcmp(drives[i].unixpath, "/")) mapped = TRUE; if (!mapped) { /* work backwards from Z, trying to map it */ char letter; for (letter = 'Z'; letter >= 'A'; letter--) { if (drives[letter - 'A'].in_use) continue; add_drive(letter, "/", "System", 0, DRIVE_FIXED); WINE_TRACE("allocated drive %c as the root drive\n", letter); } if (letter == ('A' - 1)) report_error(NO_ROOT); } } static void ensure_drive_c_is_mapped() { struct stat buf; const char *configdir = wine_get_config_dir(); int len; char *drive_c_dir; if (drives[2].in_use) return; len = snprintf(NULL, 0, "%s/../drive_c", configdir); drive_c_dir = HeapAlloc(GetProcessHeap(), 0, len); snprintf(drive_c_dir, len, "%s/../drive_c", configdir); HeapFree(GetProcessHeap(), 0, drive_c_dir); if (stat(drive_c_dir, &buf) == 0) { add_drive('C', "../drive_c", "Virtual Windows Drive", "0", DRIVE_FIXED); } else { report_error(NO_DRIVE_C); } } int autodetect_drives() { struct mntent *ent; FILE *fstab; /* we want to build a list of autodetected drives, then ensure each entry exists in the users setup. so, we superimpose the autodetected drives onto whatever is pre-existing. for now let's just rummage around inside the fstab. */ load_drives(); working_mask = drive_available_mask('\0'); fstab = fopen("/etc/fstab", "r"); if (!fstab) { report_error(FSTAB_OPEN); return FALSE; } while ((ent = getmntent(fstab))) { char letter; char label[256]; int type; WINE_TRACE("ent->mnt_dir=%s\n", ent->mnt_dir); if (should_ignore_fstype(ent->mnt_type)) continue; if (is_drive_defined(ent->mnt_dir)) continue; /* allocate a drive for it */ letter = allocate_letter(); if (letter == ']') { report_error(NO_MORE_LETTERS); fclose(fstab); return FALSE; } WINE_TRACE("adding drive %c for %s, type %s\n", letter, ent->mnt_dir, ent->mnt_type); strncpy(label, "Drive X", 8); label[6] = letter; if (!strcmp(ent->mnt_type, "nfs")) type = DRIVE_REMOTE; else if (!strcmp(ent->mnt_type, "nfs4")) type = DRIVE_REMOTE; else if (!strcmp(ent->mnt_type, "smbfs")) type = DRIVE_REMOTE; else if (!strcmp(ent->mnt_type, "cifs")) type = DRIVE_REMOTE; else if (!strcmp(ent->mnt_type, "coda")) type = DRIVE_REMOTE; else if (!strcmp(ent->mnt_type, "iso9660")) type = DRIVE_CDROM; else if (!strcmp(ent->mnt_type, "ramfs")) type = DRIVE_RAMDISK; else type = DRIVE_FIXED; add_drive(letter, ent->mnt_dir, label, "0", type); working_mask |= DRIVE_MASK_BIT(letter); } fclose(fstab); ensure_root_is_mapped(); ensure_drive_c_is_mapped(); return TRUE; } /* * Drive management UI code * * Copyright 2003 Mark Westcott * Copyright 2004 Chris Morgan * Copyright 2003-2004 Mike Hearn * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include #include #include #include #include #include #include #include #include #include #include #include #include "winecfg.h" #include "resource.h" WINE_DEFAULT_DEBUG_CHANNEL(winecfg); #define BOX_MODE_CD_ASSIGN 1 #define BOX_MODE_CD_AUTODETECT 2 #define BOX_MODE_NONE 3 #define BOX_MODE_NORMAL 4 static BOOL advanced = FALSE; static BOOL updating_ui = FALSE; static struct drive* current_drive; static void get_etched_rect(HWND dialog, RECT *rect); static void set_advanced(HWND dialog) { int state; char *text; RECT rect; /* FIXME: internationalization */ if (advanced) { state = SW_NORMAL; text = "&Hide Advanced"; } else { state = SW_HIDE; text = "&Show Advanced"; } ShowWindow(GetDlgItem(dialog, IDC_RADIO_AUTODETECT), state); ShowWindow(GetDlgItem(dialog, IDC_RADIO_ASSIGN), state); ShowWindow(GetDlgItem(dialog, IDC_EDIT_LABEL), state); ShowWindow(GetDlgItem(dialog, IDC_EDIT_DEVICE), state); ShowWindow(GetDlgItem(dialog, IDC_STATIC_LABEL), state); ShowWindow(GetDlgItem(dialog, IDC_BUTTON_BROWSE_DEVICE), state); ShowWindow(GetDlgItem(dialog, IDC_EDIT_SERIAL), state); ShowWindow(GetDlgItem(dialog, IDC_STATIC_SERIAL), state); ShowWindow(GetDlgItem(dialog, IDC_LABELSERIAL_STATIC), state); /* update the button text based on the state */ SetWindowText(GetDlgItem(dialog, IDC_BUTTON_SHOW_HIDE_ADVANCED), text); /* redraw for the etched line */ get_etched_rect(dialog, &rect); InflateRect(&rect, 5, 5); InvalidateRect(dialog, &rect, TRUE); } struct drive_typemap { const uint sCode; const char *sDesc; }; static struct drive_typemap type_pairs[] = { { DRIVE_FIXED, "Local hard disk" }, { DRIVE_REMOTE, "Network share" }, { DRIVE_REMOVABLE, "Floppy disk" }, { DRIVE_CDROM, "CD-ROM" } }; #define DRIVE_TYPE_DEFAULT 1 void fill_drive_droplist(long mask, char curletter, HWND dialog) { int i; int selection; int count; int next_letter; char sName[4] = "A:"; for (i = 0, count = 0, selection = -1, next_letter = -1; i <= 'Z'-'A'; ++i) { if (mask & DRIVE_MASK_BIT('A' + i)) { int index; sName[0] = 'A' + i; index = SendDlgItemMessage(dialog, IDC_COMBO_LETTER, CB_ADDSTRING, 0, (LPARAM) sName); if (toupper(curletter) == 'A' + i) { selection = count; } if (i >= 2 && next_letter == -1) { /* default drive is first one of C-Z */ next_letter = count; } count++; } } if (selection == -1) { selection = next_letter; } SendDlgItemMessage(dialog, IDC_COMBO_LETTER, CB_SETCURSEL, selection, 0); } void enable_labelserial_box(HWND dialog, int mode) { WINE_TRACE("mode=%d\n", mode); switch (mode) { case BOX_MODE_CD_ASSIGN: enable(IDC_RADIO_ASSIGN); disable(IDC_EDIT_DEVICE); disable(IDC_BUTTON_BROWSE_DEVICE); enable(IDC_EDIT_SERIAL); enable(IDC_EDIT_LABEL); enable(IDC_STATIC_SERIAL); enable(IDC_STATIC_LABEL); break; case BOX_MODE_CD_AUTODETECT: enable(IDC_RADIO_ASSIGN); enable(IDC_EDIT_DEVICE); enable(IDC_BUTTON_BROWSE_DEVICE); disable(IDC_EDIT_SERIAL); disable(IDC_EDIT_LABEL); disable(IDC_STATIC_SERIAL); disable(IDC_STATIC_LABEL); break; case BOX_MODE_NONE: disable(IDC_RADIO_ASSIGN); disable(IDC_EDIT_DEVICE); disable(IDC_BUTTON_BROWSE_DEVICE); disable(IDC_EDIT_SERIAL); disable(IDC_EDIT_LABEL); disable(IDC_STATIC_SERIAL); disable(IDC_STATIC_LABEL); break; case BOX_MODE_NORMAL: enable(IDC_RADIO_ASSIGN); disable(IDC_EDIT_DEVICE); disable(IDC_BUTTON_BROWSE_DEVICE); enable(IDC_EDIT_SERIAL); enable(IDC_EDIT_LABEL); enable(IDC_STATIC_SERIAL); enable(IDC_STATIC_LABEL); break; } } int fill_drives_list(HWND dialog) { int count = 0; BOOL drivec_present = FALSE; int i; int prevsel = -1; WINE_TRACE("\n"); updating_ui = TRUE; prevsel = SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LB_GETCURSEL, 0, 0); /* Clear the listbox */ SendMessage(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_RESETCONTENT, 0, 0); for(i = 0; i < 26; i++) { char *title = 0; int len; int index; /* skip over any unused drives */ if (!drives[i].in_use) continue; if (drives[i].letter == 'C') drivec_present = TRUE; len = snprintf(title, 0, "%c: %s", 'A' + i, drives[i].unixpath); len++; /* add a byte for the trailing null */ title = HeapAlloc(GetProcessHeap(), 0, len); /* the %s in the item label will be replaced by the drive letter, so -1, then -2 for the second %s which will be expanded to the label, finally + 1 for terminating #0 */ snprintf(title, len, "%c: %s", 'A' + i, drives[i].unixpath); WINE_TRACE("title is '%s'\n", title); /* the first SendMessage call adds the string and returns the index, the second associates that index with it */ index = SendMessage(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_ADDSTRING ,(WPARAM) -1, (LPARAM) title); SendMessage(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_SETITEMDATA, index, (LPARAM) &drives[i]); HeapFree(GetProcessHeap(), 0, title); count++; } WINE_TRACE("loaded %d drives\n", count); /* show the warning if there is no Drive C */ if (!drivec_present) ShowWindow(GetDlgItem(dialog, IDS_DRIVE_NO_C), SW_NORMAL); else ShowWindow(GetDlgItem(dialog, IDS_DRIVE_NO_C), SW_HIDE); SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LB_SETCURSEL, prevsel == -1 ? 0 : prevsel, 0); updating_ui = FALSE; return count; } void on_add_click(HWND dialog) { /* we should allocate a drive letter automatically. We also need some way to let the user choose the mapping point, for now we will just force them to enter a path automatically, with / being the default. In future we should be able to temporarily map / then invoke the directory chooser dialog. */ char new = 'C'; /* we skip A and B, they are historically floppy drives */ long mask = ~drive_available_mask(0); /* the mask is now which drives aren't available */ int i, c; while (mask & (1 << (new - 'A'))) { new++; if (new > 'Z') { MessageBox(dialog, "You cannot add any more drives.\n\nEach drive must have a letter, from A to Z, so you cannot have more than 26", "", MB_OK | MB_ICONEXCLAMATION); return; } } WINE_TRACE("allocating drive letter %c\n", new); if (new == 'C') add_drive(new, "../drive_c", "System Drive", "", DRIVE_FIXED); else add_drive(new, "/", "", "", DRIVE_FIXED); fill_drives_list(dialog); /* select the newly created drive */ mask = ~drive_available_mask(0); c = 0; for (i = 0; i < 26; i++) { if ('A' + i == new) break; if ((1 << i) & mask) c++; } SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LB_SETCURSEL, c, 0); SetFocus(GetDlgItem(dialog, IDC_LIST_DRIVES)); } void on_remove_click(HWND dialog) { int item; struct drive *drive; item = SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LB_GETCURSEL, 0, 0); if (item == -1) return; /* no selection */ drive = (struct drive *) SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LB_GETITEMDATA, item, 0); if (drive->letter == 'C') { DWORD result = MessageBox(dialog, "Are you sure you want to delete drive C?\n\nMost Windows applications expect drive C to exist, and will die messily if it doesn't. If you proceed remember to recreate it!", "", MB_YESNO | MB_ICONEXCLAMATION); if (result == IDNO) return; } delete_drive(drive); fill_drives_list(dialog); item = item - 1; if (item < 0) item = 0; SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LB_SETCURSEL, item, 0); /* previous item */ SetFocus(GetDlgItem(dialog, IDC_LIST_DRIVES)); } void update_controls(HWND dialog) { char *path; uint type; char *label; char *serial; char *device; int i, selection = -1; updating_ui = TRUE; i = SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LB_GETCURSEL, 0, 0); if (i == -1) { /* no selection? let's select something for the user. this will re-enter */ SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LB_SETCURSEL, 0, 0); return; } current_drive = (struct drive *) SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LB_GETITEMDATA, i, 0); WINE_TRACE("Updating sheet for drive %c\n", current_drive->letter); /* Drive letters */ fill_drive_droplist(drive_available_mask(current_drive->letter), current_drive->letter, dialog); /* path */ path = current_drive->unixpath; WINE_TRACE("set path control text to '%s'\n", path); set_text(dialog, IDC_EDIT_PATH, path); /* drive type */ type = current_drive->type; if (type) { for (i = 0; i < sizeof(type_pairs) / sizeof(struct drive_typemap); i++) { SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_ADDSTRING, 0, (LPARAM) type_pairs[i].sDesc); if (type_pairs[i].sCode == type) { selection = i; } } if (selection == -1) selection = DRIVE_TYPE_DEFAULT; SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_SETCURSEL, selection, 0); } else WINE_WARN("no Type field?\n"); /* removeable media properties */ label = current_drive->label; set_text(dialog, IDC_EDIT_LABEL, label); /* set serial edit text */ serial = current_drive->serial; set_text(dialog, IDC_EDIT_SERIAL, serial); /* TODO: get the device here to put into the edit box */ device = "Not implemented yet"; set_text(dialog, IDC_EDIT_DEVICE, device); device = NULL; selection = IDC_RADIO_ASSIGN; if ((type == DRIVE_CDROM) || (type == DRIVE_REMOVABLE)) { if (device) { selection = IDC_RADIO_AUTODETECT; enable_labelserial_box(dialog, BOX_MODE_CD_AUTODETECT); } else { selection = IDC_RADIO_ASSIGN; enable_labelserial_box(dialog, BOX_MODE_CD_ASSIGN); } } else { enable_labelserial_box(dialog, BOX_MODE_NORMAL); selection = IDC_RADIO_ASSIGN; } CheckRadioButton(dialog, IDC_RADIO_AUTODETECT, IDC_RADIO_ASSIGN, selection); updating_ui = FALSE; return; } void on_edit_changed(HWND dialog, WORD id) { if (updating_ui) return; WINE_TRACE("edit id %d changed\n", id); /* using fill_drives_list here is pretty lazy, but i'm tired fortunately there are only 26 letters in the alphabet, so we don't have to worry about efficiency too much here :) */ switch (id) { case IDC_EDIT_LABEL: { char *label; label = get_text(dialog, id); if (current_drive->label) HeapFree(GetProcessHeap(), 0, current_drive->label); current_drive->label = label ? label : strdupA(""); WINE_TRACE("set label to %s\n", current_drive->label); fill_drives_list(dialog); break; } case IDC_EDIT_PATH: { char *path; path = get_text(dialog, id); if (current_drive->unixpath) HeapFree(GetProcessHeap(), 0, current_drive->unixpath); current_drive->unixpath = path ? path : strdupA("drive_c"); WINE_TRACE("set path to %s\n", current_drive->unixpath); fill_drives_list(dialog); break; } case IDC_EDIT_SERIAL: { char *serial; serial = get_text(dialog, id); if (current_drive->serial) HeapFree(GetProcessHeap(), 0, current_drive->serial); current_drive->serial = serial ? serial : strdupA(""); WINE_TRACE("set serial to %s", current_drive->serial); break; } case IDC_EDIT_DEVICE: { char *device = get_text(dialog, id); /* TODO: handle device if/when it makes sense to do so.... */ if (device) HeapFree(GetProcessHeap(), 0, device); fill_drives_list(dialog); break; } } } static void get_etched_rect(HWND dialog, RECT *rect) { GetClientRect(dialog, rect); /* these dimensions from the labelserial static in En.rc */ rect->top = 258; rect->bottom = 258; rect->left += 35; rect->right -= 25; } /* this just draws a nice line to separate the advanced gui from the n00b gui :) */ static void paint(HWND dialog) { PAINTSTRUCT ps; BeginPaint(dialog, &ps); if (advanced) { RECT rect; get_etched_rect(dialog, &rect); DrawEdge(ps.hdc, &rect, EDGE_ETCHED, BF_TOP); } EndPaint(dialog, &ps); } INT_PTR CALLBACK DriveDlgProc (HWND dialog, UINT msg, WPARAM wParam, LPARAM lParam) { int item; struct drive *drive; switch (msg) { case WM_INITDIALOG: load_drives(); if (!drives[2].in_use) MessageBox(dialog, "You don't have a drive C. This is not so great.\n\nRemember to click 'Add' in the Drives tab to create one!\n", "", MB_OK | MB_ICONEXCLAMATION); fill_drives_list(dialog); update_controls(dialog); /* put in non-advanced mode by default */ set_advanced(dialog); break; case WM_SHOWWINDOW: set_window_title(dialog); break; case WM_PAINT: paint(dialog); break; case WM_COMMAND: if (HIWORD(wParam) == EN_CHANGE) { on_edit_changed(dialog, LOWORD(wParam)); break; } switch (LOWORD(wParam)) { case IDC_LIST_DRIVES: if (HIWORD(wParam) == LBN_SELCHANGE) update_controls(dialog); break; case IDC_BUTTON_ADD: if (HIWORD(wParam) != BN_CLICKED) break; on_add_click(dialog); break; case IDC_BUTTON_REMOVE: if (HIWORD(wParam) != BN_CLICKED) break; on_remove_click(dialog); break; case IDC_BUTTON_EDIT: if (HIWORD(wParam) != BN_CLICKED) break; item = SendMessage(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_GETCURSEL, 0, 0); drive = (struct drive *) SendMessage(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_GETITEMDATA, item, 0); /*DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DRIVE_EDIT), NULL, (DLGPROC) DriveEditDlgProc, (LPARAM) drive); */ break; case IDC_BUTTON_AUTODETECT: autodetect_drives(); fill_drives_list(dialog); break; case IDC_BUTTON_SHOW_HIDE_ADVANCED: advanced = !advanced; set_advanced(dialog); break; case IDC_BUTTON_BROWSE_PATH: MessageBox(dialog, "", "Write me!", MB_OK); break; case IDC_RADIO_ASSIGN: { char *str; str = get_text(dialog, IDC_EDIT_LABEL); if (current_drive->label) HeapFree(GetProcessHeap(), 0, current_drive->label); current_drive->label = str ? str : strdupA(""); str = get_text(dialog, IDC_EDIT_SERIAL); if (current_drive->serial) HeapFree(GetProcessHeap(), 0, current_drive->serial); current_drive->serial = str ? str : strdupA(""); /* TODO: we don't have a device at this point */ enable_labelserial_box(dialog, BOX_MODE_CD_ASSIGN); break; } case IDC_COMBO_TYPE: { int mode = BOX_MODE_NORMAL; int selection; if (HIWORD(wParam) != CBN_SELCHANGE) break; selection = SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_GETCURSEL, 0, 0); if (selection == 2 || selection == 3) /* cdrom or floppy */ { if (IsDlgButtonChecked(dialog, IDC_RADIO_AUTODETECT)) mode = BOX_MODE_CD_AUTODETECT; else mode = BOX_MODE_CD_ASSIGN; } enable_labelserial_box(dialog, mode); current_drive->type = type_pairs[selection].sCode; break; } } break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { case PSN_KILLACTIVE: WINE_TRACE("PSN_KILLACTIVE\n"); SetWindowLong(dialog, DWL_MSGRESULT, FALSE); break; case PSN_APPLY: apply_drive_changes(); SetWindowLong(dialog, DWL_MSGRESULT, PSNRET_NOERROR); break; case PSN_SETACTIVE: break; } break; } return FALSE; } #define IDC_LABELSERIAL_STATIC 1078 #define IDC_DRIVE_LABEL 1078 * TODO: * - Use unicode * - Icons in listviews/icons * - Better add app dialog, scan c: for EXE files and add to list in background * - Use [GNOME] HIG style groupboxes rather than win32 style (looks nicer, imho) * if (current_app) newtitle = HeapAlloc(GetProcessHeap(), 0, strlen(template) + strlen(current_app) + 1); sprintf(newtitle, template, current_app); * getkey: Retrieves a configuration value from the registry static char *getkey (char *subkey, char *name, char *def) * setkey: convenience wrapper to set a key/value pair int setkey(const char *subkey, const char *name, const char *value) { val = getkey(path, name, def); setkey(s->path, s->name, s->value); char *current_app = NULL; /* the app we are currently editing, or NULL if editing global */ if (current_app) result = HeapAlloc(GetProcessHeap(), 0, strlen("AppDefaults\\") + strlen(current_app) + 2 /* \\ */ + strlen(section) + 1 /* terminator */); sprintf(result, "AppDefaults\\%s\\%s", current_app, section); /* eliminate trailing newline, is this a Wine bug? */ *(strrchr(msg, '\n')) = '\0'; extern char *current_app; /* NULL means editing global settings */ the user is editing the global settings. no explicit free is needed of the string returned by this function /* hack for the property sheet control */ /* Window procedures */ /* Drive management */ void load_drives(); int autodetect_drives(); struct drive { char letter; char *unixpath; char *label; char *serial; DWORD type; /* one of the DRIVE_ constants from winbase.h */ BOOL in_use; }; #define DRIVE_MASK_BIT(B) 1 << (toupper(B) - 'A') long drive_available_mask(char letter); BOOL add_drive(char letter, char *targetpath, char *label, char *serial, unsigned int type); void delete_drive(struct drive *pDrive); void apply_drive_changes(); extern struct drive drives[26]; /* one for each drive letter */ BOOL gui_mode; /* Some basic utilities to make win32 suck less */ static inline char *get_text(HWND dialog, WORD id) char *result = len ? HeapAlloc(GetProcessHeap(), 0, len) : NULL; if (!result || GetWindowText(item, result, len) == 0) return NULL; static inline void set_text(HWND dialog, WORD id, char *text) { SetWindowText(GetDlgItem(dialog, id), text); } #define WINE_KEY_ROOT "Software\\Wine\\Testing\\Config" width = get_text(dialog, IDC_DESKTOP_WIDTH); height = get_text(dialog, IDC_DESKTOP_HEIGHT); char *newvalue = get_text(dialog, IDC_SCREEN_DEPTH); TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo, (int)lcid, ppTInfo); BSTR name; BOOL freename; if (V_VT(&pDispParams->rgvarg[0]) == VT_DISPATCH) { IFont *font; HRESULT hr = S_OK; hr = IUnknown_QueryInterface(V_DISPATCH(&pDispParams->rgvarg[0]), &IID_IFont, (void **) &font); if (FAILED(hr)) { FIXME("dispatch value for name property is not an OleFont, returning hr=0x%lx\n", hr); return hr; } hr = IFont_get_Name(font, &name); /* this allocates a new BSTR so free it later */ if (FAILED(hr)) return hr; IUnknown_Release(font); freename = TRUE; } else if (V_VT(&pDispParams->rgvarg[0]) == VT_BSTR) { name = V_BSTR(&pDispParams->rgvarg[0]); freename = FALSE; } else { FIXME("app is trying to set name property with a non BSTR, non dispatch value. returning E_FAIL\n"); return E_FAIL; TRACE("name is %s\n", debugstr_w(name)); if (freename) SysFreeString(name); winver = get(keypath("Version"), "Windows", ""); dosver = get(keypath("Version"), "DOS", ""); /* empty winver/dosver means use automatic mode (ie the builtin dll linkage heuristics) */ WINE_TRACE("winver is %s\n", *winver != '\0' ? winver : "null (automatic mode)"); WINE_TRACE("dosver is %s\n", *dosver != '\0' ? dosver : "null (automatic mode)"); if (*winver != '\0') if (*dosver != '\0') HeapFree(GetProcessHeap(), 0, winver); HeapFree(GetProcessHeap(), 0, dosver); /* Called when the application is initialized (cannot reinit!) */ /* because this list is only populated once, it's safe to bypass the settings list here */ if (RegOpenKey(config_key, "AppDefaults", &key) == ERROR_SUCCESS) while (RegEnumKeyEx(key, i, appname, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) set_window_title(dialog); char *section = keypath(""); /* AppDefaults\\whatever.exe\\ */ set(section, NULL, NULL); /* delete the section */ set(keypath("Version"), "Windows", NULL); set(keypath("Version"), "Windows", ver[selection - 1].szVersion); /* enable the apply button */ SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0); set(keypath("Version"), "DOS", NULL); set(keypath("Version"), "DOS", ver[selection - 1].szVersion); /* enable the apply button */ SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0); init_appsheet(hDlg); break; case WM_SHOWWINDOW: set_window_title(hDlg); break; on_selection_change(hDlg, GetDlgItem(hDlg, IDC_APP_LISTVIEW)); break; case PSN_APPLY: apply(); SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR); break; set("Winmm", "Drivers", (char *) pAudioDrv->szDriver); SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */ char *curAudioDriver = get("Winmm", "Drivers", "winealsa.drv"); case WM_SHOWWINDOW: set_window_title(hDlg); break; apply(); if (currentApp) { case WM_SHOWWINDOW: set_window_title(hDlg); break; * Copyright 2004 Mike Hearn #include enum dllmode UNKNOWN /* Special value indicating an erronous DLL override mode */ }; struct dll { char *name; enum dllmode mode; }; static enum dllmode parse_override(char *in) int i, j; char *out; out = HeapAlloc(GetProcessHeap(), 0, strlen(in)); /* remove the spaces */ j = 0; for (i = 0; i < strlen(in); i++) if (in[i] != ' ') { out[j] = in[i]; j++; } out[j] = 0; /* parse the string */ if (strcmp(out, "builtin,native") == 0) return BUILTIN_NATIVE; else if (strcmp(out, "native,builtin") == 0) return NATIVE_BUILTIN; else if (strcmp(out, "native") == 0) return NATIVE; else if (strcmp(out, "builtin") == 0) return BUILTIN; else if (strcmp(out, "") == 0) return DISABLE; /* this is used to convert a dllmode to a human readable string. we should read from the translations here */ static char* mode_to_label(enum dllmode mode) char* res; switch (mode) { case NATIVE: res = "native"; break; case BUILTIN: res = "builtin"; break; case NATIVE_BUILTIN: res = "native, builtin"; break; case BUILTIN_NATIVE: res = "builtin, native"; break; case DISABLE: res = "disabled"; break; default: res = "unknown/invalid"; break; } return res; static void set_controls_from_selection(HWND dialog) int index = SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETCURSEL, 0, 0); struct dll *dll; DWORD id; int i; if (index == -1) /* no selection */ { for (i = IDC_RAD_BUILTIN; i <= IDC_RAD_DISABLE; i++) disable(i); CheckRadioButton(dialog, IDC_RAD_BUILTIN, IDC_RAD_DISABLE, -1); return; } /* enable the controls */ for (i = IDC_RAD_BUILTIN; i <= IDC_RAD_DISABLE; i++) enable(i); dll = (struct dll *) SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETITEMDATA, index, 0); switch (dll->mode) { case NATIVE: id = IDC_RAD_NATIVE; break; case BUILTIN: id = IDC_RAD_BUILTIN; break; case NATIVE_BUILTIN: id = IDC_RAD_NATIVE_BUILTIN; break; case BUILTIN_NATIVE: id = IDC_RAD_BUILTIN_NATIVE; break; case DISABLE: id = IDC_RAD_DISABLE; break; case UNKNOWN: default: id = -1; break; } CheckRadioButton(dialog, IDC_RAD_BUILTIN, IDC_RAD_DISABLE, id); static void clear_settings(HWND dialog) int count = SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETCOUNT, 0, 0); int i; WINE_TRACE("count=%d\n", count); for (i = 0; i < count; i++) { struct dll *dll = (struct dll *) SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETITEMDATA, 0, 0); SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_DELETESTRING, 0, 0); HeapFree(GetProcessHeap(), 0, dll->name); HeapFree(GetProcessHeap(), 0, dll); } static void load_library_settings(HWND dialog) char **overrides = enumerate_values(keypath("DllOverrides")); char **p; int sel, count = 0; sel = SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETCURSEL, 0, 0); WINE_TRACE("sel=%d\n", sel); clear_settings(dialog); if (!overrides || *overrides == NULL) { set_controls_from_selection(dialog); disable(IDC_DLLS_REMOVEDLL); HeapFree(GetProcessHeap(), 0, overrides); return; } enable(IDC_DLLS_REMOVEDLL); for (p = overrides; *p != NULL; p++) { int index; char *str, *value, *label; struct dll *dll; value = get(keypath("DllOverrides"), *p, NULL); label = mode_to_label(parse_override(value)); str = HeapAlloc(GetProcessHeap(), 0, strlen(*p) + 2 + strlen(label) + 2); strcpy(str, *p); strcat(str, " ("); strcat(str, label); strcat(str, ")"); dll = HeapAlloc(GetProcessHeap(), 0, sizeof(struct dll)); dll->name = *p; dll->mode = parse_override(value); index = SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_ADDSTRING, (WPARAM) -1, (LPARAM) str); SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_SETITEMDATA, index, (LPARAM) dll); HeapFree(GetProcessHeap(), 0, str); count++; } HeapFree(GetProcessHeap(), 0, overrides); /* restore the previous selection, if possible */ if (sel >= count - 1) sel = count - 1; else if (sel == -1) sel = 0; SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_SETCURSEL, sel, 0); set_controls_from_selection(dialog); /* Called when the application is initialized (cannot reinit!) */ static void init_libsheet(HWND dialog) /* clear the add dll controls */ SendDlgItemMessage(dialog, IDC_DLLCOMBO, WM_SETTEXT, 1, (LPARAM) ""); disable(IDC_DLLS_ADDDLL); static void on_add_combo_change(HWND dialog) char buffer[1024]; SendDlgItemMessage(dialog, IDC_DLLCOMBO, WM_GETTEXT, sizeof(buffer), (LPARAM) buffer); if (strlen(buffer)) enable(IDC_DLLS_ADDDLL) else disable(IDC_DLLS_ADDDLL); static void set_dllmode(HWND dialog, DWORD id) enum dllmode mode; struct dll *dll; int sel; char *str; #define CONVERT(s) case IDC_RAD_##s: mode = s; break; switch (id) { CONVERT( BUILTIN ); CONVERT( NATIVE ); CONVERT( BUILTIN_NATIVE ); CONVERT( NATIVE_BUILTIN ); CONVERT( DISABLE ); default: assert( FALSE ); /* should not be reached */ } #undef CONVERT sel = SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETCURSEL, 0, 0); if (sel == -1) return; dll = (struct dll *) SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETITEMDATA, sel, 0); switch (mode) { case BUILTIN: str = "builtin"; break; case NATIVE: str = "native"; break; case BUILTIN_NATIVE: str = "builtin, native"; break; case NATIVE_BUILTIN: str = "native, builtin"; break; case DISABLE: str = ""; break; default: assert( FALSE ); /* unreachable */ } WINE_TRACE("Setting %s to %s\n", dll->name, str); set(keypath("DllOverrides"), dll->name, str); load_library_settings(dialog); /* ... and refresh */ static void on_add_click(HWND dialog) char buffer[1024]; ZeroMemory(buffer, sizeof(buffer)); SendDlgItemMessage(dialog, IDC_DLLCOMBO, WM_GETTEXT, sizeof(buffer), (LPARAM) buffer); SendDlgItemMessage(dialog, IDC_DLLCOMBO, WM_SETTEXT, 0, (LPARAM) ""); disable(IDC_DLLS_ADDDLL); WINE_TRACE("Adding %s as native, builtin", buffer); set(keypath("DllOverrides"), buffer, "native,builtin"); load_library_settings(dialog); SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_SELECTSTRING, (WPARAM) 0, (LPARAM) buffer); set_controls_from_selection(dialog); static void on_remove_click(HWND dialog) int sel = SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETCURSEL, 0, 0); struct dll *dll; if (sel == LB_ERR) return; dll = (struct dll *) SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETITEMDATA, sel, 0); SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_DELETESTRING, sel, 0); set(keypath("DllOverrides"), dll->name, NULL); HeapFree(GetProcessHeap(), 0, dll->name); HeapFree(GetProcessHeap(), 0, dll); if (SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETCOUNT, 0, 0) > 0) SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_SETCURSEL, max(sel - 1, 0), 0); else disable(IDC_DLLS_REMOVEDLL); set_controls_from_selection(dialog); init_libsheet(hDlg); break; case WM_SHOWWINDOW: set_window_title(hDlg); break; case PSN_SETACTIVE: load_library_settings(hDlg); break; /* FIXME: when the user hits enter in the DLL combo box we should invoke the add * add button, rather than the propsheet OK button. But I don't know how to do that! */ case CBN_EDITCHANGE: if(LOWORD(wParam) == IDC_DLLCOMBO) { on_add_combo_change(hDlg); break; } set_dllmode(hDlg, LOWORD(wParam)); break; on_add_click(hDlg); break; on_remove_click(hDlg); break; case LBN_SELCHANGE: set_controls_from_selection(hDlg); break; /* dll editing */ #define IDC_DLLS_LIST 1034 #define IDC_DLLCOMBO 8004 #include HKEY config_key = NULL; /* this is called from the WM_SHOWWINDOW handlers of each tab page. * * it's a nasty hack, necessary because the property sheet insists on resetting the window title * to the title of the tab, which is utterly useless. dropping the property sheet is on the todo list. */ void set_window_title(HWND dialog) { char *newtitle; /* update the window title */ if (currentApp) { char *template = "Wine Configuration for %s"; newtitle = HeapAlloc(GetProcessHeap(), 0, strlen(template) + strlen(currentApp) + 1); sprintf(newtitle, template, currentApp); else { newtitle = strdupA("Wine Configuration"); } WINE_TRACE("setting title to %s\n", newtitle); SendMessage(GetParent(dialog), PSM_SETTITLE, 0, (LPARAM) newtitle); HeapFree(GetProcessHeap(), 0, newtitle); /** * getkey: Retrieves a configuration value from the registry * char *subkey : the name of the config section * char *name : the name of the config value * char *default : if the key isn't found, return this value instead * Returns a buffer holding the value if successful, NULL if * not. Caller is responsible for releasing the result. static char *getkey (char *subkey, char *name, char *def) LPBYTE buffer = NULL; DWORD len; WINE_TRACE("subkey=%s, name=%s, def=%s\n", subkey, name, def); res = RegOpenKeyEx(config_key, subkey, 0, KEY_READ, &hSubKey); if (res != ERROR_SUCCESS) { if (res == ERROR_FILE_NOT_FOUND) return def ? strdupA(def) : NULL; res = RegQueryValueExA(hSubKey, name, NULL, NULL, NULL, &len); if (res == ERROR_FILE_NOT_FOUND) { buffer = def ? strdupA(def) : NULL; } else if (res != ERROR_SUCCESS) WINE_ERR("Couldn't query value's length (res=%ld)\n", res); buffer = HeapAlloc(GetProcessHeap(), 0, len + 1); RegQueryValueEx(hSubKey, name, NULL, NULL, buffer, &len); WINE_TRACE("buffer=%s\n", buffer); if (hSubKey) RegCloseKey(hSubKey); /** * setkey: convenience wrapper to set a key/value pair * * If valueName or value is NULL, an empty section will be created int setkey(const char *subkey, const char *name, const char *value) { WINE_TRACE("subkey=%s: name=%s, value=%s\n", subkey, name, value); res = RegCreateKey(config_key, subkey, &key); if (name == NULL || value == NULL) goto end; res = RegSetValueEx(key, name, 0, REG_SZ, value, strlen(value) + 1); if (res != 0) WINE_ERR("Unable to set configuration key %s in section %s to %s, res=%ld\n", name, subkey, value, res); /* removes the requested value from the registry, however, does not * remove the section if empty. Returns S_OK (0) on success. */ static HRESULT remove_value(const char *subkey, const char *name) { WINE_TRACE("subkey=%s, name=%s\n", subkey, name); hr = RegOpenKeyEx(config_key, subkey, 0, KEY_READ, &key); hr = RegDeleteValue(key, name); /* removes the requested subkey from the registry, assuming it exists */ static HRESULT remove_path(char *section) { return RegDeleteKey(config_key, section); /* This code exists for the following reasons: * * - It makes working with the registry easier * - By storing a mini cache of the registry, we can more easily implement * cancel/revert and apply. The 'settings list' is an overlay on top of * the actual registry data that we can write out at will. * * Rather than model a tree in memory, we simply store each absolute (rooted * at the config key) path. * */ struct setting { struct list entry; char *path; /* path in the registry rooted at the config key */ char *name; /* name of the registry value */ char *value; /* contents of the registry value. if null, this means a deletion */ }; struct list *settings; static void free_setting(struct setting *setting) { assert( setting != NULL ); WINE_TRACE("destroying %p\n", setting); assert( setting->path && setting->name ); HeapFree(GetProcessHeap(), 0, setting->path); HeapFree(GetProcessHeap(), 0, setting->name); if (setting->value) HeapFree(GetProcessHeap(), 0, setting->value); list_remove(&setting->entry); HeapFree(GetProcessHeap(), 0, setting); } /** * Returns the contents of the value at path. If not in the settings * list, it will be fetched from the registry - failing that, the * default will be used. * * If already in the list, the contents as given there will be * returned. You are expected to HeapFree the result. */ char *get(char *path, char *name, char *def) { struct list *cursor; struct setting *s; char *val; WINE_TRACE("path=%s, name=%s, def=%s\n", path, name, def); /* check if it's in the list */ LIST_FOR_EACH( cursor, settings ) { s = LIST_ENTRY(cursor, struct setting, entry); if (strcasecmp(path, s->path) != 0) continue; if (strcasecmp(name, s->name) != 0) continue; WINE_TRACE("found %s:%s in settings list, returning %s\n", path, name, s->value); return strdupA(s->value); } /* no, so get from the registry */ val = getkey(path, name, def); WINE_TRACE("returning %s\n", val); return val; } /** * Used to set a registry key. * * path is rooted at the config key, ie use "Version" or * "AppDefaults\\fooapp.exe\\Version". You can use keypath() * to get such a string. * * name is the value name, it must not be null (you cannot create * empty groups, sorry ...) * * value is what to set the value to, or NULL to delete it. * * These values will be copied when necessary. */ void set(char *path, char *name, char *value) { struct list *cursor; struct setting *s; assert( path != NULL ); assert( name != NULL ); WINE_TRACE("path=%s, name=%s, value=%s\n", path, name, value); /* firstly, see if we already set this setting */ LIST_FOR_EACH( cursor, settings ) { struct setting *s = LIST_ENTRY(cursor, struct setting, entry); if (strcasecmp(s->path, path) != 0) continue; if (strcasecmp(s->name, name) != 0) continue; /* yes, we have already set it, so just replace the content and return */ if (s->value) HeapFree(GetProcessHeap(), 0, s->value); s->value = value ? strdupA(value) : NULL; return; } /* otherwise add a new setting for it */ s = HeapAlloc(GetProcessHeap(), 0, sizeof(struct setting)); s->path = strdupA(path); s->name = strdupA(name); s->value = value ? strdupA(value) : NULL; list_add_tail(settings, &s->entry); /** * enumerates the value names at the given path, taking into account * the changes in the settings list. * * you are expected to HeapFree each element of the array, which is null * terminated, as well as the array itself. */ char **enumerate_values(char *path) { HKEY key; DWORD res, i = 0; char **values = NULL; int valueslen = 0; struct list *cursor; res = RegOpenKeyEx(config_key, path, 0, KEY_READ, &key); if (res == ERROR_SUCCESS) { while (TRUE) { char name[1024]; DWORD namesize = sizeof(name); BOOL removed = FALSE; /* find out the needed size, allocate a buffer, read the value */ if ((res = RegEnumValue(key, i, name, &namesize, NULL, NULL, NULL, NULL)) != ERROR_SUCCESS) break; WINE_TRACE("name=%s\n", name); /* check if this value name has been removed in the settings list */ LIST_FOR_EACH( cursor, settings ) { struct setting *s = LIST_ENTRY(cursor, struct setting, entry); if (strcasecmp(s->path, path) != 0) continue; if (strcasecmp(s->name, name) != 0) continue; if (!s->value) { WINE_TRACE("this key has been removed, so skipping\n"); removed = TRUE; break; } } if (removed) /* this value was deleted by the user, so don't include it */ { HeapFree(GetProcessHeap(), 0, name); i++; continue; } /* grow the array if necessary, add buffer to it, iterate */ if (values) values = HeapReAlloc(GetProcessHeap(), 0, values, sizeof(char*) * (valueslen + 1)); else values = HeapAlloc(GetProcessHeap(), 0, sizeof(char*)); values[valueslen++] = strdupA(name); WINE_TRACE("valueslen is now %d\n", valueslen); i++; } } else { WINE_WARN("failed opening registry key %s, res=0x%lx\n", path, res); } WINE_TRACE("adding settings in list but not registry\n"); /* now we have to add the values that aren't in the registry but are in the settings list */ LIST_FOR_EACH( cursor, settings ) { struct setting *setting = LIST_ENTRY(cursor, struct setting, entry); BOOL found = FALSE; if (strcasecmp(setting->path, path) != 0) continue; if (!setting->value) continue; for (i = 0; i < valueslen; i++) { if (strcasecmp(setting->name, values[i]) == 0) { found = TRUE; break; } } if (found) continue; WINE_TRACE("%s in list but not registry\n", setting->name); /* otherwise it's been set by the user but isn't in the registry */ if (values) values = HeapReAlloc(GetProcessHeap(), 0, values, sizeof(char*) * (valueslen + 1)); else values = HeapAlloc(GetProcessHeap(), 0, sizeof(char*)); values[valueslen++] = strdupA(setting->name); WINE_TRACE("adding null terminator\n"); if (values) { values = HeapReAlloc(GetProcessHeap(), 0, values, sizeof(char*) * (valueslen + 1)); values[valueslen] = NULL; RegCloseKey(key); return values; /** * returns true if the given key/value pair exists in the registry or * has been written to. */ BOOL exists(char *path, char *name) { char *val = get(path, name, NULL); if (val) { HeapFree(GetProcessHeap(), 0, val); return TRUE; return FALSE; static void process_setting(struct setting *s) if (s->value) { WINE_TRACE("Setting %s:%s to '%s'\n", s->path, s->name, s->value); setkey(s->path, s->name, s->value); } else { /* NULL name means remove that path/section entirely */ if (s->path && s->name) remove_value(s->path, s->name); else if (s->path && !s->name) remove_path(s->path); } } void apply(void) { if (list_empty(settings)) return; /* we will be called for each page when the user clicks OK */ WINE_TRACE("()\n"); while (!list_empty(settings)) { struct setting *s = (struct setting *) list_head(settings); process_setting(s); free_setting(s); if (result) HeapFree(GetProcessHeap(), 0, result); result = HeapAlloc(GetProcessHeap(), 0, strlen("AppDefaults\\") + strlen(currentApp) + 2 /* \\ */ + strlen(section) + 1 /* terminator */); int initialize(void) { DWORD res = RegCreateKey(HKEY_LOCAL_MACHINE, WINE_KEY_ROOT, &config_key); if (res != ERROR_SUCCESS) { WINE_ERR("RegOpenKey failed on wine config key (%ld)\n", res); return 1; } /* we could probably just have the list as static data */ settings = HeapAlloc(GetProcessHeap(), 0, sizeof(struct list)); list_init(settings); return 0; } extern char *currentApp; /* NULL means editing global settings */ /* Use get and set to alter registry settings. The changes made through set won't be committed to the registry until process_all_settings is called, however get will still return accurate information. You are expected to release the result of get. The parameters to set will be copied, so release them too when necessary. */ void set(char *path, char *name, char *value); char *get(char *path, char *name, char *def); BOOL exists(char *path, char *name); void apply(void); char **enumerate_values(char *path); extern HKEY config_key; void set_window_title(HWND dialog); char *r = HeapAlloc(GetProcessHeap(), 0, strlen(s)); int updating_ui; void update_gui_for_desktop_mode(HWND dialog) { updating_ui = TRUE; if (exists(keypath("x11drv"), "Desktop")) { else { updating_ui = FALSE; static char *default_desktop = "640x480"; update_gui_for_desktop_mode(hDlg); updating_ui = TRUE; buf = get(keypath("x11drv"), "Desktop", default_desktop); HeapFree(GetProcessHeap(), 0, buf); buf = get(keypath("x11drv"), "ScreenDepth", "24"); HeapFree(GetProcessHeap(), 0, buf); buf = get(keypath("x11drv"), "DXGrab", "Y"); HeapFree(GetProcessHeap(), 0, buf); buf = get(keypath("x11drv"), "DesktopDoubleBuffered", "Y"); HeapFree(GetProcessHeap(), 0, buf); updating_ui = FALSE; char *width = HeapAlloc(GetProcessHeap(), 0, RES_MAXLEN+1); char *height = HeapAlloc(GetProcessHeap(), 0, RES_MAXLEN+1); char *new = HeapAlloc(GetProcessHeap(), 0, (RES_MAXLEN*2) + 2); if (updating_ui) goto end; sprintf(new, "%sx%s", width, height); set(keypath("x11drv"), "Desktop", new); end: HeapFree(GetProcessHeap(), 0, width); HeapFree(GetProcessHeap(), 0, height); HeapFree(GetProcessHeap(), 0, new); set(keypath("x11drv"), "Desktop", NULL); update_gui_for_desktop_mode(hDlg); if (updating_ui) return; set(keypath("x11drv"), "ScreenDepth", newvalue); set(keypath("x11drv"), "DXGrab", "Y"); set(keypath("x11drv"), "DXGrab", "N"); set(keypath("x11drv"), "DesktopDoubleBuffered", "Y"); set(keypath("x11drv"), "DesktopDoubleBuffered", "N"); case WM_SHOWWINDOW: set_window_title(hDlg); break; if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updating_ui ) if (updating_ui) break; apply(); * Copyright 2004 Chris Morgan * Copyright 2004 Mike Hearn #include static void update_comboboxes(HWND dialog) char *winver, *dosver; /* retrieve the registry values */ winver = getConfigValue(keypath("Version"), "Windows", NULL); dosver = getConfigValue(keypath("Version"), "DOS", NULL); /* NULL winver/dosver means use automatic mode (ie the builtin dll linkage heuristics) */ WINE_TRACE("winver is %s\n", winver ? winver : "null (automatic mode)"); WINE_TRACE("dosver is %s\n", dosver ? dosver : "null (automatic mode)"); if (winver && strlen(winver)) if (!strcasecmp (pVer->szVersion, winver)) SendDlgItemMessage (dialog, IDC_WINVER, CB_SETCURSEL, (WPARAM) (i + 1), 0); } else /* no explicit setting */ WINE_TRACE("setting winver combobox to automatic/default\n"); SendDlgItemMessage (dialog, IDC_WINVER, CB_SETCURSEL, 0, 0); if (dosver && strlen(dosver)) if (!strcasecmp (pVer->szVersion, dosver)) SendDlgItemMessage (dialog, IDC_DOSVER, CB_SETCURSEL, (WPARAM) (i + 1), 0); } else WINE_TRACE("setting dosver combobox to automatic/default\n"); SendDlgItemMessage (dialog, IDC_DOSVER, CB_SETCURSEL, 0, 0); if (winver) free(winver); if (dosver) free(dosver); init_comboboxes (HWND dialog) const VERSION_DESC *ver = NULL; SendDlgItemMessage(dialog, IDC_WINVER, CB_RESETCONTENT, 0, 0); SendDlgItemMessage(dialog, IDC_DOSVER, CB_RESETCONTENT, 0, 0); /* add the default entries (automatic) which correspond to no setting */ if (currentApp) { SendDlgItemMessage(dialog, IDC_WINVER, CB_ADDSTRING, 0, (LPARAM) "Use global settings"); SendDlgItemMessage(dialog, IDC_DOSVER, CB_ADDSTRING, 0, (LPARAM) "Use global settings"); } else { SendDlgItemMessage(dialog, IDC_WINVER, CB_ADDSTRING, 0, (LPARAM) "Automatically detect required version"); SendDlgItemMessage(dialog, IDC_DOSVER, CB_ADDSTRING, 0, (LPARAM) "Automatically detect required version"); } if ((ver = getWinVersions ())) for (i = 0; *ver->szVersion || *ver->szDescription; i++, ver++) SendDlgItemMessage (dialog, IDC_WINVER, CB_ADDSTRING, 0, (LPARAM) ver->szDescription); if ((ver = getDOSVersions ())) for (i = 0; *ver->szVersion || *ver->szDescription ; i++, ver++) SendDlgItemMessage (dialog, IDC_DOSVER, CB_ADDSTRING, 0, (LPARAM) ver->szDescription); static void add_listview_item(HWND listview, char *text, void *association) { LVITEM item; ZeroMemory(&item, sizeof(LVITEM)); item.mask = LVIF_TEXT | LVIF_PARAM; item.pszText = text; item.cchTextMax = strlen(text); item.lParam = (LPARAM) association; item.iItem = ListView_GetItemCount(listview); ListView_InsertItem(listview, &item); } static void init_appsheet(HWND dialog) HWND listview; HKEY key; char appname[1024]; WINE_TRACE("()\n"); listview = GetDlgItem(dialog, IDC_APP_LISTVIEW); /* we use the lparam field of the item so we can alter the presentation later and not change code * for instance, to use the tile view or to display the EXEs embedded 'display name' */ add_listview_item(listview, "Default Settings", NULL); /* do the application specific stuff, then add the default item last */ if (RegOpenKey(configKey, "AppDefaults", &key) == ERROR_SUCCESS) i = 0; size = sizeof(appname); while (RegEnumKeyEx(key, i, appname, &size, NULL, NULL, NULL, &ft) == ERROR_SUCCESS) { add_listview_item(listview, appname, strdup(appname)); i++; size = sizeof(appname); } RegCloseKey(key); } init_comboboxes(dialog); /* Select the default settings listview item */ { LVITEM item; ZeroMemory(&item, sizeof(item)); item.mask = LVIF_STATE; item.iItem = 0; item.state = LVIS_SELECTED | LVIS_FOCUSED; item.stateMask = LVIS_SELECTED | LVIS_FOCUSED; ListView_SetItem(listview, &item); /* there has to be an easier way than this */ static int get_listview_selection(HWND listview) int count = ListView_GetItemCount(listview); int i; for (i = 0; i < count; i++) if (ListView_GetItemState(listview, i, LVIS_SELECTED)) return i; return -1; /* called when the user selects a different application */ static void on_selection_change(HWND dialog, HWND listview) LVITEM item; char *oldapp = currentApp; WINE_TRACE("()\n"); item.iItem = get_listview_selection(listview); item.mask = LVIF_PARAM; if (item.iItem == -1) return; ListView_GetItem(listview, &item); currentApp = (char *) item.lParam; if (currentApp) { WINE_TRACE("currentApp is now %s\n", currentApp); enable(IDC_APP_REMOVEAPP); } else { WINE_TRACE("currentApp=NULL, editing global settings\n"); /* focus will never be on the button in this callback so it's safe */ disable(IDC_APP_REMOVEAPP); } /* reset the combo boxes if we changed from/to global/app-specific */ if ((oldapp && !currentApp) || (!oldapp && currentApp)) init_comboboxes(dialog); update_comboboxes(dialog); static void on_add_app_click(HWND dialog) char filetitle[MAX_PATH]; char file[MAX_PATH]; 0, NULL, 0, "c:\\", "Select a Windows executable file", OFN_SHOWHELP | OFN_HIDEREADONLY, 0, 0, NULL, 0, NULL }; ofn.lpstrFileTitle = filetitle; ofn.nMaxFileTitle = sizeof(filetitle); ofn.lpstrFile = file; ofn.nMaxFile = sizeof(file); HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW); int count = ListView_GetItemCount(listview); if (currentApp) free(currentApp); currentApp = strdup(filetitle); WINE_TRACE("adding %s\n", currentApp); add_listview_item(listview, currentApp, currentApp); ListView_SetItemState(listview, count, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); SetFocus(listview); else WINE_TRACE("user cancelled\n"); static void on_remove_app_click(HWND dialog) HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW); int selection = get_listview_selection(listview); char *section = keypath(""); WINE_TRACE("selection=%d, section=%s\n", selection, section); assert( selection != 0 ); /* user cannot click this button when "default settings" is selected */ section[strlen(section)] = '\0'; /* remove last backslash */ addTransaction(section, NULL, ACTION_REMOVE, NULL); ListView_DeleteItem(listview, selection); SetFocus(listview); static void on_winver_change(HWND dialog) int selection = SendDlgItemMessage(dialog, IDC_WINVER, CB_GETCURSEL, 0, 0); VERSION_DESC *ver = getWinVersions(); if (selection == 0) WINE_TRACE("automatic/default selected so removing current setting\n"); addTransaction(keypath("Version"), "Windows", ACTION_REMOVE, NULL); } else { WINE_TRACE("setting Version\\Windows key to value '%s'\n", ver[selection - 1].szVersion); addTransaction(keypath("Version"), "Windows", ACTION_SET, ver[selection - 1].szVersion); } } static void on_dosver_change(HWND dialog) { int selection = SendDlgItemMessage(dialog, IDC_DOSVER, CB_GETCURSEL, 0, 0); VERSION_DESC *ver = getDOSVersions(); if (selection == 0) { WINE_TRACE("automatic/default selected so removing current setting\n"); addTransaction(keypath("Version"), "DOS", ACTION_REMOVE, NULL); } else { WINE_TRACE("setting Version\\DOS key to value '%s'\n", ver[selection - 1].szVersion); addTransaction(keypath("Version"), "DOS", ACTION_SET, ver[selection - 1].szVersion); case WM_INITDIALOG: init_appsheet(hDlg); case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { case LVN_ITEMCHANGED: on_selection_change(hDlg, GetDlgItem(hDlg, IDC_APP_LISTVIEW)); break; break; case WM_COMMAND: switch(HIWORD(wParam)) { case CBN_SELCHANGE: switch(LOWORD(wParam)) { case IDC_WINVER: on_winver_change(hDlg); break; case IDC_DOSVER: on_dosver_change(hDlg); break; } case BN_CLICKED: switch(LOWORD(wParam)) { case IDC_APP_ADDAPP: on_add_app_click(hDlg); break; case IDC_APP_REMOVEAPP: on_remove_app_click(hDlg); break; } break; {"winxp", "Windows XP"}, {"win2k", "Windows 2000"}, {"winme", "Windows ME"}, {"win98", "Windows 98"}, {"win95", "Windows 95"}, {"nt40", "Windows NT 4.0"}, {"nt351", "Windows NT 3.5"}, {"win31", "Windows 3.1"}, {"win30", "Windows 3.0"}, {"win20", "Windows 2.0"}, * Copyright 2004 Mike Hearn #define IDC_APP_LISTVIEW 1200 * Copyright 2003-2004 Mike Hearn return defaultResult ? strdup(defaultResult) : NULL; buffer = defaultResult ? strdup(defaultResult) : NULL; * setConfigValue : Sets a configuration key in the registry. Section * will be created if it doesn't already exist char *currentApp = NULL; /* the app we are currently editing, or NULL if editing global */ /* returns a registry key path suitable for passing to addTransaction */ char *keypath(char *section) { static char *result = NULL; if (result) release(result); if (currentApp) { result = alloc(strlen("AppDefaults\\") + strlen(currentApp) + 2 /* \\ */ + strlen(section) + 1 /* terminator */); sprintf(result, "AppDefaults\\%s\\%s", currentApp, section); } else { result = strdupA(section); } return result; } * Copyright 2004 Mike Hearn extern char *currentApp; /* NULL means editing global settings */ /* returns a string of the form "AppDefaults\\appname.exe\\section", or just "section" if * the user is editing the global settings. * * no explicit free is needed of the string returned by this function */ char *keypath(char *section); /* don't use these directly! */ #define alloc(size) HeapAlloc(GetProcessHeap(), 0, size); #define release(ptr) HeapFree(GetProcessHeap(), 0, ptr); /* returns a string in the win32 heap */ static inline char *strdupA(char *s) { char *r = alloc(strlen(s)); return strcpy(r, s); } * Copyright 2003-2004 Mike Hearn if (doesConfigValueExist(keypath("x11drv"), "Desktop") == S_OK) { buf = getConfigValue(keypath("x11drv"), "Desktop", default_desktop); buf = getConfigValue(keypath("x11drv"), "ScreenDepth", "24"); buf = getConfigValue(keypath("x11drv"), "DXGrab", "Y"); buf = getConfigValue(keypath("x11drv"), "DesktopDoubleBuffered", "Y"); addTransaction(keypath("x11drv"), "Desktop", ACTION_SET, newStr); addTransaction(keypath("x11drv"), "Desktop", ACTION_REMOVE, NULL); addTransaction(keypath("x11drv"), "ScreenDepth", ACTION_SET, newvalue); addTransaction(keypath("x11drv"), "DXGrab", ACTION_SET, "Y"); addTransaction(keypath("x11drv"), "DXGrab", ACTION_SET, "N"); addTransaction(keypath("x11drv"), "DesktopDoubleBuffered", ACTION_SET, "Y"); addTransaction(keypath("x11drv"), "DesktopDoubleBuffered", ACTION_SET, "N"); if (!getenv("WINECFG_NOWARN")) { WINE_FIXME("The winecfg tool is not yet complete, and does not actually alter your configuration.\n"); WINE_FIXME("If you want to alter the way Wine works, look in the ~/.wine/config file for more information.\n"); MessageBoxA(NULL, "The winecfg tool is not yet complete, and does not actually alter your configuration\n\n" "If you want to alter the way Wine works, look in the ~/.wine/config file for more information.", "", MB_OK | MB_ICONEXCLAMATION); } MessageBox(NULL, "It is not advisable to run wine as root. Doing so may compromise the security of your computer. Please run wine as a normal user.", "", MB_OK); if (wma->ash_audio.fccHandler) /* not all streams specify a handler */ TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(wma->ash_audio.fccHandler)), else TRACE("ash.fccHandler=0, no handler specified\n"); /* disconnect proxies to release the corresponding stubs. * FIXME: native version might not do this and we might just be working * around bugs elsewhere. */ MARSHAL_Disconnect_Proxies(); HRESULT MARSHAL_Disconnect_Proxies(); HRESULT MARSHAL_Disconnect_Proxies() { int i; TRACE("Disconnecting %d proxies\n", nrofproxies); for (i = 0; i < nrofproxies; i++) IRpcProxyBuffer_Disconnect((IRpcProxyBuffer*)proxies[i].pUnk); return S_OK; } MARSHAL_Register_Proxy(&mid, (LPUNKNOWN) rpcproxy); TRACE("marshalling IClassFactory to client\n"); hres = IUnknown_QueryInterface(newClass->classObject,&IID_IClassFactory,(LPVOID*)&classfac); if (hres) return hres; hres = CreateStreamOnHGlobal(0,TRUE,&pStm); if (hres) { FIXME("Failed to create stream on hglobal.\n"); return hres; } hres = CoMarshalInterface(pStm,&IID_IClassFactory,(LPVOID)classfac,0,NULL,0); if (hres) { FIXME("CoMarshalInterface failed, %lx!\n",hres); return hres; } IUnknown_Release(classfac); /* is this right? */ hres = IStream_Stat(pStm,&ststg,0); if (hres) return hres; buflen = ststg.cbSize.u.LowPart; buffer = HeapAlloc(GetProcessHeap(),0,buflen); seekto.u.LowPart = 0; seekto.u.HighPart = 0; hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos); if (hres) { FIXME("IStream_Seek failed, %lx\n",hres); return hres; } hres = IStream_Read(pStm,buffer,buflen,&res); if (hres) { FIXME("Stream Read failed, %lx\n",hres); return hres; } IStream_Release(pStm); TRACE("done marshalling IClassFactory\n"); TRACE("(%p) before %lu\n", This, This->ref); TRACE("(%p) after %lu\n", This, This->ref-1); IRpcStubBuffer_Disconnect(iface); TRACE("(%p)->(%p)\n", This, pUnkServer); TRACE("(%p)->()\n", This); TRACE("IRpcStubBuffer: %p\n", stub); void MARSHAL_Invalidate_Stub_From_MID(wine_marshal_id *mid); void MARSHAL_Invalidate_Stub_From_MID(wine_marshal_id *mid) { int i; for (i=0;imid, sizeof(wine_marshal_id)); pipe = PIPE_FindByMID(&This->mid); _xwrite(pipe, &reqtype, sizeof(reqtype)); _xwrite(pipe, &header, sizeof(wine_rpc_disconnect_header)); TRACE("written disconnect packet\n"); if (reqtype == REQTYPE_DISCONNECT) { /* only received by servers */ wine_rpc_disconnect_header header; IRpcStubBuffer *stub; ULONG ret; hres = _xread(xhPipe, &header, sizeof(header)); if (hres) { ERR("could not read disconnect header\n"); goto end; } TRACE("read disconnect header\n"); hres = MARSHAL_Find_Stub_Buffer(&header.mid, &stub); if (hres) { ERR("could not locate stub to disconnect, mid.objectid=%p\n", (void*)header.mid.objectid); goto end; } /* release reference added by MARSHAL_Find_Stub_Buffer call */ IRpcStubBuffer_Release(stub); /* release it for real */ ret = IRpcStubBuffer_Release(stub); /* FIXME: race */ if (ret == 0) MARSHAL_Invalidate_Stub_From_MID(&header.mid); goto end; } else if (reqtype == REQTYPE_REQUEST) { } else if (reqtype == REQTYPE_RESPONSE) { if (SUCCEEDED(MARSHAL_Find_Stub_Buffer(&mid,&stub))) { /* Find_Stub_Buffer gives us a ref but we want to keep it, as if we'd created a new one */ TRACE("Found RpcStubBuffer %p\n", stub); WARN("No PSFactoryBuffer object is registered for this IID\n"); TRACE("Calling IMarshal::MarshalInterace\n"); static const WCHAR embedding[] = { ' ', '-','E','m','b','e','d','d','i','n','g',0 }; WCHAR exe[MAX_PATH+1]; DWORD exelen = sizeof(exe); WCHAR command[MAX_PATH+sizeof(embedding)/sizeof(WCHAR)]; if (hres != ERROR_SUCCESS) { WARN("CLSID %s not registered as LocalServer32\n", xclsid); } memset(exe,0,sizeof(exe)); hres= RegQueryValueExW(key, NULL, NULL, NULL, (LPBYTE)exe, &exelen); if (hres) { WARN("No default value for LocalServer32 key\n"); return REGDB_E_CLASSNOTREG; /* FIXME: check retval */ } /* EXE servers are started with the -Embedding switch. MSDN also claims /Embedding is used, 9x does -Embedding, perhaps an 9x/NT difference? */ strcpyW(command, exe); strcatW(command, embedding); TRACE("activating local server '%s' for %s\n", debugstr_w(command), xclsid); if (!CreateProcessW(exe, command, NULL, NULL, FALSE, 0, NULL, NULL, &sinfo, &pinfo)) { WARN("failed to run local server %s\n", debugstr_w(exe)); } TRACE("rclsid=%s, iid=%s\n", debugstr_guid(rclsid), debugstr_guid(iid)); IUnknown_Release(stub); WARN("class %s not registered inproc\n", xclsid); STARTUPINFOA startup, us; GetStartupInfoA(&us); okChildString("StartupInfoA", "lpDesktop", us.lpDesktop); STARTUPINFOA startup, us; GetStartupInfoA(&us); okChildString("StartupInfoA", "lpDesktop", us.lpDesktop); STARTUPINFOA startup, us; GetStartupInfoA(&us); okChildString("StartupInfoA", "lpDesktop", us.lpDesktop); ret = SetEnvironmentVariableA(name, value[0] ? value : NULL) ? 0 : -1; /* _putenv returns success on deletion of non-existent variable, unlike [Rtl]SetEnvironmentVariable */ if ((ret == -1) && (GetLastError() == ERROR_ENVVAR_NOT_FOUND)) ret = 0; ret = SetEnvironmentVariableW(name, value[0] ? value : NULL) ? 0 : -1; /* _putenv returns success on deletion of non-existent variable, unlike [Rtl]SetEnvironmentVariable */ if ((ret == -1) && (GetLastError() == ERROR_ENVVAR_NOT_FOUND)) ret = 0; /* * Unit tests for C library environment routines * * Copyright 2004 Mike Hearn * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "wine/test.h" #include START_TEST(environ) { ok( _putenv("cat=") == 0, "_putenv failed on deletion of non-existent environment variable\n" ); ok( _putenv("cat=dog") == 0, "failed setting cat=dog\n" ); ok( strcmp(getenv("cat"), "dog") == 0, "getenv did not return 'dog'\n" ); ok( _putenv("cat=") == 0, "failed deleting cat\n" ); ok( _putenv("=") == -1, "should not accept '=' as input\n" ); ok( _putenv("=dog") == -1, "should not accept '=dog' as input\n" ); ok( getenv("nonexistent") == NULL, "getenv should fail with nonexistent var name\n" ); } /* * TWAIN 16-bit functions * * Copyright (C) 2004 Mike Hearn for CodeWeavers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include "windef.h" #include "winbase.h" #include "twain.h" #include "twain_i.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(twain); /* Main entry point for the TWAIN library */ TW_UINT16 WINAPI DSM_Entry16 (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest, TW_UINT32 DG, TW_UINT16 DAT, TW_UINT16 MSG, TW_MEMREF pData) { FIXME("stub\n"); return TWRC_FAILURE; } if (synchronous) { ERR( "X protocol error: serial=%ld, request_code=%d - breaking into debugger\n", error_evt->serial, error_evt->request_code ); DebugBreak(); /* force an entry in the debugger */ } static const WCHAR bogus[] = { '\\', '\\', '.', '\\', 'B', 'O', 'G', 'U', 'S', 0 }; /* test the result of opening a non-existent driver name */ hFile = CreateFileW(bogus, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_NOT_FOUND, "CreateFileW on invalid VxD name returned ret=%p error=%ld\n",hFile,GetLastError()); SetLastError( ERROR_FILE_NOT_FOUND ); * Copyright 1999 Sylvain St-Germain * Copyright 2002 Marcus Meissner * Copyright 2004 Mike Hearn /* Inter-thread RPCs are done through window messages rather than pipes. When an interface is marshalled into another apartment in the same process, a window of the following class is created. The *caller* of CoMarshalInterface (ie the application) is responsible for pumping the message loop in that thread, the WM_USER messages which point to the RPCs are then dispatched to COM_AptWndProc by the users code. */ /* The multi-threaded apartment (MTA) contains zero or more threads interacting with free threaded (ie thread safe) COM objects. There is only ever one MTA in a process - you can enter it by calling CoInitializeEx(COINIT_MULTITHREADED) */ /* OXIDs are object exporter IDs. Each apartment has an OXID, which is unique within a network. That is, two different MTAs on different machines will have different OXIDs. This method of generating an OXID is therefore wrong as it doesn't work across a network, but for local RPC only it's OK. We can distinguish between MTAs and STAs because STAs use the thread ID as well, and no thread can have an ID of zero. */ /* The given OXID must be local to this process: you cannot use apartment windows to send RPCs to other processes */ /* Currently inter-thread marshalling is not fully implemented, so this does nothing */ * RPC_E_CHANGED_MODE if a previous call to CoInitializeEx specified another * threading model. /* Changing the threading model after it's been set is illegal. If this warning is triggered by Wine code then we are probably using the wrong threading model to implement that API. */ WARN("Attempt to change threading model of this apartment from 0x%lx to 0x%lx\n", apt->model, dwCoInit); /* On COM finalization for a STA thread, the message queue is flushed to ensure no pending RPCs are ignored. Non-COM messages are discarded at this point. */ void COM_FlushMessageQueue(void) { MSG message; APARTMENT *apt = NtCurrentTeb()->ReservedForOle; if (!apt || !apt->win) return; TRACE("Flushing STA message queue\n"); while (PeekMessageA(&message, NULL, 0, 0, PM_REMOVE)) { if (message.hwnd != apt->win) continue; TranslateMessage(&message); DispatchMessageA(&message); } } /* Release the references to the registered class objects */ /* This will free the loaded COM Dlls */ /* This will free list of external references to COM objects */ /* This ensures we deal with any pending RPCs */ COM_FlushMessageQueue(); * * Disconnects all connections to this object from remote processes. Dispatches * pending RPCs while blocking new RPCs from occuring, and then calls * IMarshal::DisconnectObject on the given object. * * Typically called when the object server is forced to shut down, for instance by * the user. FIXME("(%p, %lx): stub - probably harmless\n",lpUnk,reserved); * This function returns the CLSID of the proxy/stub factory that implements IPSFactoryBuffer * The standard marshaller activates the object with the CLSID returned and uses the * CreateProxy and CreateStub methods on its IPSFactoryBuffer interface to construct * the proxies and stubs for a given object. * * CoGetPSClsid determines this CLSID by searching the * This method will register the class object for a given class ID. Servers housed * in EXE files use this method instead of exporting DllGetClassObject to allow other * code to connect to their objects. * * When a class object (an object which implements IClassFactory) is registered in * this way, a new thread is started which listens for connections on a named pipe * specific to the registered CLSID. When something else connects to it, it writes * out the marshalled IClassFactory interface to the pipe. The code on the other end * uses this buffer to unmarshal the class factory, and can then call methods on it. * * In Windows, such objects are registered with the RPC endpoint mapper, not with * a unique named pipe. * * MSDN claims that multiple interface registrations are legal, but we can't do that with * our current implementation. /* Finally try remote: this requires networked DCOM (a lot of work) */ FIXME("stub\n"); /* if the above strategies fail then search for the extension key in the registry */ VirtualFree(This->asmstubs, 0, MEM_RELEASE); proxy = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TMProxyImpl)); proxy->asmstubs = VirtualAlloc(NULL, sizeof(TMAsmProxy) * nroffuncs, MEM_COMMIT, PAGE_EXECUTE_READWRITE); if (!proxy->asmstubs) { ERR("Could not commit pages for proxy thunks\n"); HeapFree(GetProcessHeap(), 0, proxy); return E_OUTOFMEMORY; } case VT_HRESULT: sprintf(szVarType, "VT_HRESULT"); break; MESSAGE("\telemdescFunc (return value type):\n"); dump_ELEMDESC(&funcdesc->elemdescFunc); /* This file contains the proxy/stub code for core COM interfaces. It is usually generated directly by MIDL, however this file has been tweaked since then to account for slight differences in the way gcc and MSVC++ compile it. In particular, in some functions REFIIDs declared on the stack have been converted to plain IID* in order to eliminate the constness of the REFIID type, ensuring that the zero initializer is not discarded. Therefore, please do not regenerate this file. */ IID* riid = 0; IID* riid = 0; IID* riid = 0; IID* riid = 0; IID* riid = 0; TRACE_(olerelay)("->"); if (relaydeb) TRACE_(olerelay)(")\n"); extern char *arg_command; #include "tlhelp32.h" if (tid == -1) /* backtrace every thread in every process except the debugger itself, invoking via "bt all" */ { THREADENTRY32 entry; HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); if (snapshot == INVALID_HANDLE_VALUE) { dbg_printf("unable to create toolhelp snapshot\n"); return; } entry.dwSize = sizeof(entry); if (!Thread32First(snapshot, &entry)) { CloseHandle(snapshot); return; } do { if (entry.th32OwnerProcessID == GetCurrentProcessId()) continue; if (dbg_curr_process) dbg_detach_debuggee(); dbg_printf("\n"); if (!dbg_attach_debuggee(entry.th32OwnerProcessID, FALSE, TRUE)) { dbg_printf("\nwarning: could not attach to 0x%lx\n", entry.th32OwnerProcessID); continue; } dbg_printf("Backtracing for thread 0x%lx in process 0x%lx (%s):\n", entry.th32ThreadID, dbg_curr_pid, dbg_curr_process->imageName); stack_backtrace(entry.th32ThreadID, TRUE); } while (Thread32Next(snapshot, &entry)); if (dbg_curr_process) dbg_detach_debuggee(); CloseHandle(snapshot); return; } if (!dbg_curr_process) { dbg_printf("You must be attached to a process to run this command.\n"); return; } if (!strcmp(argv[1], "--command")) { argc--; argv++; arg_command = HeapAlloc(GetProcessHeap(), 0, strlen(argv[1])+2); strcpy(arg_command, argv[1]); strcat(arg_command, "\n"); argc--; argv++; continue; } return WIN98; return WIN98; WINE_DECLARE_DEBUG_CHANNEL(msgbox); TRACE_(msgbox)("%s\n", debugstr_w(lpszText)); * The olerelay debug channel allows you to see calls marshalled by * the typelib marshaller. It is not a generic COM relaying system. * /* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */ static char *relaystr(WCHAR *in) { char *tmp = (char *)debugstr_w(in); tmp += 2; tmp[strlen(tmp)-1] = '\0'; return tmp; } if (debugout) TRACE_(olerelay)("%lx",*arg); if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype); if (debugout) TRACE_(olerelay)(")"); TRACE_(olerelay)("%s",relaystr((BSTR)*arg)); TRACE_(olerelay)(""); if (debugout) TRACE_(olerelay)("*"); if (debugout) TRACE_(olerelay)("NULL"); if (debugout) TRACE_(olerelay)("unk(0x%lx)",*arg); if (debugout) TRACE_(olerelay)("idisp(0x%lx)",*arg); if (debugout) TRACE_(olerelay)(""); if (debugout) TRACE_(olerelay)("{"); TRACE_(olerelay)("%s=",relaystr(names[0])); TRACE_(olerelay)(","); if (debugout) TRACE_(olerelay)("}"); if (debugout) TRACE_(olerelay)("carr"); if (debugout) TRACE_(olerelay)("[%ld]",adesc->rgbounds[i].cElements); if (debugout) TRACE_(olerelay)("["); if (debugout && (i"); TRACE_(olerelay)("ppv(%p)",*(LPUNKNOWN*)*arg); if (debugout) TRACE_(olerelay)(""); if (debugout) TRACE_(olerelay)("D{"); TRACE_(olerelay)(","); if (debugout) TRACE_(olerelay)("}{"); TRACE_(olerelay)(","); if (debugout) TRACE_(olerelay)("}"); if (debugout) TRACE_(olerelay)(""); if (debugout) TRACE_(olerelay)(""); if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype); TRACE_(olerelay)(")"); if (debugout) TRACE_(olerelay)("%lx",*arg); if (debugout) TRACE_(olerelay)(""); if (debugout) TRACE_(olerelay)("%s",relaystr(str)); if (debugout) TRACE_(olerelay)("NULL"); if (debugout) TRACE_(olerelay)("*"); TRACE_(olerelay)("unk(%p)",arg); TRACE_(olerelay)("idisp(%p)",arg); if (debugout) TRACE_(olerelay)(""); if (debugout) TRACE_(olerelay)("{"); if (debugout && (icVars-1)) TRACE_(olerelay)(","); if (debugout) TRACE_(olerelay)("}"); if (debugout) TRACE_(olerelay)(""); if (debugout) TRACE_(olerelay)("ppv(%p)",(LPVOID)*arg); if (debugout) TRACE_(olerelay)(""); if (debugout) TRACE_(olerelay)("D{"); if (debugout) TRACE_(olerelay)("}{"); if (debugout && i<(disps->cNamedArgs-1)) TRACE_(olerelay)(","); if (debugout) TRACE_(olerelay)("}"); TRACE_(olerelay)("\n->"); TRACE_(olerelay)("%s:",relaystr(iname)); TRACE_(olerelay)("%s(%d)",relaystr(fname),method); TRACE_(olerelay)("%d",method); TRACE_(olerelay)("("); if (relaydeb) TRACE_(olerelay)("riid=%s,[out]",debugstr_guid((REFIID)args[0])); if (i) TRACE_(olerelay)(","); TRACE_(olerelay)("%s=",relaystr(names[i+1])); if (relaydeb) TRACE_(olerelay)("[out]"); if (relaydeb) TRACE_(olerelay)(")"); if (relaydeb) TRACE_(olerelay)("\n"); if (relaydeb) TRACE_(olerelay)(" = %08lx (",status); if (relaydeb) TRACE_(olerelay)("[in],%p",*((DWORD**)args[1])); if (i) TRACE_(olerelay)(","); if (i+1FromConn); RPCRT4_CreateConnection(&NewConnection, Binding->server, Binding->Protseq, Binding->NetworkAddr, Binding->Endpoint, NULL, Binding); RPCRT4_DestroyConnection(*Connection); RPCRT4_DestroyConnection(*Connection); RPCRT4_DestroyConnection(*Connection); RPCRT4_DestroyConnection(*Connection); RPCRT4_DestroyConnection(*Connection); RPCRT4_DestroyConnection(*Connection); return RPCRT4_DestroyConnection(Connection); TRACE("returning %p for %s\n", cif, debugstr_guid(object)); TRACE("packet size less than min size, or active interface syntax guid non-null\n"); TRACE("rejecting bind request on connection %p\n", conn); TRACE("accepting bind request on connection %p\n", conn); TRACE("releasing pre-existing connection\n"); RPCRT4_ReleaseConnection(*Connection); RPCRT4_ReleaseConnection(*Connection); int dxgrab = 0; int usedga = 0; int usexvidmode = 0; int usexrandr = 1; /* ShowWindow(SW_HIDE) for an invisible overlapped window */ static const struct message WmHideInvisibleOverlappedSeq[] = { { 0 } }; /* test ShowWindow(SW_HIDE) on a newly created invisible window */ ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" ); ok_sequence(WmHideInvisibleOverlappedSeq, "ShowWindow(SW_HIDE):overlapped, invisible"); if (!wasVisible) goto END; TRACE( "Broken app is writing to the resource data, enabling work-around\n" ); #include "winnls.h" HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD data) FIXME("(%p, %s, %d, %ld): stub\n", caller, debugstr_w(filename), command, data); /* if command is HH_DISPLAY_TOPIC just display an informative message for now */ if (command == 0) MessageBoxA( NULL, "HTML Help functionality is currently unimplemented.\n\n" "Try installing Internet Explorer, or using a native hhctrl.ocx with the Mozilla ActiveX control.", "Wine", MB_OK | MB_ICONEXCLAMATION ); return 0; HWND WINAPI HtmlHelpA(HWND caller, LPCSTR filename, UINT command, DWORD data) WCHAR *wfile = NULL; DWORD len = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 ); HWND result; wfile = HeapAlloc( GetProcessHeap(), 0, len ); MultiByteToWideChar( CP_ACP, 0, filename, -1, wfile, len ); result = HtmlHelpW( caller, wfile, command, data ); HeapFree( GetProcessHeap(), 0, wfile ); return result; TRACE_(dll)("Calling LibMain for %.*s, cs:ip=%04lx:%04lx ds=%04lx di=%04x cx=%04x\n", *((BYTE*)pModule + pModule->name_table), (char *)pModule + pModule->name_table + 1, context.SegCs, context.Eip, context.SegDs, LOWORD(context.Edi), LOWORD(context.Ecx) ); log_pixels_x = log_pixels_y = 96; #include "winternl.h" #include "ntstatus.h" /* These functions have nearly identical prototypes to CryptProtectMemory and CryptUnprotectMemory, in crypt32.dll. */ /****************************************************************************** * SystemFunction040 (ADVAPI32.@) * * PARAMS: * memory : pointer to memory to encrypt * length : length of region to encrypt, in bytes. must be multiple of RTL_ENCRYPT_MEMORY_SIZE * flags : RTL_ENCRYPT_OPTION_SAME_PROCESS | RTL_ENCRYPT_OPTION_CROSS_PROCESS, | RTL_ENCRYPT_OPTION_SAME_LOGON * control whether other processes are able to decrypt the memory. The same value must be given * when decrypting the memory. */ NTSTATUS WINAPI SystemFunction040(PVOID memory, ULONG length, ULONG flags) /* RtlEncryptMemory */ { FIXME("(%p, %lx, %lx): stub [RtlEncryptMemory]\n", memory, length, flags); return STATUS_SUCCESS; } /****************************************************************************** * SystemFunction041 (ADVAPI32.@) * * PARAMS: * memory : pointer to memory to decrypt * length : length of region to decrypt, in bytes. must be multiple of RTL_ENCRYPT_MEMORY_SIZE * flags : RTL_ENCRYPT_OPTION_SAME_PROCESS | RTL_ENCRYPT_OPTION_CROSS_PROCESS, | RTL_ENCRYPT_OPTION_SAME_LOGON * control whether other processes are able to decrypt the memory. The same value must be given * when encrypting the memory. */ NTSTATUS WINAPI SystemFunction041(PVOID memory, ULONG length, ULONG flags) /* RtlDecryptMemory */ { FIXME("(%p, %lx, %lx): stub [RtlDecryptMemory]\n", memory, length, flags); return STATUS_SUCCESS; } #include "winreg.h" char* device; char* device; /* return a string duplicated on the win32 process heap, free with HeapFree */ static char* ALSA_strdup(char *s) { char *result = HeapAlloc(GetProcessHeap(), 0, strlen(s)+1); strcpy(result, s); return result; } /****************************************************************** * ALSA_GetDeviceFromReg * * Returns either "default" or reads the registry so the user can * override the playback/record device used. */ char *ALSA_GetDeviceFromReg(char *value) { DWORD res; DWORD type; HKEY playbackKey = 0; char *result = NULL; DWORD resultSize; res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\ALSA", 0, KEY_QUERY_VALUE, &playbackKey); if (res != ERROR_SUCCESS) goto end; res = RegQueryValueExA(playbackKey, value, NULL, &type, NULL, &resultSize); if (res != ERROR_SUCCESS) goto end; if (type != REG_SZ) { ERR("Registry key [HKEY_LOCAL_MACHINE\\Software\\Wine\\Wine\\ALSA\\%s] must be a string\n", value); goto end; } result = HeapAlloc(GetProcessHeap(), 0, resultSize); res = RegQueryValueExA(playbackKey, value, NULL, NULL, result, &resultSize); end: if (!result) result = ALSA_strdup("default"); if (playbackKey) RegCloseKey(playbackKey); return result; } wwo->device = ALSA_GetDeviceFromReg("PlaybackDevice"); TRACE("using waveout device \"%s\"\n", wwo->device); wwi->device = ALSA_GetDeviceFromReg("RecordDevice"); TRACE("using wavein device \"%s\"\n", wwi->device); HeapFree(GetProcessHeap(), 0, wwo->device); HeapFree(GetProcessHeap(), 0, wwi->device); if (!hWnd && event->type != PropertyNotify && event->type != MappingNotify && event->type != KeymapNotify) if (TRACE_ON(snoop) && current_modref) proc = SNOOP_GetProcAddress( module, exports, exp_size, proc, ordinal, current_modref->ldr.BaseDllName.Buffer ); FARPROC origfun, DWORD ordinal, const WCHAR *user ); static const WCHAR **debug_from_snoop_excludelist; static const WCHAR **debug_from_snoop_includelist; static const WCHAR SnoopFromIncludeW[] = {'S','n','o','o','p','F','r','o','m','I','n','c','l','u','d','e',0}; static const WCHAR SnoopFromExcludeW[] = {'S','n','o','o','p','F','r','o','m','E','x','c','l','u','d','e',0}; RtlInitUnicodeString( &name, SnoopFromIncludeW ); if (!NtQueryValueKey( hkey, &name, KeyValuePartialInformation, buffer, sizeof(buffer), &count )) { TRACE_(snoop)("SnoopFromInclude = %s\n", debugstr_w(str) ); debug_from_snoop_includelist = build_list( str ); } RtlInitUnicodeString( &name, SnoopFromExcludeW ); if (!NtQueryValueKey( hkey, &name, KeyValuePartialInformation, buffer, sizeof(buffer), &count )) { TRACE_(snoop)( "SnoopFromExclude = %s\n", debugstr_w(str) ); debug_from_snoop_excludelist = build_list( str ); } * check_from_module * Check if calls from a given module must be included in the relay/snoop output, * given the exclusion and inclusion lists. static BOOL check_from_module( const WCHAR **includelist, const WCHAR **excludelist, const WCHAR *module ) if (!includelist && !excludelist) return TRUE; if (excludelist) listitem = excludelist; listitem = includelist; if (check_from_module( debug_from_relay_includelist, debug_from_relay_excludelist, user )) return proc; /* we want to relay it */ TRACE_(snoop)("hmod=%p, name=%s\n", hmod, name); DWORD exp_size, FARPROC origfun, DWORD ordinal, const WCHAR *user) if (!check_from_module( debug_from_snoop_includelist, debug_from_snoop_excludelist, user )) return origfun; /* the calling module was explicitly excluded */ if (nt->OptionalHeader.ImageBase == 0x400000) { ERR("Image was mapped at %p: standard load address for a Win32 program (0x00400000) not available\n", ptr); ERR("Do you have exec-shield or prelink active?\n"); } else WINE_DEFAULT_DEBUG_CHANNEL(time); if (flags & (DCX_LOCKWINDOWUPDATE)) { FIXME("not yet supported - see source\n"); /* See the comment in LockWindowUpdate for more explanation. This flag is not implemented * by that patch, but we need LockWindowUpdate implemented correctly before this can be done. */ } /* This function is fully implemented by the following patch: * * http://www.winehq.org/hypermail/wine-patches/2004/01/0142.html * * but in order to work properly, it needs the ability to invalidate * DCEs in other processes when the lock window is changed, which * isn't possible yet. * -mike */ HRESULT WINAPI SHDOCVW_DllGetVersion (DLLVERSIONINFO *info) if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n"); /* this is what IE6 on Windows 98 reports */ info->dwMajorVersion = 6; info->dwMinorVersion = 0; info->dwBuildNumber = 2600; info->dwPlatformID = DLLVER_PLATFORM_WINDOWS; return NOERROR; WINE_DEFAULT_DEBUG_CHANNEL(olemalloc); * we can't revoke a malloc spy as long as memory blocks allocated with Rectangle(hdc, centerx - rectsize - 1, centery - rectsize - 1, centerx + rectsize + 2, centery + rectsize + 2); * Copyright 2003 Mike Hearn #include "winternl.h" /*********************************************************************** * RpcNetworkIsProtSeqValidA (RPCRT4.@) */ RPC_STATUS RPC_ENTRY RpcNetworkIsProtSeqValidA(unsigned char *protseq) { UNICODE_STRING protseqW; if (!protseq) return RPC_S_INVALID_RPC_PROTSEQ; /* ? */ if (RtlCreateUnicodeStringFromAsciiz(&protseqW, protseq)) { RPC_STATUS ret = RpcNetworkIsProtSeqValidW(protseqW.Buffer); RtlFreeUnicodeString(&protseqW); return ret; } else return RPC_S_OUT_OF_MEMORY; } /*********************************************************************** * RpcNetworkIsProtSeqValidW (RPCRT4.@) * * Checks if the given protocol sequence is known by the RPC system. * If it is, returns RPC_S_OK, otherwise RPC_S_PROTSEQ_NOT_SUPPORTED. * * We currently only support ncalrpc. */ RPC_STATUS RPC_ENTRY RpcNetworkIsProtSeqValidW(LPWSTR protseq) { static const WCHAR ncalrpcW[] = {'n','c','a','l','r','p','c',0}; if (!protseq) return RPC_S_INVALID_RPC_PROTSEQ; /* ? */ if (!strcmpW(protseq, ncalrpcW)) return RPC_S_OK; FIXME("Unknown protseq %s - we probably need to implement it one day", debugstr_w(protseq)); return RPC_S_PROTSEQ_NOT_SUPPORTED; } static void test_GetTempFileNameA() { UINT result; char out[MAX_PATH]; char *expected = "c:\\windows\\abc2.tmp"; /* this test may depend on the config file settings */ result = GetTempFileNameA("C:", "abc", 1, out); ok( result != 0, "GetTempFileNameA: error %ld\n", GetLastError() ); ok( ((out[0] == 'C') && (out[1] == ':')) && (out[2] == '\\'), "GetTempFileNameA: first three characters should be C:\\, string was actually %s", out ); result = GetTempFileNameA("c:\\windows\\", "abc", 2, out); ok( result != 0, "GetTempFileNameA: error %ld\n", GetLastError() ); ok( strcasecmp( out, expected ) == 0, "GetTempFileNameA: Unexpected output \"%s\" vs \"%s\"\n", out, expected ); } test_GetTempFileNameA(); static const WCHAR formatW[] = {'%','x','.','t','m','p',0}; /* add a \, if there isn't one */ if ((p == buffer) || (p[-1] != '\\')) *p++ = '\\'; #define TEST_URL "http://www.winehq.org/site/about" #define TEST_URL_PATH "/site/about" ok (InternetCanonicalizeUrl(TEST_URL, buffer, &size,ICU_BROWSER_MODE), ok((InternetCrackUrl(TEST_URL, 0,0,&urlComponents)), myhttp = InternetOpenUrl(myhinternet, TEST_URL, 0, 0, ok((InternetCrackUrl(TEST_URL, 0,0,&urlComponents)), ok((strcmp(TEST_URL_PATH,path) == 0),"path cracked wrong"); FIXME("stub: don't know what to do for code %lx\n", unknown ); FIXME("generic stub: %s\n", ((LPSTR)context->Eax ? (LPSTR)context->Eax : "?")); hkey = get_special_root_hkey( hkey ); if (!hkey) return ERROR_INVALID_HANDLE; return RtlNtStatusToDosError( NtFlushKey( hkey ) ); /****************************************************************************** * VMM_RegFlushKey */ static DWORD VMM_RegFlushKey( HKEY hkey ) { return RtlNtStatusToDosError( NtFlushKey( hkey ) ); } return VMM_RegFlushKey( hkey ); NTSTATUS WINAPI NtFlushKey(HKEY key) NTSTATUS ret; TRACE("key=%p\n", key); SERVER_START_REQ( flush_key ) { req->hkey = key; ret = wine_server_call( req ); } SERVER_END_REQ; return ret; /* flush a registry key */ DECL_HANDLER(flush_key) { struct key *key = get_hkey_obj( req->hkey, 0 ); if (key) { /* we don't need to do anything here with the current implementation */ release_object( key ); } } DECL_HANDLER(flush_key); (req_handler)req_flush_key, static void dump_flush_key_request( const struct flush_key_request *req ) { fprintf( stderr, " hkey=%p", req->hkey ); } (dump_func)dump_flush_key_request, (dump_func)0, "flush_key", * the destination path. It appears to be a pointer to an optional return struct. * The IE6 installer derefs this value + 4. Contents currently unknown. dest->result2 = 0; ERR( "Main exe initialization for %s failed, status %lx\n", debugstr_w(main_exe_name->Buffer), status ); if (GetWindowTextW( list[i], buffer, len + 1 ) && !strcmpiW( buffer, title )) break; "_NET_WM_WINDOW_TYPE", "_NET_WM_WINDOW_TYPE_UTILITY", /* windows with caption are managed */ /* tool windows are not managed */ if (win->dwExStyle & WS_EX_TOOLWINDOW) return FALSE; /* windows with thick frame are managed */ /* map WS_EX_TOOLWINDOW to _NET_WM_WINDOW_TYPE_UTILITY */ if (win->dwExStyle & WS_EX_TOOLWINDOW) { Atom a = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY); XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE), XA_ATOM, 32, PropModeReplace, (char*)&a, 1); } XATOM__NET_WM_WINDOW_TYPE, XATOM__NET_WM_WINDOW_TYPE_UTILITY, * Copyright 1995 Sven Verdoolaege * Copyright 1998 Juergen Schmied * Copyright 2003 Mike Hearn WINE_DECLARE_DEBUG_CHANNEL(eventlog); LPCWSTR *wideStrArray; UNICODE_STRING str; int i; BOOL ret; if (wNumStrings == 0) return TRUE; if (!lpStrings) return TRUE; wideStrArray = HeapAlloc(GetProcessHeap(), 0, sizeof(LPCWSTR) * wNumStrings); for (i = 0; i < wNumStrings; i++) { RtlCreateUnicodeStringFromAsciiz(&str, lpStrings[i]); wideStrArray[i] = str.Buffer; } ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, wideStrArray, lpRawData); for (i = 0; i < wNumStrings; i++) { if (wideStrArray[i]) HeapFree( GetProcessHeap(), 0, (LPSTR)wideStrArray[i] ); } HeapFree(GetProcessHeap(), 0, wideStrArray); return ret; int i; /* partial stub */ if (wNumStrings == 0) return TRUE; if (!lpStrings) return TRUE; for (i = 0; i < wNumStrings; i++) { switch (wType) { case EVENTLOG_SUCCESS: TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i])); break; case EVENTLOG_ERROR_TYPE: ERR_(eventlog)("%s\n", debugstr_w(lpStrings[i])); break; case EVENTLOG_WARNING_TYPE: WARN_(eventlog)("%s\n", debugstr_w(lpStrings[i])); break; default: TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i])); break; } } return TRUE; #define versionSection (appSettings == EDITING_GLOBAL ? "Version" : (getSectionForApp("Version"))) #define tweakSection (appSettings == EDITING_GLOBAL ? "Tweak.Layout" : (getSectionForApp("Tweak.Layout"))) char *curWinVer = getConfigValue(versionSection, "Windows", "win98"); char *curDOSVer = getConfigValue(versionSection, "DOS", "6.22"); char *curWineLook = getConfigValue(tweakSection, "WineLook", "win95"); case WM_NOTIFY: if (((LPNMHDR)lParam)->code != PSN_SETACTIVE) break; /* otherwise fall through, we want to refresh the page as well */ addTransaction(versionSection, "Windows", ACTION_SET, desc->szVersion); case IDC_WINELOOK: if (HIWORD(wParam) == CBN_SELCHANGE) { /* user changed the wine look combo box */ int selection = SendDlgItemMessage( hDlg, IDC_WINELOOK, CB_GETCURSEL, 0, 0); VERSION_DESC *desc = getWinelook(); while (selection > 0) { desc++; selection--; } addTransaction(tweakSection, "WineLook", ACTION_SET, desc->szVersion); } break; case IDC_DOSVER: if (HIWORD(wParam) == CBN_SELCHANGE) { /* user changed the dos version combo box */ int selection = SendDlgItemMessage( hDlg, IDC_WINELOOK, CB_GETCURSEL, 0, 0); VERSION_DESC *desc = getDOSVersions(); while (selection > 0) { desc++; selection--; } addTransaction(versionSection, "DOS", ACTION_SET, desc->szVersion); } static int needToRefresh = 1; if (SendDlgItemMessage(hDlg, IDC_LIST_APPS, LB_GETCURSEL, 0, 0) == LB_ERR) { /* no selection, so select the first one */ SendDlgItemMessage(hDlg, IDC_LIST_APPS, LB_SETCURSEL, 0, 0); onAppsListSelChange(hDlg); } refreshDialog(hDlg); refreshDialog(hDlg); if (needToRefresh) { refreshDialog(hDlg); needToRefresh = 0; } } int refreshDriveDlg (HWND dialog) SendMessageA(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_RESETCONTENT, 0, 0); itemIndex = SendMessageA(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_ADDSTRING ,(WPARAM) -1, (LPARAM) title); SendMessageA(GetDlgItem(dialog, IDC_LIST_DRIVES), LB_SETITEMDATA, itemIndex, (LPARAM) driveLetter); SendDlgItemMessage(dialog, IDC_LIST_DRIVES, LB_SETSEL, TRUE, lastSel); ShowWindow(GetDlgItem(dialog, IDS_DRIVE_NO_C), SW_NORMAL); ShowWindow(GetDlgItem(dialog, IDS_DRIVE_NO_C), SW_HIDE); free(subKeyName); /* disable or enable controls depending on whether we are editing global vs app specific config */ if (appSettings == EDITING_GLOBAL) { WINE_TRACE("enabling controls\n"); enable(IDC_LIST_DRIVES); enable(IDC_BUTTON_ADD); enable(IDC_BUTTON_REMOVE); enable(IDC_BUTTON_EDIT); enable(IDC_BUTTON_AUTODETECT); } else { WINE_TRACE("disabling controls\n"); disable(IDC_LIST_DRIVES); disable(IDC_BUTTON_ADD); disable(IDC_BUTTON_REMOVE); disable(IDC_BUTTON_EDIT); disable(IDC_BUTTON_AUTODETECT); } void refreshDriveEditDialog(HWND dialog) { fill_drive_droplist( drive_available_mask( editWindowLetter ), editWindowLetter, dialog ); SetWindowText(GetDlgItem(dialog, IDC_EDIT_PATH), path); SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_ADDSTRING, 0, SendDlgItemMessage(dialog, IDC_COMBO_TYPE, CB_SETCURSEL, selection, 0); SendDlgItemMessage(dialog, IDC_COMBO_NAMES, CB_ADDSTRING, 0, SendDlgItemMessage(dialog, IDC_COMBO_NAMES, CB_SETCURSEL, selection, 0); SendDlgItemMessage(dialog, IDC_EDIT_SERIAL, WM_SETTEXT, 0,(LPARAM)serial); SendDlgItemMessage(dialog, IDC_EDIT_LABEL, WM_SETTEXT, 0,(LPARAM)label); SendDlgItemMessage(dialog, IDC_EDIT_DEVICE, WM_SETTEXT, 0,(LPARAM)device); enable_labelserial_box(dialog, BOX_MODE_CD_AUTODETECT); enable_labelserial_box(dialog, BOX_MODE_CD_ASSIGN); enable_labelserial_box(dialog, BOX_MODE_NORMAL); CheckRadioButton( dialog, IDC_RADIO_AUTODETECT, IDC_RADIO_ASSIGN, selection ); if (path) SendDlgItemMessage(dialog, IDC_EDIT_PATH, WM_SETTEXT, 0,(LPARAM)path); if (doesConfigValueExist(section, "Desktop") == S_OK) { updatingUI = TRUE; buf = getConfigValue(section, "Desktop", "640x480"); SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_RESETCONTENT, 0, 0); buf = getConfigValue(section, "ScreenDepth", "24"); buf = getConfigValue(section, "DXGrab", "Y"); buf = getConfigValue(section, "DesktopDoubleBuffered", "Y"); buf = getConfigValue(section, "UseTakeFocus", "N"); addTransaction(section, "Desktop", ACTION_SET, newStr); addTransaction(section, "Desktop", ACTION_REMOVE, NULL); addTransaction(section, "ScreenDepth", ACTION_SET, newvalue); addTransaction(section, "DXGrab", ACTION_SET, "Y"); addTransaction(section, "DXGrab", ACTION_SET, "N"); addTransaction(section, "DesktopDoubleBuffered", ACTION_SET, "Y"); addTransaction(section, "DesktopDoubleBuffered", ACTION_SET, "N"); addTransaction(section, "UseTakeFocus", ACTION_SET, "Y"); addTransaction(section, "UseTakeFocus", ACTION_SET, "N"); if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updatingUI ) setFromDesktopSizeEdits(hDlg); if (updatingUI) break; #define IDC_DX_MOUSE_GRAB 1078 #define IDC_USE_TAKE_FOCUS 1079 #define IDC_DOUBLE_BUFFER 1080 buf = getConfigValue("x11drv", "DXGrab", "Y"); CheckDlgButton(hDlg, IDC_DX_MOUSE_GRAB, BST_CHECKED); CheckDlgButton(hDlg, IDC_DX_MOUSE_GRAB, BST_UNCHECKED); free(buf); buf = getConfigValue("x11drv", "DesktopDoubleBuffered", "Y"); if (IS_OPTION_TRUE(*buf)) CheckDlgButton(hDlg, IDC_DOUBLE_BUFFER, BST_CHECKED); else CheckDlgButton(hDlg, IDC_DOUBLE_BUFFER, BST_UNCHECKED); free(buf); buf = getConfigValue("x11drv", "UseTakeFocus", "N"); if (IS_OPTION_TRUE(*buf)) CheckDlgButton(hDlg, IDC_USE_TAKE_FOCUS, BST_CHECKED); else CheckDlgButton(hDlg, IDC_USE_TAKE_FOCUS, BST_UNCHECKED); free(buf); void onDXMouseGrabClicked(HWND hDlg) { if (IsDlgButtonChecked(hDlg, IDC_DX_MOUSE_GRAB) == BST_CHECKED) addTransaction("x11drv", "DXGrab", ACTION_SET, "Y"); addTransaction("x11drv", "DXGrab", ACTION_SET, "N"); void onDoubleBufferClicked(HWND hDlg) { if (IsDlgButtonChecked(hDlg, IDC_DOUBLE_BUFFER) == BST_CHECKED) addTransaction("x11drv", "DesktopDoubleBuffered", ACTION_SET, "Y"); else addTransaction("x11drv", "DesktopDoubleBuffered", ACTION_SET, "N"); } void onUseTakeFocusClicked(HWND hDlg) { if (IsDlgButtonChecked(hDlg, IDC_USE_TAKE_FOCUS) == BST_CHECKED) addTransaction("x11drv", "UseTakeFocus", ACTION_SET, "Y"); else addTransaction("x11drv", "UseTakeFocus", ACTION_SET, "N"); } case IDC_DX_MOUSE_GRAB: onDXMouseGrabClicked(hDlg); break; case IDC_USE_TAKE_FOCUS: onUseTakeFocusClicked(hDlg); break; case IDC_DOUBLE_BUFFER: onDoubleBufferClicked(hDlg); break; #define IDC_SCREEN_DEPTH 1077 * - Clean up resource.h, it's a bog char *bufindex; bufindex = strchr(buf, 'x'); *bufindex = '\0'; bufindex++; SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), bufindex); free(buf); SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "8 bit"); SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "16 bit"); SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "24 bit"); SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "32 bit"); /* is this valid? */ buf = getConfigValue("x11drv", "ScreenDepth", "24"); if (strcmp(buf, "8") == 0) SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 0, 0); else if (strcmp(buf, "16") == 0) SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 1, 0); else if (strcmp(buf, "24") == 0) SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 2, 0); else if (strcmp(buf, "32") == 0) SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 3, 0); else WINE_ERR("Invalid screen depth read from registry (%s)\n", buf); void onScreenDepthChanged(HWND hDlg) { char *newvalue = getDialogItemText(hDlg, IDC_SCREEN_DEPTH); char *spaceIndex = strchr(newvalue, ' '); WINE_TRACE("newvalue=%s\n", newvalue); *spaceIndex = '\0'; addTransaction("x11drv", "ScreenDepth", ACTION_SET, newvalue); case CBN_SELCHANGE: { if (LOWORD(wParam) == IDC_SCREEN_DEPTH) onScreenDepthChanged(hDlg); break; } #define IDC_ENABLE_MANAGED 1076 * Minor things that should be done someday: * - Make the desktop size UI a combo box, with a Custom option, so it's more obvious what you might want to choose here * SendDlgItemMessage(hDlg, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0); buf = getConfigValue("x11drv", "AllocSysColors", "100"); SetWindowText(GetDlgItem(hDlg, IDC_SYSCOLORS), buf); free(buf); buf = getConfigValue("x11drv", "Managed", "Y"); if (IS_OPTION_TRUE(*buf)) CheckDlgButton(hDlg, IDC_ENABLE_MANAGED, BST_CHECKED); else CheckDlgButton(hDlg, IDC_ENABLE_MANAGED, BST_UNCHECKED); void onSysColorsChange(HWND hDlg) { char *newvalue = getDialogItemText(hDlg, IDC_SYSCOLORS); WINE_TRACE("\n"); if (updatingUI) return; if (!newvalue) return; addTransaction("x11drv", "AllocSystemColors", ACTION_SET, newvalue); free(newvalue); } void onEnableManagedClicked(HWND hDlg) { if (IsDlgButtonChecked(hDlg, IDC_ENABLE_MANAGED) == BST_CHECKED) addTransaction("x11drv", "Managed", ACTION_SET, "Y"); else addTransaction("x11drv", "Managed", ACTION_SET, "N"); } if (LOWORD(wParam) == IDC_SYSCOLORS) onSysColorsChange(hDlg); case IDC_ENABLE_MANAGED: onEnableManagedClicked(hDlg); break; static int lastSel = 0; /* the last drive selected in the property sheet */ /* call with newValue == NULL to remove a value */ if (newValue) addTransaction(driveSection, valueName, ACTION_SET, newValue); else addTransaction(driveSection, valueName, ACTION_REMOVE, NULL); /* copies a drive configuration branch */ void copyDrive(char srcLetter, char destLetter) { char *driveSection = alloca(strlen("Drive X")+1); char *path, *label, *type, *serial, *fs; WINE_TRACE("srcLetter=%c, destLetter=%c\n", srcLetter, destLetter); sprintf(driveSection, "Drive %c", srcLetter); path = getDriveValue(srcLetter, "Path"); label = getDriveValue(srcLetter, "Label"); type = getDriveValue(srcLetter, "Type"); serial = getDriveValue(srcLetter, "Serial"); fs = getDriveValue(srcLetter, "FileSystem"); sprintf(driveSection, "Drive %c", destLetter); if (path) addTransaction(driveSection, "Path", ACTION_SET, path); if (label) addTransaction(driveSection, "Label", ACTION_SET, label); if (type) addTransaction(driveSection, "Type", ACTION_SET, type); if (serial) addTransaction(driveSection, "Serial", ACTION_SET, serial); if (fs) addTransaction(driveSection, "FileSystem", ACTION_SET, fs); if (path) free(path); if (label) free(label); if (type) free(type); if (serial) free(serial); if (fs) free(fs); } void removeDrive(char letter) { char *driveSection = alloca(strlen("Drive X")+1); sprintf(driveSection, "Drive %c", letter); addTransaction(driveSection, NULL, ACTION_REMOVE, NULL); } int refreshDriveDlg (HWND hDlg) DWORD sizeOfSubKeyName = MAX_NAME_LENGTH; int doesDriveCExist = FALSE; ++i, sizeOfSubKeyName = MAX_NAME_LENGTH) { WINE_TRACE("%s\n", subKeyName); char *device; return -1; if (driveLetter) driveLetter = toupper(driveLetter); if (driveLetter == 'C') doesDriveCExist = TRUE; device = getDriveValue(driveLetter, "Device"); WINE_TRACE("Adding %c: label=%s to the listbox, device=%s\n", driveLetter, label, device); /* fixup label */ if (!label && device) { label = malloc(strlen("[label read from device ]")+1+strlen(device)); sprintf(label, "[label read from device %s]", device); } if (!label) label = strdup("(no label)"); snprintf(title, titleLen, "Drive %c: %s", driveLetter, label); free(label); SendDlgItemMessage(hDlg, IDC_LIST_DRIVES, LB_SETSEL, TRUE, lastSel); /* show the warning if there is no Drive C */ if (!doesDriveCExist) ShowWindow(GetDlgItem(hDlg, IDS_DRIVE_NO_C), SW_NORMAL); else ShowWindow(GetDlgItem(hDlg, IDS_DRIVE_NO_C), SW_HIDE); return driveCount; typedef struct { int index; sName[0] = 'A' + i; index = SendDlgItemMessage( hDlg, IDC_COMBO_LETTER, CB_ADDSTRING, 0, (LPARAM) sName ); #define BOX_MODE_CD_ASSIGN 1 #define BOX_MODE_CD_AUTODETECT 2 #define BOX_MODE_NONE 3 #define BOX_MODE_NORMAL 4 void enable_labelserial_box(HWND hDlg, int mode) WINE_TRACE("mode=%d\n", mode); switch (mode) { case BOX_MODE_CD_ASSIGN: EnableWindow( GetDlgItem( hDlg, IDC_RADIO_AUTODETECT ), 1 ); EnableWindow( GetDlgItem( hDlg, IDC_RADIO_ASSIGN ), 1 ); EnableWindow( GetDlgItem( hDlg, IDC_EDIT_DEVICE ), 0 ); EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_BROWSE_DEVICE ), 0 ); EnableWindow( GetDlgItem( hDlg, IDC_EDIT_SERIAL ), 1 ); EnableWindow( GetDlgItem( hDlg, IDC_EDIT_LABEL ), 1 ); EnableWindow( GetDlgItem( hDlg, IDC_STATIC_SERIAL ), 1); EnableWindow( GetDlgItem( hDlg, IDC_STATIC_LABEL ), 1); break; case BOX_MODE_CD_AUTODETECT: EnableWindow( GetDlgItem( hDlg, IDC_RADIO_AUTODETECT ), 1 ); EnableWindow( GetDlgItem( hDlg, IDC_RADIO_ASSIGN ), 1 ); EnableWindow( GetDlgItem( hDlg, IDC_EDIT_DEVICE ), 1 ); EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_BROWSE_DEVICE ), 1 ); EnableWindow( GetDlgItem( hDlg, IDC_EDIT_SERIAL ), 0 ); EnableWindow( GetDlgItem( hDlg, IDC_EDIT_LABEL ), 0 ); EnableWindow( GetDlgItem( hDlg, IDC_STATIC_SERIAL ), 0); EnableWindow( GetDlgItem( hDlg, IDC_STATIC_LABEL ), 0); break; case BOX_MODE_NONE: EnableWindow( GetDlgItem( hDlg, IDC_RADIO_AUTODETECT ), 0 ); EnableWindow( GetDlgItem( hDlg, IDC_RADIO_ASSIGN ), 0 ); EnableWindow( GetDlgItem( hDlg, IDC_EDIT_DEVICE ), 0 ); EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_BROWSE_DEVICE ), 0 ); EnableWindow( GetDlgItem( hDlg, IDC_EDIT_SERIAL ), 0 ); EnableWindow( GetDlgItem( hDlg, IDC_EDIT_LABEL ), 0 ); EnableWindow( GetDlgItem( hDlg, IDC_STATIC_SERIAL ), 0); EnableWindow( GetDlgItem( hDlg, IDC_STATIC_LABEL ), 0); break; case BOX_MODE_NORMAL: EnableWindow( GetDlgItem( hDlg, IDC_RADIO_AUTODETECT ), 0 ); EnableWindow( GetDlgItem( hDlg, IDC_RADIO_ASSIGN ), 1 ); EnableWindow( GetDlgItem( hDlg, IDC_EDIT_DEVICE ), 0 ); EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_BROWSE_DEVICE ), 0 ); EnableWindow( GetDlgItem( hDlg, IDC_EDIT_SERIAL ), 1 ); EnableWindow( GetDlgItem( hDlg, IDC_EDIT_LABEL ), 1 ); EnableWindow( GetDlgItem( hDlg, IDC_STATIC_SERIAL ), 1); EnableWindow( GetDlgItem( hDlg, IDC_STATIC_LABEL ), 1); break; } if ((type && strcmp("cdrom", type) == 0) || (type && strcmp("floppy", type) == 0)) { if (device) { enable_labelserial_box(hDlg, BOX_MODE_CD_AUTODETECT); } else { selection = IDC_RADIO_ASSIGN; enable_labelserial_box(hDlg, BOX_MODE_CD_ASSIGN); } else { enable_labelserial_box(hDlg, BOX_MODE_NORMAL); case IDC_EDIT_LABEL: { if (label) free(label); case IDC_EDIT_PATH: { char *path = getDialogItemText(hDlg, controlID); if (!path) path = strdup("fake_windows"); /* default to assuming fake_windows in the .wine directory */ setDriveValue(editWindowLetter, "Path", path); free(path); break; } case IDC_EDIT_SERIAL: { char *serial = getDialogItemText(hDlg, controlID); setDriveValue(editWindowLetter, "Serial", serial); if (serial) free (serial); break; } case IDC_EDIT_DEVICE: { char *device = getDialogItemText(hDlg,controlID); setDriveValue(editWindowLetter, "Device", device); if (device) free(device); refreshDriveDlg(driveDlgHandle); break; } if (HIWORD(wParam) != CBN_SELCHANGE) break; selection = SendDlgItemMessage( hDlg, IDC_COMBO_TYPE, CB_GETCURSEL, 0, 0); if( selection == 2 || selection == 3 ) { /* cdrom or floppy */ if (IsDlgButtonChecked(hDlg, IDC_RADIO_AUTODETECT)) enable_labelserial_box(hDlg, BOX_MODE_CD_AUTODETECT); else enable_labelserial_box(hDlg, BOX_MODE_CD_ASSIGN); } else { enable_labelserial_box( hDlg, BOX_MODE_NORMAL ); setDriveValue(editWindowLetter, "Type", type_pairs[selection].sCode); break; case IDC_COMBO_LETTER: { int item = SendDlgItemMessage(hDlg, IDC_COMBO_LETTER, CB_GETCURSEL, 0, 0); char newLetter; SendDlgItemMessage(hDlg, IDC_COMBO_LETTER, CB_GETLBTEXT, item, (LPARAM) &newLetter); if (HIWORD(wParam) != CBN_SELCHANGE) break; if (newLetter == editWindowLetter) break; WINE_TRACE("changing drive letter to %c\n", newLetter); copyDrive(editWindowLetter, newLetter); removeDrive(editWindowLetter); editWindowLetter = newLetter; refreshDriveDlg(driveDlgHandle); break; } case IDC_BUTTON_BROWSE_PATH: WRITEME(hDlg); break; case IDC_RADIO_AUTODETECT: { setDriveValue(editWindowLetter, "Label", NULL); setDriveValue(editWindowLetter, "Serial", NULL); setDriveValue(editWindowLetter, "Device", getDialogItemText(hDlg, IDC_EDIT_DEVICE)); enable_labelserial_box(hDlg, BOX_MODE_CD_AUTODETECT); refreshDriveDlg(driveDlgHandle); break; } case IDC_RADIO_ASSIGN: setDriveValue(editWindowLetter, "Device", NULL); setDriveValue(editWindowLetter, "Label", getDialogItemText(hDlg, IDC_EDIT_LABEL)); setDriveValue(editWindowLetter, "Serial", getDialogItemText(hDlg, IDC_EDIT_SERIAL)); enable_labelserial_box(hDlg, BOX_MODE_CD_ASSIGN); refreshDriveDlg(driveDlgHandle); char newLetter = 'C'; /* we skip A and B, they are historically floppy drives */ if (newLetter == 'C') { addTransaction(sectionName, "Path", ACTION_SET, "fake_windows"); addTransaction(sectionName, "Label", ACTION_SET, "System Drive"); } else addTransaction(sectionName, "Path", ACTION_SET, "/"); /* default to root path */ DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DRIVE_EDIT), NULL, (DLGPROC) DriveEditDlgProc, (LPARAM) newLetter); int nItem; char letter; if (HIWORD(wParam) == LBN_DBLCLK) selection = -1; if (HIWORD(wParam) == LBN_SELCHANGE) lastSel = SendDlgItemMessage(hDlg, IDC_LIST_DRIVES, LB_GETCURSEL, 0, 0); if (HIWORD(wParam) != BN_CLICKED) break; nItem = SendDlgItemMessage(hDlg, IDC_LIST_DRIVES, LB_GETCURSEL, 0, 0); letter = SendDlgItemMessage(hDlg, IDC_LIST_DRIVES, LB_GETITEMDATA, nItem, 0); removeDrive(letter); refreshDriveDlg(driveDlgHandle); if (HIWORD(wParam) != BN_CLICKED) break; nItem = SendMessage(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_GETCURSEL, 0, 0); letter = SendMessage(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_GETITEMDATA, nItem, 0); DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DRIVE_EDIT), NULL, (DLGPROC) DriveEditDlgProc, (LPARAM) letter); break; case IDC_BUTTON_AUTODETECT: WRITEME(hDlg); #define IDD_DRIVE_EDIT 114 #define IDS_DRIVE_NO_C 1075 /* removes the requested configuration section (subkey) from the registry, assuming it exists */ /* this function might be slightly pointless, but in future we may wish to treat recursion specially etc, so we'll keep it for now */ HRESULT removeConfigSection(char *section) { HRESULT hr; WINE_TRACE("section=%s\n", section); return hr = RegDeleteKey(configKey, section); } if (trans->key) free(trans->key); struct transaction *trans = calloc(sizeof(struct transaction),1); if (action == ACTION_SET) assert( key != NULL ); if (key) trans->key = strdup(key); if (newValue) trans->newValue = strdup(newValue); if (trans->key) { WINE_TRACE("Removing %s\\%s\n", trans->section, trans->key); removeConfigValue(trans->section, trans->key); } else { /* NULL key means remove that section entirely */ WINE_TRACE("Removing section %s\n", trans->section); removeConfigSection(trans->section); } #define WRITEME(owner) MessageBox(owner, "Write me!", "", MB_OK | MB_ICONEXCLAMATION); #include case WM_MOUSEWHEEL: { int wheelDelta = 0; UINT scrollLines = 3; int curPos = GetScrollPos(hWnd, SB_VERT); int min, max; GetScrollRange(hWnd, SB_VERT, &min, &max); SystemParametersInfo(SPI_GETWHEELSCROLLLINES,0, &scrollLines, 0); if (wParam & (MK_SHIFT | MK_CONTROL)) return DefWindowProc(hWnd, msg, wParam, lParam); wheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam); if (abs(wheelDelta) >= WHEEL_DELTA && scrollLines) { int dy; curPos += wheelDelta; if (curPos > max) curPos = max; else if (curPos < min) curPos = min; dy = GetScrollPos(hWnd, SB_VERT) - curPos; SetScrollPos(hWnd, SB_VERT, curPos, TRUE); ScrollWindow(hWnd, 0, dy, NULL, NULL); UpdateWindow(hWnd); } } break; /* normalize the version strings */ if (!strcmp(curWinVer, "win2000") || !strcmp(curWinVer, "nt2k") || !strcmp(curWinVer, "nt2000")) { free(curWinVer); curWinVer = strdup("win2k"); } if (!strcmp(curWinVer, "win2k3")) { free(curWinVer); curWinVer = strdup("win2003"); } {"win2003", "Windows 2003"}, * TODO: (in rough order of priority) * - A mind bogglingly vast amount of stuff * * - Complete X11DRV page, so all controls are hooked up * - Implement autodetect for drive configuration * - Figure out whether we need the virtual vs real drive selection stuff at the top of the property page * - Implement explicit mode vs instant-apply mode * - AppDefaults handling * - DLL editing * - Make a list of prefs that have been dropped from the UI/should be eliminated * - Multimedia page * - Settings migration code (from old configs) * * Copyright 2003 Mike Hearn ULONG size; HRESULT hr; /* find the buffer size of the marshalled dispatch interface */ hr = CoGetMarshalSizeMax(&size, &IID_IDispatch, (IUnknown*)V_DISPATCH(pvar), LOWORD(*pFlags), NULL, MSHLFLAGS_NORMAL); if (FAILED(hr)) { ERR("Dispatch variant buffer size calculation failed, HRESULT=0x%lx\n", hr); return 0; } size += sizeof(ULONG); /* we have to store the buffersize in the stream */ TRACE("wire-size extra of dispatch variant is %ld\n", size); return size; /* helper: called for VT_DISPATCH variants to marshal the IDispatch* into the buffer. returns Buffer on failure, new position otherwise */ static unsigned char* dispatch_variant_marshal(unsigned long *pFlags, unsigned char *Buffer, VARIANT *pvar) { IStream *working; HGLOBAL working_mem; void *working_memlocked; unsigned char *oldpos; ULONG size; HRESULT hr; TRACE("pFlags=%ld, Buffer=%p, pvar=%p\n", *pFlags, Buffer, pvar); oldpos = Buffer; /* CoMarshalInterface needs a stream, whereas at this level we are operating in terms of buffers. * We create a stream on an HGLOBAL, so we can simply do a memcpy to move it to the buffer. * in rpcrt4/ndr_ole.c, a simple IStream implementation is wrapped around the buffer object, * but that would be overkill here, hence this implementation. We save the size because the unmarshal * code has no way to know how long the marshalled buffer is. */ size = wire_extra(pFlags, pvar); working_mem = GlobalAlloc(0, size); if (!working_mem) return oldpos; hr = CreateStreamOnHGlobal(working_mem, TRUE, &working); if (hr != S_OK) { GlobalFree(working_mem); return oldpos; } hr = CoMarshalInterface(working, &IID_IDispatch, (IUnknown*)V_DISPATCH(pvar), LOWORD(*pFlags), NULL, MSHLFLAGS_NORMAL); if (hr != S_OK) { IStream_Release(working); /* this also releases the hglobal */ return oldpos; } working_memlocked = GlobalLock(working_mem); memcpy(Buffer, &size, sizeof(ULONG)); /* copy the buffersize */ Buffer += sizeof(ULONG); memcpy(Buffer, working_memlocked, size); GlobalUnlock(working_mem); IStream_Release(working); TRACE("done, size=%ld\n", sizeof(ULONG) + size); return Buffer + sizeof(ULONG) + size; } /* helper: called for VT_DISPATCH variants to unmarshal the buffer back into a dispatch variant. returns Buffer on failure, new position otherwise */ static unsigned char *dispatch_variant_unmarshal(unsigned long *pFlags, unsigned char *Buffer, VARIANT *pvar) { IStream *working; HGLOBAL working_mem; void *working_memlocked; unsigned char *oldpos; ULONG size; HRESULT hr; TRACE("pFlags=%ld, Buffer=%p, pvar=%p\n", *pFlags, Buffer, pvar); oldpos = Buffer; /* get the buffersize */ memcpy(&size, Buffer, sizeof(ULONG)); TRACE("buffersize=%ld\n", size); Buffer += sizeof(ULONG); working_mem = GlobalAlloc(0, size); if (!working_mem) return oldpos; hr = CreateStreamOnHGlobal(working_mem, TRUE, &working); if (hr != S_OK) { GlobalFree(working_mem); return oldpos; } working_memlocked = GlobalLock(working_mem); /* now we copy the contents of the marshalling buffer to working_memlocked, unlock it, and demarshal the stream */ memcpy(working_memlocked, Buffer, size); GlobalUnlock(working_mem); hr = CoUnmarshalInterface(working, &IID_IDispatch, (void**)&V_DISPATCH(pvar)); if (hr != S_OK) { IStream_Release(working); return oldpos; } IStream_Release(working); /* this also frees the underlying hglobal */ TRACE("done, processed=%ld bytes\n", sizeof(ULONG) + size); return Buffer + sizeof(ULONG) + size; } case VT_DISPATCH | VT_BYREF: FIXME("handle DISPATCH by ref\n"); break; case VT_DISPATCH: /* this should probably call WdtpInterfacePointer_UserMarshal in ole32.dll */ Pos = dispatch_variant_marshal(pFlags, Pos, pvar); break; case VT_DISPATCH: Pos = dispatch_variant_unmarshal(pFlags, Pos, pvar); break; case VT_DISPATCH | VT_BYREF: FIXME("handle DISPATCH by ref\n"); subKeyName = malloc(strlen("Drive X")+1); void setDriveValue(char letter, char *valueName, char *newValue) { char *driveSection = malloc(strlen("Drive X")+1); sprintf(driveSection, "Drive %c", letter); addTransaction(driveSection, valueName, ACTION_SET, newValue); free(driveSection); } void refreshDriveDlg (HWND hDlg) if (label && (strcmp(label, "no label") != 0)) free(label); SendMessageA(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_SETSEL, TRUE, 0); result = ~result; if (letter) result |= DRIVE_MASK_BIT(letter); selection = IDC_RADIO_ASSIGN; if ((type && strcmp("cdrom", type) == 0) || (type && strcmp("floppy", type) == 0)) { if( (type && (strlen( device ) == 0)) && ((serial && strlen( serial ) > 0) || (label && strlen( label ) > 0)) ) { if (path) SendDlgItemMessage(hDlg, IDC_EDIT_PATH, WM_SETTEXT, 0,(LPARAM)path); /* storing the drive propsheet HWND here is a bit ugly, but the simplest solution for now */ static HWND driveDlgHandle; void onEditChanged(HWND hDlg, WORD controlID) { WINE_TRACE("controlID=%d\n", controlID); switch (controlID) { case IDC_EDIT_LABEL: { /* drive label edit box */ char *label = getDialogItemText(hDlg, controlID); setDriveValue(editWindowLetter, "Label", label); refreshDriveDlg(driveDlgHandle); free(label); break; } } } case ID_BUTTON_OK: if (HIWORD(wParam) == EN_CHANGE) onEditChanged(hDlg, LOWORD(wParam)); break; void onAddDriveClicked(HWND hDlg) { /* we should allocate a drive letter automatically. We also need some way to let the user choose the mapping point, for now we will just force them to enter a path automatically, with / being the default. In future we should be able to temporarily map / then invoke the directory chooser dialog. */ char newLetter = 'D'; /* we skip A, B and of course C is already mapped, right? */ long mask = ~drive_available_mask(0); /* the mask is now which drives aren't available */ char *sectionName; while (mask & (1 << (newLetter - 'A'))) { newLetter++; if (newLetter > 'Z') { MessageBox(NULL, "You cannot add any more drives.\n\nEach drive must have a letter, from A to Z, so you cannot have more than 26", "", MB_OK | MB_ICONEXCLAMATION); return; } } WINE_TRACE("allocating drive letter %c\n", newLetter); sectionName = malloc(strlen("Drive X") + 1); sprintf(sectionName, "Drive %c", newLetter); addTransaction(sectionName, "Path", ACTION_SET, "/"); /* default to root path */ addTransaction(sectionName, "Type", ACTION_SET, "hd"); processTransQueue(); /* make sure the drive has been added, even if we are not in instant apply mode */ free(sectionName); refreshDriveDlg(driveDlgHandle); DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DRIVE_EDIT2), NULL, (DLGPROC) DriveEditDlgProc, (LPARAM) newLetter); } break; onAddDriveClicked(hDlg); driveDlgHandle = hDlg; refreshDriveDlg (driveDlgHandle); * setConfigValue : Sets a configuration key in the registry. Section will be created if it doesn't already exist trans->section = strdup(section); trans->key = strdup(key); trans->newValue = strdup(newValue); if (instantApply) { processTransaction(trans); destroyTransaction(trans); } void processTransQueue(void) { while (tqtail != NULL) { struct transaction *next = tqtail->next; processTransaction(tqtail); destroyTransaction(tqtail); tqtail = next; /* ================================== utility functions ============================ */ /* returns a string with the window text of the dialog item. user is responsible for freeing the result */ char *getDialogItemText(HWND hDlg, WORD controlID) { HWND item = GetDlgItem(hDlg, controlID); int len = GetWindowTextLength(item) + 1; char *result = malloc(len); if (GetWindowText(item, result, len) == 0) return NULL; return result; } /* some basic utilities to make win32 suck less */ char *getDialogItemText(HWND hDlg, WORD controlID); static BOOL updatingUI = FALSE; static char editWindowLetter; /* drive letter of the drive we are currently editing */ /* returns NULL on failure. caller is responsible for freeing result */ char *getDriveValue(char letter, char *valueName) { HKEY hkDrive = 0; char *subKeyName; char *result = NULL; HRESULT hr; DWORD bufferSize; WINE_TRACE("letter=%c, valueName=%s\n", letter, valueName); subKeyName = malloc(strlen("Drive X")); sprintf(subKeyName, "Drive %c", letter); hr = RegOpenKeyEx(configKey, subKeyName, 0, KEY_READ, &hkDrive); if (hr != ERROR_SUCCESS) goto end; hr = RegQueryValueEx(hkDrive, valueName, NULL, NULL, NULL, &bufferSize); if (hr != ERROR_SUCCESS) goto end; result = malloc(bufferSize); hr = RegQueryValueEx(hkDrive, valueName, NULL, NULL, result, &bufferSize); if (hr != ERROR_SUCCESS) goto end; end: if (hkDrive) RegCloseKey(hkDrive); free(subKeyName); return result; void initDriveDlg (HWND hDlg) { int i; char *subKeyName = malloc(MAX_NAME_LENGTH); int driveCount = 0; DWORD sizeOfSubKeyName; WINE_TRACE("\n"); updatingUI = TRUE; /* Clear the listbox */ SendMessageA(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_RESETCONTENT, 0, 0); for (i = 0; RegEnumKeyExA(configKey, i, subKeyName, &sizeOfSubKeyName, NULL, NULL, NULL, NULL ) != ERROR_NO_MORE_ITEMS; ++i, sizeOfSubKeyName = 50) { HKEY hkDrive; char returnBuffer[MAX_NAME_LENGTH]; DWORD sizeOfReturnBuffer = sizeof(returnBuffer); LONG r; if (!strncmp("Drive ", subKeyName, 5)) { char driveLetter = '\0'; char *label; char *title; int titleLen; const char *itemLabel = "Drive %s (%s)"; int itemIndex; if (RegOpenKeyExA (configKey, subKeyName, 0, KEY_READ, &hkDrive) != ERROR_SUCCESS) { WINE_ERR("unable to open drive registry key"); RegCloseKey(configKey); return; } /* extract the drive letter, force to upper case */ driveLetter = subKeyName[strlen(subKeyName)-1]; if(driveLetter) driveLetter = toupper(driveLetter); ZeroMemory(returnBuffer, sizeof(*returnBuffer)); sizeOfReturnBuffer = sizeof(returnBuffer); r = RegQueryValueExA(hkDrive, "Label", NULL, NULL, returnBuffer, &sizeOfReturnBuffer); if (r == ERROR_SUCCESS) { label = malloc(sizeOfReturnBuffer); strncpy(label, returnBuffer, sizeOfReturnBuffer); } else { WINE_WARN("label not loaded: %ld\n", r); label = NULL; } /* We now know the label and drive letter, so we can add to the list. The list items will have the letter associated * with them, which acts as the key. We can then use that letter to get/set the properties of the drive. */ WINE_TRACE("Adding %c (%s) to the listbox\n", driveLetter, label); if (!label) label = "no label"; titleLen = strlen(itemLabel) - 1 + strlen(label) - 2 + 1; title = malloc(titleLen); /* the %s in the item label will be replaced by the drive letter, so -1, then -2 for the second %s which will be expanded to the label, finally + 1 for terminating #0 */ snprintf(title, titleLen, "Drive %c (%s)", driveLetter, label); /* the first SendMessage call adds the string and returns the index, the second associates that index with it */ itemIndex = SendMessageA(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_ADDSTRING ,(WPARAM) -1, (LPARAM) title); SendMessageA(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_SETITEMDATA, itemIndex, (LPARAM) driveLetter); free(title); free(label); driveCount++; } } WINE_TRACE("loaded %d drives\n", driveCount); free(subKeyName); updatingUI = FALSE; return; } void fill_drive_droplist(long mask, char currentLetter, HWND hDlg) if( toupper(currentLetter) == 'A' + i ) { /* This function produces a mask for each drive letter that isn't currently used. Each bit of the long result * represents a letter, with A being the least significant bit, and Z being the most significant. * * To calculate this, we loop over each letter, and see if we can get a drive entry for it. If so, we * set the appropriate bit. At the end, we flip each bit, to give the desired result. * * The letter parameter is always marked as being available. This is so the edit dialog can display the * currently used drive letter alongside the available ones. */ long drive_available_mask(char letter) { long result = 0; char curLetter; char *slop; WINE_TRACE("\n"); for (curLetter = 'A'; curLetter < 'Z'; curLetter++) { slop = getDriveValue(curLetter, "Path"); if (slop != NULL) { result |= DRIVE_MASK_BIT(curLetter); free(slop); } } result = ~result; result |= DRIVE_MASK_BIT(letter); WINE_TRACE( "finished drive letter loop with %lx\n", result ); return result; } void refreshDriveEditDialog(HWND hDlg) { char *path; char *type; char *fs; char *serial; char *label; char *device; int i, selection; updatingUI = TRUE; /* Drive letters */ fill_drive_droplist( drive_available_mask( editWindowLetter ), editWindowLetter, hDlg ); /* path */ path = getDriveValue(editWindowLetter, "Path"); if (path) { SetWindowText(GetDlgItem(hDlg, IDC_EDIT_PATH), path); } else WINE_WARN("no Path field?\n"); /* drive type */ type = getDriveValue(editWindowLetter, "Type"); if (type) { for(i = 0, selection = -1; i < sizeof(type_pairs)/sizeof(code_desc_pair); i++) { SendDlgItemMessage(hDlg, IDC_COMBO_TYPE, CB_ADDSTRING, 0, (LPARAM) type_pairs[i].sDesc); if(strcasecmp(type_pairs[i].sCode, type) == 0){ selection = i; } } if( selection == -1 ) selection = DRIVE_TYPE_DEFAULT; SendDlgItemMessage(hDlg, IDC_COMBO_TYPE, CB_SETCURSEL, selection, 0); } else WINE_WARN("no Type field?\n"); /* FileSystem name handling */ fs = getDriveValue(editWindowLetter, "FileSystem"); if (fs) { for( i=0, selection=-1; i < sizeof(fs_pairs)/sizeof(code_desc_pair); i++) { SendDlgItemMessage(hDlg, IDC_COMBO_NAMES, CB_ADDSTRING, 0, (LPARAM) fs_pairs[i].sDesc); if(strcasecmp(fs_pairs[i].sCode, fs) == 0){ selection = i; } } if( selection == -1 ) selection = DRIVE_FS_DEFAULT; SendDlgItemMessage(hDlg, IDC_COMBO_NAMES, CB_SETCURSEL, selection, 0); } else WINE_WARN("no FileSystem field?\n"); /* removeable media properties */ serial = getDriveValue(editWindowLetter, "Serial"); if (serial) { SendDlgItemMessage(hDlg, IDC_EDIT_SERIAL, WM_SETTEXT, 0,(LPARAM)serial); } else WINE_WARN("no Serial field?\n"); label = getDriveValue(editWindowLetter, "Label"); if (label) { SendDlgItemMessage(hDlg, IDC_EDIT_LABEL, WM_SETTEXT, 0,(LPARAM)label); } else WINE_WARN("no Label field?\n"); device = getDriveValue(editWindowLetter, "Device"); if (device) { SendDlgItemMessage(hDlg, IDC_EDIT_DEVICE, WM_SETTEXT, 0,(LPARAM)device); } else WINE_WARN("no Device field?\n"); if( strcmp("cdrom", type) == 0 || strcmp("floppy", type) == 0) { if( (strlen( device ) == 0) && ((strlen( serial ) > 0) || (strlen( label ) > 0)) ) { selection = IDC_RADIO_ASSIGN; } else { selection = IDC_RADIO_AUTODETECT; } enable_labelserial_box( hDlg, 1 ); } else { enable_labelserial_box( hDlg, 0 ); selection = IDC_RADIO_ASSIGN; } CheckRadioButton( hDlg, IDC_RADIO_AUTODETECT, IDC_RADIO_ASSIGN, selection ); SendDlgItemMessage(hDlg, IDC_EDIT_PATH, WM_SETTEXT, 0,(LPARAM)path); if (path) free(path); if (type) free(type); if (fs) free(fs); if (serial) free(serial); if (label) free(label); if (device) free(device); updatingUI = FALSE; return; } case WM_INITDIALOG: { editWindowLetter = (char) lParam; refreshDriveEditDialog(hDlg); switch (LOWORD(wParam)) { case IDC_COMBO_TYPE: switch( HIWORD(wParam)) { case CBN_SELCHANGE: selection = SendDlgItemMessage( hDlg, IDC_COMBO_TYPE, CB_GETCURSEL, 0, 0); if( selection == 2 || selection == 3 ) { /* cdrom or floppy */ enable_labelserial_box( hDlg, 1 ); } else { enable_labelserial_box( hDlg, 0 ); } break; break; case ID_BUTTON_OK: break; case ID_BUTTON_CANCEL: EndDialog(hDlg, wParam); return TRUE; } } switch (uMsg) { case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_LIST_DRIVES: switch(HIWORD( wParam )) { case LBN_DBLCLK: selection = -1; break; } case IDC_BUTTON_ADD: /* temporarily disabled, awaiting rewrite for transactional design (need to fill in defaults smartly, wizard?) */ break; case IDC_BUTTON_REMOVE: /* temporarily disabled, awaiting rewrite */ break; case IDC_BUTTON_EDIT: if (HIWORD(wParam) == BN_CLICKED) { int nItem = SendMessage(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_GETCURSEL, 0, 0); char letter = SendMessage(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_GETITEMDATA, nItem, 0); DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DRIVE_EDIT2), NULL, (DLGPROC) DriveEditDlgProc, (LPARAM) letter); } break; case WM_NOTIFY: switch(((LPNMHDR)lParam)->code) { case PSN_KILLACTIVE: SetWindowLong(hDlg, DWL_MSGRESULT, FALSE); break; case PSN_APPLY: SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR); break; case PSN_SETACTIVE: initDriveDlg (hDlg); break; break; } extern HKEY configKey; char *curWinVer = getConfigValue("Version", "Windows", "win98"); char *curDOSVer = getConfigValue("Version", "DOS", "6.22"); char *curWineLook = getConfigValue("Tweak.Layout", "WineLook", "win95"); if (!strcmp (pVer->szVersion, curWinVer)) if (!strcmp (pVer->szVersion, curDOSVer)) if (!strcmp (pVer->szVersion, curWineLook)) free(curWinVer); free(curDOSVer); free(curWineLook); VERSION_DESC *desc = getWinVersions(); addTransaction("Version", "Windows", ACTION_SET, desc->szVersion); if (initialize() != 0) { WINE_ERR("initialization failed, aborting\n"); ExitProcess(1); } VERSION_DESC* getWinVersions(void) VERSION_DESC* getDOSVersions(void) VERSION_DESC* getWinelook(void) DLL_DESC* getDLLDefaults(void) VERSION_DESC *getWinVersions(void); VERSION_DESC *getDOSVersions(void); VERSION_DESC *getWinelook(void); DLL_DESC *getDLLDefaults(void); #define IDC_ENABLE_DESKTOP 1074 #include int initialize(void) { DWORD res = RegCreateKey(HKEY_LOCAL_MACHINE, WINE_KEY_ROOT, &configKey); if (res != ERROR_SUCCESS) { WINE_ERR("RegOpenKey failed on wine config key (%ld)\n", res); return 1; } * Returns a buffer holding the value if successful, NULL if not. Caller is responsible for freeing the result. char *getConfigValue (char *subkey, char *valueName, char *defaultResult) char *buffer = NULL; DWORD res; res = RegOpenKeyEx( configKey, subkey, 0, KEY_ALL_ACCESS, &hSubKey ); if(res != ERROR_SUCCESS) { return strdup(defaultResult); if( res == ERROR_FILE_NOT_FOUND ) { buffer = strdup(defaultResult); goto end; } else if( res!=ERROR_SUCCESS ) { buffer = malloc(dataLength); return buffer; int setConfigValue (char *subkey, char *valueName, const char *value) { assert( subkey != NULL ); assert( valueName != NULL ); assert( value != NULL ); res = RegCreateKey(configKey, subkey, &key); /* returns 0 on success, an HRESULT from the registry funtions otherwise */ HRESULT doesConfigValueExist(char *subkey, char *valueName) { HRESULT hr; HKEY key; WINE_TRACE("subkey=%s, valueName=%s - ", subkey, valueName); hr = RegOpenKeyEx(configKey, subkey, 0, KEY_READ, &key); if (hr != S_OK) { WINE_TRACE("no: subkey does not exist\n"); return hr; } hr = RegQueryValueEx(key, valueName, NULL, NULL, NULL, NULL); if (hr != S_OK) { WINE_TRACE("no: key does not exist\n"); return hr; } RegCloseKey(key); WINE_TRACE("yes\n"); return S_OK; } /* removes the requested value from the registry, however, does not remove the section if empty. Returns S_OK (0) on success. */ HRESULT removeConfigValue(char *subkey, char *valueName) { HRESULT hr; HKEY key; WINE_TRACE("subkey=%s, valueName=%s\n", subkey, valueName); hr = RegOpenKeyEx(configKey, subkey, 0, KEY_READ, &key); if (hr != S_OK) return hr; hr = RegDeleteValue(key, valueName); if (hr != ERROR_SUCCESS) return hr; return S_OK; } return_if_fail( initialize() == 0 , 1 ); /* getConfigValue(configKey, "Wine", "Windows", pCfg->szWinDir, MAX_PATH, "c:\\Windows"); */ /* getConfigValue(configKey, "Wine", "GraphicsDriver", pCfg->szGraphDriver, MAX_NAME_LENGTH, "x11drv"); */ /* for (pDllDefaults = getDLLDefaults (); *pDllDefaults->szName; pDllDefaults++) */ /* pCfg->pDrives = DPA_Create(26); */ /* ========================================================================= */ /* Transaction management code */ struct transaction *tqhead, *tqtail; int instantApply = 1; void destroyTransaction(struct transaction *trans) { assert( trans != NULL ); WINE_TRACE("destroying %p\n", trans); free(trans->section); free(trans->key); if (trans->newValue) free(trans->newValue); if (trans->next) trans->next->prev = trans->prev; if (trans->prev) trans->prev->next = trans->next; if (trans == tqhead) tqhead = NULL; if (trans == tqtail) tqtail = NULL; free(trans); } void addTransaction(char *section, char *key, enum transaction_action action, char *newValue) { struct transaction *trans = malloc(sizeof(struct transaction)); assert( section != NULL ); assert( key != NULL ); if (action == ACTION_SET) assert( newValue != NULL ); trans->section = section; trans->key = key; trans->newValue = newValue; trans->action = action; trans->next = NULL; trans->prev = NULL; if (tqtail == NULL) { tqtail = trans; tqhead = tqtail; } else { tqhead->next = trans; trans->prev = tqhead; tqhead = trans; } if (instantApply) processTransaction(trans); } void processTransaction(struct transaction *trans) { if (trans->action == ACTION_SET) { WINE_TRACE("Setting %s\\%s to '%s'\n", trans->section, trans->key, trans->newValue); setConfigValue(trans->section, trans->key, trans->newValue); } else if (trans->action == ACTION_REMOVE) { WINE_TRACE("Removing %s\\%s", trans->section, trans->key); removeConfigValue(trans->section, trans->key); } /* TODO: implement notifications here */ } void processTransQueue() { WINE_TRACE("\n"); while (tqhead != NULL) { processTransaction(tqhead); tqhead = tqhead->next; destroyTransaction(tqhead->prev); } #define return_if_fail(try, ret) \ if (!(try)) { \ WINE_ERR("assertion (##try) failed, returning\n"); \ return ret; \ } /* Transaction management */ enum transaction_action { ACTION_SET, ACTION_REMOVE }; struct transaction { char *section; char *key; char *newValue; enum transaction_action action; struct transaction *next, *prev; }; extern struct transaction *tqhead, *tqtail; extern int instantApply; /* non-zero means apply all changes instantly */ /* Commits a transaction to the registry */ void processTransaction(struct transaction *trans); /* Processes every pending transaction in the queue, removing them as it works from head to tail */ void processTransQueue(); /* Adds a transaction to the head of the queue. If we're using instant apply, this calls processTransaction * action can be either: * ACTION_SET -> this transaction will change a registry key, newValue is the replacement value * ACTION_REMOVE -> this transaction will remove a registry key. In this case, newValue is ignored. */ void addTransaction(char *section, char *key, enum transaction_action action, char *newValue); /* frees the transaction structure, all fields, and removes it from the queue if in it */ void destroyTransaction(struct transaction *trans); /* Initializes the transaction system */ int initialize(void); int setConfigValue (char *subkey, char *valueName, const char *value); char *getConfigValue (char *subkey, char *valueName, char *defaultResult); HRESULT doesConfigValueExist (char *subkey, char *valueName); HRESULT removeConfigValue (char *subkey, char *valueName); #define WINE_KEY_ROOT "Software\\Wine\\WineCfg\\Config" #define RES_MAXLEN 5 /* the maximum number of characters in a screen dimension. 5 digits should be plenty, what kind of crazy person runs their screen >10,000 pixels across? */ int updatingUI; void updateGUIForDesktopMode(HWND hDlg) { WINE_TRACE("\n"); updatingUI = TRUE; /* do we have desktop mode enabled? */ if (doesConfigValueExist("x11drv", "Desktop") == S_OK) { CheckDlgButton(hDlg, IDC_ENABLE_DESKTOP, BST_CHECKED); /* enable the controls */ EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), 1); EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), 1); EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_SIZE), 1); EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_BY), 1); SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), "640"); SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), "480"); } else { CheckDlgButton(hDlg, IDC_ENABLE_DESKTOP, BST_UNCHECKED); /* disable the controls */ EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), 0); EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), 0); EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_SIZE), 0); EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_BY), 0); SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), ""); SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), ""); } updatingUI = FALSE; } char *buf; int x, y; char *i; updatingUI = TRUE; updateGUIForDesktopMode(hDlg); /* desktop size */ buf = getConfigValue("x11drv", "Desktop", "640x480"); i = strchr(buf, 'x'); *i = '\0'; i++; SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), buf); SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), i); free(buf); SendDlgItemMessage(hDlg, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0); SendDlgItemMessage(hDlg, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0); updatingUI = FALSE; } void setFromDesktopSizeEdits(HWND hDlg) { char *width = malloc(RES_MAXLEN+1); char *height = malloc(RES_MAXLEN+1); char *newStr = malloc((RES_MAXLEN*2) + 2); if (updatingUI) return; WINE_TRACE("\n"); GetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), width, RES_MAXLEN+1); GetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), height, RES_MAXLEN+1); if (strcmp(width, "") == 0) strcpy(width, "640"); if (strcmp(height, "") == 0) strcpy(height, "480"); sprintf(newStr, "%sx%s", width, height); addTransaction("x11drv", "Desktop", ACTION_SET, newStr); free(width); free(height); free(newStr); void onEnableDesktopClicked(HWND hDlg) { WINE_TRACE("\n"); if (IsDlgButtonChecked(hDlg, IDC_ENABLE_DESKTOP) == BST_CHECKED) { /* it was just unchecked, so read the values of the edit boxes, set the config value */ setFromDesktopSizeEdits(hDlg); } else { /* it was just checked, so remove the config values */ addTransaction("x11drv", "Desktop", ACTION_REMOVE, NULL); } updateGUIForDesktopMode(hDlg); } if ( (LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT) ) setFromDesktopSizeEdits(hDlg); case BN_CLICKED: { WINE_TRACE("%ld\n", LOWORD(wParam)); switch(LOWORD(wParam)) { case IDC_ENABLE_DESKTOP: onEnableDesktopClicked(hDlg); break; }; break; } /* Clear the listbox */ SendMessageA(GetDlgItem(hDlg, IDC_LIST_DRIVES), LB_RESETCONTENT, 0, 0); WINE_TRACE("Adding %s (%s) to the listbox\n", drive->szName, drive->szLabel); /* if bEnable is 1 then we are editing a CDROM, so can enable all controls, otherwise we want to disable * "detect from device" and "serial number", but still allow the user to manually set the path. The UI * for this could be somewhat better -mike */ void enable_labelserial_box(HWND hDlg, int bEnable) enable_labelserial_box( hDlg, 1 ); enable_labelserial_box( hDlg, 0 ); selection = IDC_RADIO_ASSIGN; enable_labelserial_box( hDlg, 1 ); enable_labelserial_box( hDlg, 0 ); strncpy(pDrive->szPath, buffer, MAX_NAME_LENGTH); GetWindowText(GetDlgItem(hDlg, IDC_EDIT_LABEL), pDrive->szLabel, MAX_NAME_LENGTH); GetWindowText(GetDlgItem(hDlg, IDC_EDIT_SERIAL), pDrive->szSerial, MAX_NAME_LENGTH); GetWindowText(GetDlgItem(hDlg, IDC_EDIT_DEVICE), pDrive->szDevice, MAX_NAME_LENGTH); WINE_TRACE("refreshing main dialog\n"); initDriveDlg(hDlg); #define IDC_BOX_LABELSERIAL 1071 #include "wine/port.h" ERR("%s: %s\n", ossdev->mixer_name , strerror( errno )); ERR("%s: %s\n", ossdev->mixer_name, strerror(errno)); if (himl->cx > 0) nImageCount = bmp.bmWidth / himl->cx; else nImageCount = 0; *pptLib = NULL; /* typelibs are cached, keyed by path, so store the linked list info within them */ struct tagITypeLibImpl *next, *prev; WCHAR *path; /* Because type library parsing has some degree of overhead, and some apps repeatedly load the same * typelibs over and over, we cache them here. According to MSDN Microsoft have a similar scheme in * place. This will cause a deliberate memory leak, but generally losing RAM for cycles is an acceptable * tradeoff here. */ static ITypeLibImpl *tlb_cache_first; static CRITICAL_SECTION cache_section; static CRITICAL_SECTION_DEBUG cache_section_debug = { 0, 0, &cache_section, { &cache_section_debug.ProcessLocksList, &cache_section_debug.ProcessLocksList }, 0, 0, { 0, (DWORD)(__FILE__ ": typelib loader cache") } }; static CRITICAL_SECTION cache_section = { &cache_section_debug, -1, 0, 0, 0, 0 }; ITypeLibImpl *entry; /* We look the path up in the typelib cache. If found, we just addref it, and return the pointer. */ EnterCriticalSection(&cache_section); for (entry = tlb_cache_first; entry != NULL; entry = entry->next) { if (!strcmpiW(entry->path, pszFileName)) { TRACE("cache hit\n"); *ppTypeLib = (ITypeLib2*)entry; ITypeLib_AddRef(*ppTypeLib); LeaveCriticalSection(&cache_section); return S_OK; } } LeaveCriticalSection(&cache_section); if(*ppTypeLib) { ITypeLibImpl *impl = (ITypeLibImpl*)*ppTypeLib; TRACE("adding to cache\n"); impl->path = HeapAlloc(GetProcessHeap(), 0, (strlenW(pszFileName)+1) * sizeof(WCHAR)); lstrcpyW(impl->path, pszFileName); /* We should really canonicalise the path here. */ /* FIXME: check if it has added already in the meantime */ EnterCriticalSection(&cache_section); if ((impl->next = tlb_cache_first) != NULL) impl->next->prev = impl; impl->prev = NULL; tlb_cache_first = impl; LeaveCriticalSection(&cache_section); ret = S_OK; } else ERR("Loading of typelib %s failed with error %ld\n", debugstr_w(pszFileName), GetLastError()); TRACE("(%p)->ref was %u\n",This, This->ref); /* remove cache entry */ TRACE("removing from cache list\n"); EnterCriticalSection(&cache_section); if (This->next) This->next->prev = This->prev; if (This->prev) This->prev->next = This->next; else tlb_cache_first = This->next; LeaveCriticalSection(&cache_section); /* FIXME destroy child objects */ TRACE("returning pIndex=%d\n", *pIndex); TRACE("returning ppTLib=%p\n", *ppTLib); /* Until winecfg is fully functional, warn users that it is incomplete and doesn't do anything */ MessageBox(NULL, "The winecfg tool is not yet complete, and does not actually alter your configuration. If you want to alter the way Wine works, look in the ~/.wine/config file for more information.", "winecfg", MB_OK | MB_ICONWARNING); #define NONAMELESSUNION #define NONAMELESSSTRUCT static CRITICAL_SECTION git_section; static CRITICAL_SECTION_DEBUG critsect_debug = { 0, 0, &git_section, { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, 0, 0, { 0, (DWORD)(__FILE__ ": global interface table") } }; static CRITICAL_SECTION git_section = { &critsect_debug, -1, 0, 0, 0, 0 }; EnterCriticalSection(&git_section); if (e->cookie == cookie) { LeaveCriticalSection(&git_section); return e; } LeaveCriticalSection(&git_section); /* InterlockedIncrement(&self->ref); */ /* InterlockedDecrement(&self->ref); */ EnterCriticalSection(&git_section); LeaveCriticalSection(&git_section); TRACE("Cookie is 0x%lx\n", entry->cookie); /* Free the stream */ IStream_Release(entry->stream); EnterCriticalSection(&git_section); LeaveCriticalSection(&git_section); LARGE_INTEGER move; LPUNKNOWN lpUnk; TRACE("dwCookie=0x%lx, riid=%s, ppv=%p\n", dwCookie, debugstr_guid(riid), ppv); hres = CoUnmarshalInterface(entry->stream, riid, ppv); if (hres) { WARN("Failed to unmarshal stream\n"); return hres; } /* rewind stream, in case it's used again */ move.s.LowPart = 0; move.s.HighPart = 0; IStream_Seek(entry->stream, move, STREAM_SEEK_SET, NULL); /* addref it */ lpUnk = *ppv; IUnknown_AddRef(lpUnk); TRACE("ppv=%p\n", *ppv); IID iid; /* IID of the interface */ newGIT->ref = 1; /* Initialise the reference count */ StdGlobalInterfaceTableInstance = NULL; StdGlobalInterfaceTable_AddRef(iface); /* self->ref++; */ /* self->ref--; */ TRACE("About to marshal the interface\n"); if (!IsEqualIID(&entry->iid, riid)) { WARN("entry->iid (%s) != riid\n", debugstr_guid(&entry->iid)); return E_INVALIDARG; } TRACE("entry=%p\n", entry); hres = CoGetInterfaceAndReleaseStream(entry->stream, riid, ppv); DWORD preAllocResult; preAllocResult = IMallocSpy_PreAlloc(Malloc32.pSpy, cb); if ((cb != 0) && (preAllocResult == 0)) { /* PreAlloc can force Alloc to fail, but not if cb == 0 */ TRACE("returning null\n"); LeaveCriticalSection(&IMalloc32_SpyCS); { TRACE("PIDL length is %d\n", wLen); if (wLen != 0) { *ppPidl = SHAlloc (wLen); if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead))) { TRACE("Stream read OK\n"); ret = S_OK; } else { WARN("reading pidl failed\n"); SHFree(*ppPidl); *ppPidl = NULL; } } else { ret = S_OK; if (*ppPidl && !pcheck(*ppPidl)) { WARN("Check failed\n"); SHFree(*ppPidl); TRACE("done\n"); PrintStructures = (PRINT_PTRW*) GetPropW(hDlg, "__WINE_PRINTDLGDATA"); SetPropW(hDlg, "__WINE_PRINTDLGDATA", PrintStructures); res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg); res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam); extern HRESULT StdGlobalInterfaceTable_GetFactory(LPVOID *ppv); extern void* StdGlobalInterfaceTableInstance; void* StdGlobalInterfaceTableInstance; TRACE("constructing\n"); TRACE("Entry not found\n"); TRACE("iface=%p, pUnk=%p, riid=%s, pdwCookie=0x%p\n", iface, pUnk, debugstr_guid(riid), pdwCookie); TRACE("Cookie is 0x%ld\n", entry->cookie); TRACE("dwCookie=0x%lx, riid=%s\n", dwCookie, debugstr_guid(riid)); /* Classfactory definition - despite what MSDN says, some programs need this */ static HRESULT WINAPI GITCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) { *ppv = NULL; if (IsEqualIID(riid,&IID_IUnknown) || IsEqualIID(riid,&IID_IGlobalInterfaceTable)) { *ppv = (LPVOID)iface; return S_OK; } return E_NOINTERFACE; } static ULONG WINAPI GITCF_AddRef(LPCLASSFACTORY iface) { return 2; } static ULONG WINAPI GITCF_Release(LPCLASSFACTORY iface) { return 1; } static HRESULT WINAPI GITCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv) { if (IsEqualIID(riid,&IID_IGlobalInterfaceTable)) { if (StdGlobalInterfaceTableInstance == NULL) StdGlobalInterfaceTableInstance = StdGlobalInterfaceTable_Construct(); return IGlobalInterfaceTable_QueryInterface( (IGlobalInterfaceTable*) StdGlobalInterfaceTableInstance, riid, ppv); } FIXME("(%s), not supported.\n",debugstr_guid(riid)); return E_NOINTERFACE; } static HRESULT WINAPI GITCF_LockServer(LPCLASSFACTORY iface, BOOL fLock) { FIXME("(%d), stub!\n",fLock); return S_OK; } static ICOM_VTABLE(IClassFactory) GITClassFactoryVtbl = { ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE GITCF_QueryInterface, GITCF_AddRef, GITCF_Release, GITCF_CreateInstance, GITCF_LockServer }; static ICOM_VTABLE(IClassFactory) *PGITClassFactoryVtbl = &GITClassFactoryVtbl; HRESULT StdGlobalInterfaceTable_GetFactory(LPVOID *ppv) { *ppv = &PGITClassFactoryVtbl; TRACE("Returning GIT classfactory\n"); return S_OK; } if (IsEqualIID(rclsid,&CLSID_StdGlobalInterfaceTable) && (IsEqualIID(iid,&IID_IClassFactory) || IsEqualIID(iid,&IID_IUnknown))) return StdGlobalInterfaceTable_GetFactory(ppv); BOOL WINAPI GetUrlCacheConfigInfoA(LPDWORD CacheInfo, LPDWORD size, DWORD bitmask) BOOL WINAPI GetUrlCacheConfigInfoW(LPDWORD CacheInfo, LPDWORD size, DWORD bitmask) /*********************************************************************** * SetUrlCacheEntryInfoA (WININET.@) */ BOOL WINAPI SetUrlCacheEntryInfoA(LPCSTR lpszUrlName, LPINTERNET_CACHE_ENTRY_INFOA lpCacheEntryInfo, DWORD dwFieldControl) { FIXME("stub\n"); return FALSE; } /*********************************************************************** * SetUrlCacheEntryInfoW (WININET.@) */ BOOL WINAPI SetUrlCacheEntryInfoW(LPCWSTR lpszUrlName, LPINTERNET_CACHE_ENTRY_INFOW lpCacheEntryInfo, DWORD dwFieldControl) { FIXME("stub\n"); return FALSE; } BOOL bFocussed; channel->left = lpRect.left + offsetthumb - cyChannel; channel->top = lpRect.top + offsetedge; int range, width, height, thumbdepth, ticOffset = 5 + 2; /* 5 is length of tic, 2 is extra indent */ range = infoPtr->lRangeMax - infoPtr->lRangeMin; thumbdepth = ((int)(infoPtr->uThumbLen / 4.5)) + 2; height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top; thumb->left = (lpRect.right - lpRect.left - infoPtr->uThumbLen)/2 + ticOffset; thumb->right = thumb->left + infoPtr->uThumbLen - (ticOffset * 2); (height*(lPos - infoPtr->lRangeMin))/range - width = infoPtr->rcChannel.right - infoPtr->rcChannel.left; thumb->bottom = thumb->top + infoPtr->uThumbLen - 20; /* double the bottom padding for the ticks, chosen to resemble native control */ int runOver = 5; /* make the channel slightly overrun the last tick, to make it look more like the native control, and less "clunky" */ if (dwStyle & TBS_VERT) { rcChannel.top -= runOver; rcChannel.bottom += runOver; } else { rcChannel.left -= runOver; rcChannel.right += runOver; } rcTics.bottom -= 10; /* value obtained by guesswork and experimentation */ int height = rcTics.bottom - rcTics.top; /* draw focus rectangle */ if (infoPtr->bFocussed) { DrawFocusRect(hdc, &rcClient); } if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_FIXEDLENGTH) { infoPtr->flags |= TB_THUMBSIZECHANGED; InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE); } DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE); /* initial thumb length */ if (dwStyle & TBS_VERT) { infoPtr->uThumbLen = (rect.right - rect.left - 6); } else { infoPtr->uThumbLen = (rect.bottom - rect.top); } infoPtr->bFocussed = FALSE; infoPtr->bFocussed = TRUE; * Control_FillCache_RunDLLA [SHELL32.@] HRESULT WINAPI Control_FillCache_RunDLLA(HWND hWnd, HANDLE hModule, DWORD w, DWORD x) /************************************************************************* * Control_FillCache_RunDLLW [SHELL32.@] * */ HRESULT WINAPI Control_FillCache_RunDLLW(HWND hWnd, HANDLE hModule, DWORD w, DWORD x) { return Control_FillCache_RunDLLA(hWnd, hModule, w, x); } ERR( "section %p %s wait timed out in thread %04lx, blocked by %04lx, retrying (60 sec)\n", crit, debugstr_a(name), GetCurrentThreadId(), (DWORD)crit->OwningThread ); ERR( "section %p %s wait timed out in thread %04lx, blocked by %04lx, retrying (5 min)\n", crit, debugstr_a(name), GetCurrentThreadId(), (DWORD) crit->OwningThread ); if (pConv == NULL) return NULL; int le = GetLastError(); if ((le != ERROR_NO_MORE_FILES) && (le != ERROR_FILE_NOT_FOUND)) return LB_ERR; extern Atom netwmPing; } else if (protocol == netwmPing) { XClientMessageEvent xev; xev = *event; TRACE("NET_WM Ping\n"); xev.window = DefaultRootWindow(xev.display); XSendEvent(xev.display, xev.window, False, SubstructureRedirectMask | SubstructureNotifyMask, (XEvent*)&xev); /* this line is semi-stolen from gtk2 */ TRACE("NET_WM Pong\n"); #include Atom netwmPid = None; Atom netwmPing = None; if (netwmPing) protocols[i++] = netwmPing; /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */ XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL); /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */ i = getpid(); XChangeProperty(display, data->whole_window, netwmPid, XA_CARDINAL, 32, PropModeReplace, (char *)&i, 1); netwmPid = XInternAtom( display, "_NET_WM_PID", False ); netwmPing = XInternAtom( display, "_NET_WM_PING", False ); SetLastError( ERROR_FILE_NOT_FOUND ); static const int _ws_ip_ops[] = { WS_IP_MULTICAST_IF, WS_IP_MULTICAST_TTL, WS_IP_MULTICAST_LOOP, WS_IP_ADD_MEMBERSHIP, WS_IP_DROP_MEMBERSHIP, WS_IP_OPTIONS, WS_IP_HDRINCL, WS_IP_TOS, WS_IP_TTL, 0 }; static const int _px_ip_ops[] = { IP_MULTICAST_IF, IP_MULTICAST_TTL, IP_MULTICAST_LOOP, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_OPTIONS, IP_HDRINCL, IP_TOS, IP_TTL, 0 }; case WS_IPPROTO_IP: *level = IPPROTO_IP; for(i=0; _ws_ip_ops[i]; i++) { if (_ws_ip_ops[i] == *optname ) break; } if( _ws_ip_ops[i] ) { *optname = _px_ip_ops[i]; return 1; } FIXME("Unknown IPPROTO_IP optname 0x%x\n", *optname); break; default: FIXME("Unimplemented or unknown socket level\n"); TRACE( "Setting WS_SO_REUSEADDR on socket before we bind it\n"); ERR("Invalid level (%d) or optname (%d)\n", level, optname); TRACE("Setting socket error, %d\n", wsaErrno()); #define setsockopt linux_setsockopt #define getsockopt linux_getsockopt /* for the get/setsockopt forwarders */ #undef setsockopt #undef getsockopt extern int WINAPI setsockopt(SOCKET s, INT level, INT optname ,char* optval, INT optlen); extern int WINAPI getsockopt(SOCKET s, INT level, INT optname ,char* optval, INT* optlen); /* internal remapper function for the IP_ constants */ static INT _remap_optname(INT level, INT optname) { TRACE("level=%d, optname=%d\n", level, optname); if (level == WS_IPPROTO_IP) { switch (optname) { /***** from value *****/ case 2: return 9; /* IP_MULTICAST_IF */ case 3: return 10; /* IP_MULTICAST_TTL */ case 4: return 11; /* IP_MULTICAST_LOOP */ case 5: return 12; /* IP_ADD_MEMBERSHIP */ case 6: return 13; /* IP_DROP_MEMBERSHIP */ case 7: return 4; /* IP_TTL */ case 8: return 3; /* IP_TOS */ case 9: return 14; /* IP_DONTFRAGMENT */ default: FIXME("Unknown optname %d, can't remap!\n", optname); return optname; } } else { /* don't need to do anything */ return optname; } } /*********************************************************************** * setsockopt (WSOCK32.21) * * We have these forwarders because, for reasons unknown to us mere mortals, * the values of the IP_ constants changed between winsock.h and winsock2.h. * So, we need to remap them here. */ INT WINAPI WS1_setsockopt(SOCKET s, INT level, INT optname, char *optval, INT optlen) { return setsockopt(s, level, _remap_optname(level, optname), optval, optlen); } /*********************************************************************** * getsockopt (WSOCK32.7) */ INT WINAPI WS1_getsockopt(SOCKET s, INT level, INT optname, char *optval, INT *optlen) { return getsockopt(s, level, _remap_optname(level, optname), optval, optlen); } if (bTrack && TREEVIEW_SendSimpleNotify(infoPtr, NM_CLICK)) if (tvItem->mask & TVIF_STATE) { /* Careful here - Windows ignores the stateMask when you get the state That contradicts the documentation, but makes more common sense, masking retrieval in this way seems overkill */ tvItem->state = wineItem->state; } /* store the orignal item values */ originalItem = *wineItem; #define SELECTED_TAB_OFFSET 2 item_height = fontMetrics.tmHeight + 2; * Unless otherwise noted, we believe this code to be complete, as per #define SELECTED_TAB_OFFSET 1 RECT clientRect, r; /* Punch out the updown control */ if (infoPtr->needsScrolling && (clientRect.right > 0)) { GetClientRect(infoPtr->hwndUpDown, &r); clientRect.right = clientRect.right - (r.right - r.left); } const CLSID CLSID_StdGlobalInterfaceTable = { 0x00000323, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46} }; static void* StdGlobalInterfaceTableInstance; /* * The Standard Global Interface Table (GIT) object is a process-wide singleton. * Rather than create a class factory, we can just check for it here */ if (IsEqualIID(rclsid, &CLSID_StdGlobalInterfaceTable)) { if (StdGlobalInterfaceTableInstance == NULL) StdGlobalInterfaceTableInstance = StdGlobalInterfaceTable_Construct(); hres = IGlobalInterfaceTable_QueryInterface( (IGlobalInterfaceTable*) StdGlobalInterfaceTableInstance, iid, ppv); if (hres) return hres; TRACE("Retrieved GIT (%p)\n", *ppv); return S_OK; } extern void* StdGlobalInterfaceTable_Construct(); extern void StdGlobalInterfaceTable_Destroy(void* self); /* * Implementation of the StdGlobalInterfaceTable object * * The GlobalInterfaceTable (GIT) object is used to marshal interfaces between * threading apartments (contexts). When you want to pass an interface but not * as a parameter, it wouldn't get marshalled automatically, so you can use this * object to insert the interface into a table, and you get back a cookie. * Then when it's retrieved, it'll be unmarshalled into the right apartment. * * Copyright 1999 Mike Hearn * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include #include #include #include #include "windef.h" #include "objbase.h" #include "ole2.h" #include "winbase.h" #include "winerror.h" #include "winternl.h" #include "compobj_private.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(ole); /**************************************************************************** * StdGlobalInterfaceTable definition * * This class implements IGlobalInterfaceTable and is a process-wide singleton * used for marshalling interfaces between threading apartments using cookies. */ /* Each entry in the linked list of GIT entries */ typedef struct StdGITEntry { DWORD cookie; IID iid; /* IID of the interface */ IStream* stream; /* Holds the marshalled interface */ struct StdGITEntry* next; struct StdGITEntry* prev; } StdGITEntry; /* Class data */ typedef struct StdGlobalInterfaceTableImpl { ICOM_VFIELD(IGlobalInterfaceTable); ULONG ref; struct StdGITEntry* firstEntry; struct StdGITEntry* lastEntry; ULONG nextCookie; } StdGlobalInterfaceTableImpl; /* IUnknown */ static HRESULT WINAPI StdGlobalInterfaceTable_QueryInterface(IGlobalInterfaceTable* iface, REFIID riid, void** ppvObject); static ULONG WINAPI StdGlobalInterfaceTable_AddRef(IGlobalInterfaceTable* iface); static ULONG WINAPI StdGlobalInterfaceTable_Release(IGlobalInterfaceTable* iface); /* IGlobalInterfaceTable */ static HRESULT WINAPI StdGlobalInterfaceTable_RegisterInterfaceInGlobal(IGlobalInterfaceTable* iface, IUnknown* pUnk, REFIID riid, DWORD* pdwCookie); static HRESULT WINAPI StdGlobalInterfaceTable_RevokeInterfaceFromGlobal(IGlobalInterfaceTable* iface, DWORD dwCookie); static HRESULT WINAPI StdGlobalInterfaceTable_GetInterfaceFromGlobal(IGlobalInterfaceTable* iface, DWORD dwCookie, REFIID riid, void **ppv); /* Virtual function table */ static ICOM_VTABLE(IGlobalInterfaceTable) StdGlobalInterfaceTableImpl_Vtbl = { ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE StdGlobalInterfaceTable_QueryInterface, StdGlobalInterfaceTable_AddRef, StdGlobalInterfaceTable_Release, StdGlobalInterfaceTable_RegisterInterfaceInGlobal, StdGlobalInterfaceTable_RevokeInterfaceFromGlobal, StdGlobalInterfaceTable_GetInterfaceFromGlobal }; /*** * Let's go! Here is the constructor and destructor for the class. * */ /** This function constructs the GIT. It should only be called once **/ void* StdGlobalInterfaceTable_Construct() { StdGlobalInterfaceTableImpl* newGIT; newGIT = HeapAlloc(GetProcessHeap(), 0, sizeof(StdGlobalInterfaceTableImpl)); if (newGIT == 0) return newGIT; ICOM_VTBL(newGIT) = &StdGlobalInterfaceTableImpl_Vtbl; newGIT->ref = 0; /* Initialise the reference count */ newGIT->firstEntry = NULL; /* we start with an empty table */ newGIT->lastEntry = NULL; newGIT->nextCookie = 0xf100; /* that's where windows starts, so that's where we start */ TRACE("Created the GIT at %p\n", newGIT); return (void*)newGIT; } /** This destroys it again. It should revoke all the held interfaces first **/ void StdGlobalInterfaceTable_Destroy(void* self) { TRACE("(%p)\n", self); FIXME("Revoke held interfaces here\n"); HeapFree(GetProcessHeap(), 0, self); } /*** * A helper function to traverse the list and find the entry that matches the cookie. * Returns NULL if not found */ StdGITEntry* StdGlobalInterfaceTable_FindEntry(IGlobalInterfaceTable* iface, DWORD cookie) { StdGlobalInterfaceTableImpl* const self = (StdGlobalInterfaceTableImpl*) iface; StdGITEntry* e; TRACE("iface=%p, cookie=0x%x\n", iface, (UINT)cookie); e = self->firstEntry; while (e != NULL) { if (e->cookie == cookie) return e; e = e->next; } return NULL; } /*** * Here's the boring boilerplate stuff for IUnknown */ HRESULT WINAPI StdGlobalInterfaceTable_QueryInterface(IGlobalInterfaceTable* iface, REFIID riid, void** ppvObject) { StdGlobalInterfaceTableImpl* const self = (StdGlobalInterfaceTableImpl*) iface; /* Make sure silly coders can't crash us */ if (ppvObject == 0) return E_INVALIDARG; *ppvObject = 0; /* assume we don't have the interface */ /* Do we implement that interface? */ if (IsEqualIID(&IID_IUnknown, riid)) { *ppvObject = (IGlobalInterfaceTable*) self; } else if (IsEqualIID(&IID_IGlobalInterfaceTable, riid)) { *ppvObject = (IGlobalInterfaceTable*) self; } else return E_NOINTERFACE; /* Now inc the refcount */ /* we don't use refcounts for now: StdGlobalInterfaceTable_AddRef(iface); */ return S_OK; } ULONG WINAPI StdGlobalInterfaceTable_AddRef(IGlobalInterfaceTable* iface) { StdGlobalInterfaceTableImpl* const self = (StdGlobalInterfaceTableImpl*) iface; self->ref++; return self->ref; } ULONG WINAPI StdGlobalInterfaceTable_Release(IGlobalInterfaceTable* iface) { StdGlobalInterfaceTableImpl* const self = (StdGlobalInterfaceTableImpl*) iface; self->ref--; if (self->ref == 0) { /* Hey ho, it's time to go, so long again 'till next weeks show! */ StdGlobalInterfaceTable_Destroy(self); return 0; } return self->ref; } /*** * Now implement the actual IGlobalInterfaceTable interface */ HRESULT WINAPI StdGlobalInterfaceTable_RegisterInterfaceInGlobal(IGlobalInterfaceTable* iface, IUnknown* pUnk, REFIID riid, DWORD* pdwCookie) { StdGlobalInterfaceTableImpl* const self = (StdGlobalInterfaceTableImpl*) iface; IStream* stream = NULL; HRESULT hres; StdGITEntry* entry; TRACE("iface=%p, pUnk=%p, riid=%s, pdwCookie=%p\n", iface, pUnk, debugstr_guid(riid), pdwCookie); if (pUnk == NULL) return E_INVALIDARG; /* marshal the interface */ hres = CoMarshalInterThreadInterfaceInStream(riid, pUnk, &stream); if (hres) return hres; entry = HeapAlloc(GetProcessHeap(), 0, sizeof(StdGITEntry)); if (entry == NULL) return E_OUTOFMEMORY; entry->iid = *riid; entry->stream = stream; entry->cookie = self->nextCookie; self->nextCookie++; /* inc the cookie count */ /* insert the new entry at the end of the list */ entry->next = NULL; entry->prev = self->lastEntry; if (entry->prev) entry->prev->next = entry; else self->firstEntry = entry; self->lastEntry = entry; /* and return the cookie */ *pdwCookie = entry->cookie; return S_OK; } HRESULT WINAPI StdGlobalInterfaceTable_RevokeInterfaceFromGlobal(IGlobalInterfaceTable* iface, DWORD dwCookie) { StdGlobalInterfaceTableImpl* const self = (StdGlobalInterfaceTableImpl*) iface; StdGITEntry* entry; TRACE("iface=%p, dwCookie=0x%x\n", iface, (UINT)dwCookie); entry = StdGlobalInterfaceTable_FindEntry(iface, dwCookie); if (entry == NULL) { TRACE("Entry not found\n"); return E_INVALIDARG; /* not found */ } /* chop entry out of the list, and free the memory */ if (entry->prev) entry->prev->next = entry->next; else self->firstEntry = entry->next; if (entry->next) entry->next->prev = entry->prev; else self->lastEntry = entry->prev; HeapFree(GetProcessHeap(), 0, entry); return S_OK; } HRESULT WINAPI StdGlobalInterfaceTable_GetInterfaceFromGlobal(IGlobalInterfaceTable* iface, DWORD dwCookie, REFIID riid, void **ppv) { StdGITEntry* entry; HRESULT hres; entry = StdGlobalInterfaceTable_FindEntry(iface, dwCookie); if (entry == NULL) return E_INVALIDARG; if (!IsEqualIID(&entry->iid, &riid)) return E_INVALIDARG; /* unmarshal the interface */ hres = CoGetInterfaceAndReleaseStream(entry->stream, riid, *ppv); if (hres) return hres; return S_OK; } TRACE("(%s, %p, %p)\n",debugstr_guid(riid), pUnk, ppStm); /* UNDOCUMENTED: If requested Width or Height is 0 this means that program wants to use default. */ if (LOWORD(lParam)) infoPtr->tabWidth = (INT)LOWORD(lParam); /* If a pointer is null, we simply ignore it, the ATL in particular passes pIndex as 0 */ if (pIndex) { *pIndex=This->index; TRACE("returning pIndex=%d", *pIndex); } if (ppTLib) { *ppTLib=(LPTYPELIB )(This->pTypeLib); ITypeLib2_AddRef(*ppTLib); TRACE("returning ppTLib=%p", *ppTLib); } * Provides information about the status of the memory, so apps can tell * roughly how much they are able to allocate * /*********************************************************************** * GlobalMemoryStatusEx (KERNEL32.@) * A version of GlobalMemoryStatus that can deal with memory over 4GB * * RETURNS * None */ BOOL WINAPI GlobalMemoryStatusEx( LPMEMORYSTATUSEX lpBuffer ) { MEMORYSTATUS memstatus; /* Because GlobalMemoryStatusEx is identical to GlobalMemoryStatus save for one extra field in the struct, and the lack of a bug, we simply call GlobalMemoryStatus and copy the values across. */ FIXME("we should emulate the 4GB bug here, as per MSDN\n"); GlobalMemoryStatus(&memstatus); lpBuffer->dwMemoryLoad = memstatus.dwMemoryLoad; lpBuffer->ullTotalPhys = memstatus.dwTotalPhys; lpBuffer->ullAvailPhys = memstatus.dwAvailPhys; lpBuffer->ullTotalPageFile = memstatus.dwTotalPageFile; lpBuffer->ullAvailPageFile = memstatus.dwAvailPageFile; lpBuffer->ullTotalVirtual = memstatus.dwTotalVirtual; lpBuffer->ullAvailVirtual = memstatus.dwAvailVirtual; /* MSDN says about AvailExtendedVirtual: Size of unreserved and uncommitted memory in the extended portion of the virtual address space of the calling process, in bytes. However, I don't know what this means, so set it to zero :( */ lpBuffer->ullAvailExtendedVirtual = 0; return 1; } " info (see 'help info' for options)", /* QuickTime does pass invalid data into SetMenuItemInfo. * do some of the checks Windows does. */ WARN("Bad masks (0x%08x) for type (0x%08x) or state (0x%08x)\n", lpmii->fMask, lpmii->fType,lpmii->fState ); /* is the app setting both MFT_BITMAP and MFT_SEPARATOR (which is wrong)? */ if (lpmii->fType & (MFT_BITMAP | MFT_SEPARATOR)) { WARN("fType contains MFT_BITMAP and MFT_SEPARATOR, API violation\n"); return FALSE; } POINT posClient; posClient.x = pos.x; posClient.y = pos.y; ScreenToClient(hwnd, &posClient); get_key_state(), MAKELPARAM( posClient.x, posClient.y )); PostMessageW(TrackingList[i].tme.hwndTrack, WM_MOUSEHOVER, get_key_state(), MAKELPARAM( pos.x, pos.y ));