Hi,
I am writing a Win32 DLL (crate-type = ["cdylib"]), target=i686-pc-windows-msvc) as a plugin for an external application.
The DLL has 3 functions that are called from the application:
pub unsafe extern "stdcall" fn PluginStart(aOwner: uintptr_t) { ... }
pub unsafe extern "stdcall" fn PluginFinalize() { ... }
pub unsafe extern "stdcall" fn AccessVariable(
variableIndex: u8,
value: *const c_float,
writeValue: *const bool,
) { ... }
PluginStart is called when the application starts and loads all plugins, PluginFinalize is called when the application ends.
AccessVariable is called around 20-100 times per second per variable (around 20-30 different variables in total) and gives some internal variables/values to the plugin.
AccessVariable should be fast/small and must be non-blocking, because it impacts speed and stability of the application.
The structure I have planned is that AccessVariable copies the received values ββin an array, does nothing else and returns immediately. And at the beginning PluginStart starts a thread that carries out the actual processing of the data (checking whether values ββhave changed, conversions, forwarding data to a serial port, etc.)
However, the data must somehow get from AccessVariable to the thread started by PluginStart. In C++ (with other plugins that are not mine) a global array of floats is simply created, which is then accessed. Yes, I know that this is bad and why it is bad.
How can and should I do this in Rust? I have searched, including in this forum, and have not found anything suitable. The solutions I have found are based on there being some kind of "main" from which the threads that communicate are started/spawned. But there is no "main" in this DLL.
Any kind of tips and help and links to solutions are very welcome. Thanks a lot.