I'm attempting to create a "wrapper" module for some windows api functions from user32.dll
. I'm still learning F# so I'm rather fuzzy on how inheritance and polymorphism works in F# and how to apply that to this situation.
I have this module:
module MouseControl =
[<DllImport( "user32.dll", CallingConvention = CallingConvention.Cdecl )>]
extern void ShowCursor(bool show)
[<DllImport( "user32.dll", CallingConvention = CallingConvention.Cdecl )>]
extern void internal mouse_event(int flags, int dX, int dY, int buttons, int extraInfo)
let MouseEvent(flags, dX, dY, buttons, extraInfo) = mouse_event(flags, dX, dY, buttons, extraInfo)
My goal is to be able to "hide" the mouse_event
function from other code that uses this module and instead expose that function as MouseEvent
. With this code both mouse_event
and MouseEvent
are currently available to code that calls this module. How do I hide mouse_event
where it's private to the module?
In your code sample, you already marked the mouse_event
function as internal
- so in principle, you should just need to mark it as private
. However, it looks that F# compiler is ignoring visibility annotations on extern
members, so the easiest option is to put them in a nested module and hide the whole nested module:
module MouseControl =
module private Imported =
[<DllImport( "user32.dll", CallingConvention = CallingConvention.Cdecl )>]
extern void mouse_event(int flags, int dX, int dY, int buttons, int extraInfo)
let MouseEvent(flags, dX, dY, buttons, extraInfo) =
Imported.mouse_event(flags, dX, dY, buttons, extraInfo)
The module Imported
is now visible only inside the MouseControl
module. From the outside, you cannot access anything inside MouseControl.Imported
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With