EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Getting handle of current file

Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.
#34916
Posted: 10/30/2015 10:49:43
by Dennis  (Premium support level)
Joined: 10/20/2015
Posts: 20

Hi,
some WinApi functions like DeviceIoControl require file handle as parameter. I can't get one in CallbackFilter event handlers via CreateFile WinApi function because files are usually locked. Querying the system would be too costly so I am wondering - is it possible to get one from CallbackFilter (I guess it might have it)?

Thanks,
Dennis
#34920
Posted: 10/30/2015 12:17:23
by Vladimir Cherniga (EldoS Corp.)

Hello,
you can use CreateNonCbFile CallbackFilter api call in order to obtain file handle. It uses the same parameters as CreateFile win32 api.
#37021
Posted: 06/17/2016 08:57:47
by Dennis  (Premium support level)
Joined: 10/20/2015
Posts: 20

Hi,
I noticed this in documentation for CreateNonCbFile: "Unlike OpenFile, this method should not be used from within a callback/event handler.". Why is it so? What are the risks? It works smoothly in callbacks as far as I can see...

Thanks,
Denis
#37022
Posted: 06/17/2016 09:38:02
by Vladimir Cherniga (EldoS Corp.)

CreateNonCbFile should be used for ordinal file open from anywhere, kept in mind to use it in application, when callbacks is undesirable. But OpenFile api is a must to use, when need to access file content from within callback handler, and the handle obtained must be used within callback handlers too.
#37023
Posted: 06/17/2016 09:51:02
by Dennis  (Premium support level)
Joined: 10/20/2015
Posts: 20

I don't need file content. I have to create alternate stream for the file OnFileWrite callback is raised for. Is it a legal use case for CreateNonCbFile? Standard CreateFile didn't work for me but CreateNonCbFile does.
#37024
Posted: 06/17/2016 09:55:42
by Vladimir Cherniga (EldoS Corp.)

Quote
Dennis wrote:
Is it a legal use case for CreateNonCbFile? Standard CreateFile didn't work for me but CreateNonCbFile does.

Forget to mention, that CreateFile api is used for the same file, that triggers callback(Create or Open file callback). To open another file, CreateNonCbFile is acceptable.
#37026
Posted: 06/17/2016 10:26:57
by Dennis  (Premium support level)
Joined: 10/20/2015
Posts: 20

Thanks, good to know. Documentation is a bit misleading...
Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages

Reply

Statistics

Topic viewed 3554 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!