--- original/boost/interprocess/detail/win32_api.hpp 2009-07-01 09:48:08.000000000 +0200 +++ fixedlnk2005/boost/interprocess/detail/win32_api.hpp 2009-07-01 09:47:44.792750000 +0200 @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -658,22 +659,13 @@ return false; } - void *hiPSAPI = load_library("PSAPI.DLL"); - if (0 == hiPSAPI) + boost::shared_ptr hiPSAPI = boost::shared_ptr(load_library("PSAPI.DLL"), free_library); + if (!hiPSAPI) return 0; - class library_unloader - { - void *lib_; - - public: - library_unloader(void *module) : lib_(module){} - ~library_unloader(){ free_library(lib_); } - } unloader(hiPSAPI); - // Pointer to function getMappedFileName() in PSAPI.DLL GetMappedFileName_t pfGMFN = - (GetMappedFileName_t)get_proc_address(hiPSAPI, "GetMappedFileNameW"); + (GetMappedFileName_t)get_proc_address(hiPSAPI.get(), "GetMappedFileNameW"); if (! pfGMFN){ return 0; // Failed: unexpected error } @@ -789,20 +781,11 @@ (NtQueryObject_t)get_proc_address(get_module_handle("ntdll.dll"), "NtQueryObject"); //First step: Obtain a handle to the file using Win32 rules. This resolves relative paths - void *fh = create_file(filename, generic_read | delete_access, open_existing, - file_flag_backup_semantics | file_flag_delete_on_close); - if(fh == invalid_handle_value){ + boost::shared_ptr fh = boost::shared_ptr(create_file(filename, generic_read | delete_access, open_existing, + file_flag_backup_semantics | file_flag_delete_on_close), close_handle); + if(fh.get() == invalid_handle_value){ return false; } - - class handle_closer - { - void *handle_; - public: - handle_closer(void *handle) : handle_(handle){} - ~handle_closer(){ close_handle(handle_); } - } handle_closer(fh); - const std::size_t CharArraySize = 32767; //Max name length union mem_t @@ -815,16 +798,7 @@ } ren; }; - class auto_ptr - { - public: - explicit auto_ptr(mem_t *ptr) : ptr_(ptr){} - ~auto_ptr(){ delete ptr_; } - mem_t *get() const{ return (ptr_); } - mem_t *operator->() const{ return this->get(); } - private: - mem_t *ptr_; - } pmem(new mem_t); + boost::shared_ptr pmem= boost::shared_ptr(new mem_t); file_rename_information_t *pfri = (file_rename_information_t*)&pmem->ren.info; const std::size_t RenMaxNumChars = @@ -832,7 +806,7 @@ //Obtain file name unsigned long size; - if(pNtQueryObject(fh, object_name_information, pmem.get(), sizeof(mem_t), &size)){ + if(pNtQueryObject(fh.get(), object_name_information, pmem.get(), sizeof(mem_t), &size)){ return false; } @@ -841,7 +815,7 @@ std::size_t filename_string_length = pmem->name.Name.Length/sizeof(wchar_t); //Second step: obtain the complete native-nt filename - //if(!get_file_name_from_handle_function(fh, pfri->FileName, RenMaxNumChars, filename_string_length)){ + //if(!get_file_name_from_handle_function(fh.get(), pfri->FileName, RenMaxNumChars, filename_string_length)){ //return 0; //} @@ -870,7 +844,7 @@ //Final step: change the name of the in-use file: io_status_block_t io; - if(0 != pNtSetInformationFile(fh, &io, pfri, sizeof(mem_t::ren_t), file_rename_information)){ + if(0 != pNtSetInformationFile(fh.get(), &io, pfri, sizeof(mem_t::ren_t), file_rename_information)){ return false; } return true;