![]() |
|
![]() ![]() ![]() |
|
StrikeTheCore |
|
|||
Новичок Профиль Группа: Участник Сообщений: 11 Регистрация: 25.5.2006 Репутация: нет Всего: нет |
Hi,
Question for any of you English-speaking Borland experts out there. I have a program in Borland 6 running on Windows XP that needs to be able to save a file (overwriting the previous file) using std::ofstream. However the file is on a network and is often open on other computers which prevents the computer that needs to overwrite it from having write access. Is there any way to check to see if this file is already open so the user can be warned that any changes made will not be saved? Thanks -Brian |
|||
|
||||
SergeCpp |
|
|||
![]() ![]() ![]() Профиль Группа: Участник Сообщений: 955 Регистрация: 8.8.2005 Где: At Home Репутация: нет Всего: 124 |
Hi, Brian!
Try to open that file through API's CreateFile with dwDesiredAccess = GENERIC_WRITE and dwShareMode = 0 Then close it and create ofstream. But you are risking... File can be reopened remotely in between... So create ofstream as quickly as possible... It was quick-and-dirty method, but it's simple... Serge |
|||
|
||||
stmamont |
|
|||
![]() Опытный ![]() ![]() Профиль Группа: Участник Сообщений: 343 Регистрация: 13.3.2004 Где: влг Репутация: 3 Всего: 3 |
Is there any method to lock file quickly?
And only then write to file? Это сообщение отредактировал(а) stmamont - 13.8.2006, 08:28 |
|||
|
||||
SergeCpp |
|
|||
![]() ![]() ![]() Профиль Группа: Участник Сообщений: 955 Регистрация: 8.8.2005 Где: At Home Репутация: нет Всего: 124 |
You can hold file opened for writing with exclusive access.
Or you can use LockFile or LockFileEx API. |
|||
|
||||
stmamont |
|
|||
![]() Опытный ![]() ![]() Профиль Группа: Участник Сообщений: 343 Регистрация: 13.3.2004 Где: влг Репутация: 3 Всего: 3 |
But, as I understood
LockFile - is only used by WriteFile, ReadFile but not by std::ofstream |
|||
|
||||
![]() ![]() ![]() |
Правила форума "С++ Builder" | |
|
Запрещается! 1. Публиковать ссылки на вскрытые компоненты 2. Обсуждать взлом компонентов и делиться вскрытыми компонентами
Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, Rrader. |
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей) | |
0 Пользователей: | |
« Предыдущая тема | C++ Builder | Следующая тема » |
|
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности Powered by Invision Power Board(R) 1.3 © 2003 IPS, Inc. |