Click here to Skip to main content
15,846,091 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all,

I tried to use the function "FbwfCacheThresholdNotification" of the fbwf library of microsoft. The library is used in windows XP embedded and doesn't work on normal windows I guess. The documentation can be found here: [^]

The documentation is insufficient for me. What managed type can I use for handle?

Currently I tried the following:

Create a delegate of type:
delegate void ThresholdNotificationDelegate();

Passing that delegate to the unmanaged function:
[DllImport("fbwflib.dll", CallingConvention = CallingConvention.Winapi)]
static extern UInt32 FbwfCacheThresholdNotification(UInt32 threshold, [MarshalAs(UnmanagedType.FunctionPtr)] ThresholdNotificationDelegate thresholdNotification)

When I call the function I get "6" as return value, that means "invalid handle".

Thanks for your help!
Updated 26-Jan-16 2:55am

1 solution

The argument is an event handle. Try changing the declaration to:
[DllImport("fbwflib.dll", CallingConvention = CallingConvention.Winapi)]
static extern UInt32 FbwfCacheThresholdNotification(UInt32 threshold, Microsoft.Win32.SafeHandles.SafeWaitHandle thresholdNotification);

You should then be able to create a new AutoResetEvent (or a ManualResetEvent) and pass its SafeWaitHandle property to the function. That event will then be signalled when the cache falls below the threshold.
Share this answer
Georg Newton 27-Jan-16 8:26am    
Thank you very much for your help.
I created a handle by using the unmanaged "createEvent" function before, but substituted it by using your solution now.
I pass AutoResetEvent.SafeWaitHandle to the function and it is accepted. So far it works.
Then I create a new thread where I wait for the handle with AutoResetEvent.WaitOne() but it is not signaled when the threshold is exceeded.
When I use AutoResetEvent.Set() to signal the event manually, it works and the thread continues.
Do you have an idea what's the problem? Is there an issue with permissions or sth. like that?
Richard Deeming 27-Jan-16 8:32am    
What parameters did you pass to the CreateEvent function when it was working? You might need to use a ManualResetEvent instead, or even the base EventWaitHandle class. These all eventually call CreateEvent for you behind the scenes, so they should work in the same way.
Georg Newton 27-Jan-16 8:51am    
Sorry if what I wrote was unclear. With the createEvent function the event was not signaled either. Just the return value of FbwfCacheThresholdNotification() was fine.
Richard Deeming 27-Jan-16 8:58am    
According to this thread[^], the parameters to CreateEvent need to be:

That corresponds to an AutoResetEvent with the initial state set to false, so that should work.

Are you sure you're passing in the cache size threshold in megabytes, not bytes?
Georg Newton 28-Jan-16 6:09am    
Yes, I'm passing the cache size in megabytes, but maybe I was not aware of the fact, that it is the remaining cache or miscalculated the actual usage of the cache and did something wrong in testing the functionality.
Now I tested it again and it works.
Thanks a lot for your time and effort.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900