///////////////////////////////////////////////////////////////////////////////// // GetDLLInfo ///////////////////////////////////////////////////////////////////////////////// // This function loads the library and gets the entry point address. // With the information returned we can create the property dialog. // // For simplicity reasons we load the DLL "ac97prop" and call the function // "AC97PropPageProvider". A more flexible course of action is to get this // information from the registry. To do this, we read the "EnumPropPages32" // entry in the drivers section to obtain a registry path (read the "drivers" // entry in the device section to get the registry path of the drivers section) // -- this path leads to a key and entry which specifies the DLL and entry point. // // Arguments: // *phDLL pointer to module handle of loaded DLL. // *pAC97PropPageProvider pointer to "AC97PropPageProvider" in loaded DLL // // Return Value: // TRUE on success, otherwise FALSE. // Note: on success the library is still loaded. // BOOL GetDLLInfo (HMODULE *phDLL, LPFNADDPROPSHEETPAGES *pAC97PropPageProvider) { TCHAR szLoadPath[MAX_PATH]; TCHAR szWinSysPath[MAX_PATH]; GetSystemDirectory(szWinSysPath, MAX_PATH); if(FAILED(StringCbPrintf(szLoadPath, MAX_PATH * sizeof(TCHAR), TEXT("%s\\%s"), szWinSysPath, TEXT("ac97prop.dll")))) { dbgError (TEXT("DisplayPropertySheet: Can't build DLL path\n")); return FALSE; } // Load the library. *phDLL = LoadLibrary (szLoadPath); if (!*phDLL) { dbgError (TEXT("DisplayPropertySheet: LoadLibrary")); return FALSE; } // Get the address of the function. *pAC97PropPageProvider = (LPFNADDPROPSHEETPAGES)GetProcAddress (*phDLL, "AC97PropPageProvider"); if (!*pAC97PropPageProvider) { dbgError (TEXT("DisplayPropertySheet: GetProcAddress")); FreeLibrary (*phDLL); return FALSE; } return TRUE; }
void luaStore_writeValue(TValue * v, file& f, std::vector<void *>& functions) { uint i; bool found; byte type = ttype(v); f.write(type); switch(type) { case LUA_TNIL: // nil has no data break; case LUA_TBOOLEAN: f.write((byte)val_(v).b); break; case LUA_TLIGHTUSERDATA: // write the pointer f.write(&val_(v).p, sizeof(void*)); break; case LUA_TNUMBER: f.write(num_(v)); break; case LUA_TSTRING: // write the pointer to gc objects case LUA_TTABLE: case LUA_TUSERDATA: case LUA_TTHREAD: // all gc objects will be flushed to disk later f.write(&val_(v).gc, sizeof(void*)); break; case LUA_TLCL: f.write(&val_(v).gc, sizeof(void*)); // this variant is a gc object break; case LUA_TLCF: // c-function // look up the function in the bindings list found = false; for(i = 0;i < functions.size();i++) { if(functions[i] == val_(v).f) { // write the index as a short f.write((ushort)i); found = true; break; } } if(!found) dbgError("unknown light function"); break; default: dbgError("unknown object type %i", type); break; } }
void luaStore_writeStrings(stringtable * strt, file&f) { GCObject * list; int i; // The total amount of strings f.write(strt->nuse); for(i = 0;i < strt->size;i++) { list = strt->hash[i]; while(list) { // write the object pointer f.write(&list, sizeof(void*)); // write the string length if(list->ts.tsv.len > 0xFFFF) dbgError("string too long"); f.write((ushort)list->ts.tsv.len); // write the string f.write(&list->ts + 1, list->ts.tsv.len); // next! list = list->gch.next; } } }
void luaStore_writeLongString(GCObject * obj, file& f) { // Long String format: // ushort length // length bytes if(obj->ts.tsv.len > 0xFFFF) dbgError("string too long"); f.write((ushort)obj->ts.tsv.len); f.write(&obj->ts + 1, obj->ts.tsv.len); }
void luaStore_writeObject(GCObject * obj, file& f, std::vector<void *>& functions) { // write the data switch(obj->gch.tt) { case LUA_TSHRSTR: dbgError("short string is not a valid object type"); break; case LUA_TLNGSTR: luaStore_writeHeader(obj, f); luaStore_writeLongString(obj, f); break; case LUA_TTABLE: luaStore_writeHeader(obj, f); luaStore_writeTable(obj, f, functions); break; case LUA_TLCL: // Lua closure, serialize this luaStore_writeHeader(obj, f); break; case LUA_TTHREAD: // Thread, serialize this luaStore_writeHeader(obj, f); luaStore_writeThread(&obj->th, f, functions); break; case LUA_TPROTO: // Prototype, serialize this luaStore_writeHeader(obj, f); break; case LUA_TUPVAL: // Upval, serialize this luaStore_writeHeader(obj, f); break; default: dbgError("unknown object type %i", obj->gch.tt); break; } }
///////////////////////////////////////////////////////////////////////////////// // FindAC97Device ///////////////////////////////////////////////////////////////////////////////// // This function stores the device info and device data of the "ac97smpl" driver. // It first creates a list of all devices that have a topology filter exposed // and then searches through the list to find the device with the service // "ac97smpl". The information is stored in pspRequest. // // For simplicity we search for the service name "ac97smpl". // Alternately, one could get more information about the device or driver, // then decide if it is suitable (regardless of its name). // // Arguments: // pspRequest pointer to Property sheet page request structure. // DeviceInfoData pointer to Device info data structure. // // Return Value: // TRUE on success, otherwise FALSE. // Note: on success that we have the device list still open - we have to destroy // the list later. The handle is stored at pspRequest->DeviceInfoSet. // BOOL FindAC97Device (PSP_PROPSHEETPAGE_REQUEST pspRequest, PSP_DEVINFO_DATA DeviceInfoData) { TCHAR szServiceName[128]; // // Prepare the pspRequest structure... // pspRequest->cbSize = sizeof (SP_PROPSHEETPAGE_REQUEST); pspRequest->DeviceInfoData = DeviceInfoData; pspRequest->PageRequested = SPPSR_ENUM_ADV_DEVICE_PROPERTIES; // ...and the DeviceInfoData structure. DeviceInfoData->cbSize = sizeof (SP_DEVINFO_DATA); // Create a list of devices with Topology interface. pspRequest->DeviceInfoSet = SetupDiGetClassDevs (&KSCATEGORY_TOPOLOGY, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); // None found? if (pspRequest->DeviceInfoSet == INVALID_HANDLE_VALUE) { dbgError (TEXT("Test: SetupDiGetClassDevs: ")); return FALSE; } // // Go through the list of all devices found. // int nIndex = 0; while (SetupDiEnumDeviceInfo (pspRequest->DeviceInfoSet, nIndex, DeviceInfoData)) { // // Get the service name for that device. // if (!SetupDiGetDeviceRegistryProperty (pspRequest->DeviceInfoSet, DeviceInfoData, SPDRP_SERVICE, NULL, (PBYTE)szServiceName, sizeof (szServiceName), NULL)) { dbgError (TEXT("Test: SetupDiGetDeviceRegistryProperty: ")); SetupDiDestroyDeviceInfoList (pspRequest->DeviceInfoSet); return FALSE; } // // We only care about service "ac97smpl" // DWORD lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT); if (CompareString (lcid, NORM_IGNORECASE, szServiceName, -1, TEXT("AC97SMPL"), -1) == CSTR_EQUAL) { // // We found it! The information is already stored, just return. // Note that we have the device list still open - we have to destroy // the list later. // return TRUE; } // Take the next in the list. nIndex++; } // // We did not find the service. // SetupDiDestroyDeviceInfoList (pspRequest->DeviceInfoSet); return FALSE; }