stop the kernell32 event - delphi

how can i stop or freeze the kernel32 event? for example stop the copy file??

You can't stop the kernel from copying files. If you want to stop the user from copying files, then you need to write a hook that implements the ICopyHook interface.

I'm not sure what exactly you want to do, but if you are using CopyFile winapi, then you should look at CopyFileEx
You can pass there lpProgressRoutine - pointer to your function, and then return from it PROGRESS_CANCEL when you want stop your file copy operation.
Also, starting from Vista, you can cancel sync. IO operations from different thread by CancelSynchronousIo, so you should be able to stop CopyFile operation.

Related

How to stop the GNUradio flowgraph after a specified time?

I am new to GNUradio and I am making a FM Receiver. I am recording the data into the file sink. But I need the data of just 1 millisecond. How can I specify this time so that my flowgraph automatically stop after this time?
I also read some solutions regarding the calling of stop() and start() methods and I tried that in GRC generated python file also but it didn't work for me, may be I made a mistake.
Simply use the "Head" block to stop after passing the 1msĀ·sample rate of samples.

Mixing Custom External File Handler with Micro Focus Default EXTFH

I have written a custom external file handler (EXTFH), but there are some cases where I want to revert to the Micro Focus EXTFH. The cases are on a file by file basis (as opposed to a filetype by filetype basis).
My idea is that upon OPEN, I place a marker in the FCD that tells the subsequent operations (READ, WRITE, CLOSE) as to which EXTFH is in use.
My EXTFH has control and the logic can be very simple if there is a place in the FCD that is guaranteed to not be corrupted by MicroFocus.
Is there a place in the FCD (fcd2.h and fcd3.h) that I can mark an open file as being opened by my EXTFH?
My worst case is that I keep a list of the fcd->handle pointers that I have allocated and if I allocated it, then direct to my EXTFH. If not, direct to the MF EXTFH.
Here is the documentation from Micro Focus on EXTFH:
http://supportline.microfocus.com/documentation/books/sx20books/fhexfh.htm
That is older documentation, but is appears to be pretty much up-to-date.
[edit to clarify how we will use detect which to use: We will use the extension on the file name to determine which file handler to use. For instance, if the extension is: .xyz, then use our EXTFH, otherwise use MF EXTFH]. It appears we can check the filename on every fileio, but I think it would be cleaner if we just checked upon OPEN. For subsequent calls for that file, we would just check something in the FCD.

Delphi - How to prevent application hang when writing to LPT port

I have an application what writes commands to some specialized printers directly on LPT1 port. The code looks like this:
AssignFile(t, 'LPT1');
Rewrite(t);
Write(t,#27 + '#'); // initialize
Sleep(50); // avoid buffer fill
Write(t,#27#32 + Chr(0)); // set default font
...
The problem is that when the printer is not connected to the port, the first Write instruction doesn't do anything, it just hangs up and the entire thread is locked.
Is there a way to define a timeout for these instructions, or can you recommend another library that could do this job? It would be great if it had a Write function similar to the one in Delphi, because the amount of code using this approach is very large, and it would be very hard to change all of it.
You can use SetCommTimeouts to configure a timeout for the printer handle. To get the handle from your TextFile variable, type-cast it to TTextRec and read the Handle field:
var
CommTimeouts: TCommTimeouts;
CommTimeouts.WriteTotalTimeoutConstant := DesiredTimeout;
Win32Check(SetCommTimeouts(TTextRec(t).Handle, CommTimeouts));
You may wish to call GetCommTimeouts first to discover the default values for the other fields before you set the ones you need.
Move your printing code to a separate thread. The built-in text-file functions don't have any timeout mechanism, but you can tell the OS to cancel any pending I/O operations whenever you decide that too much time has passed.
I'd start with CancelSynchronousIo, which cancels all I/O on a given thread. It should allow you to keep all your existing Write calls. Be prepared to handle when they fail upon being cancelled.
That function requires Windows Vista or higher, which shouldn't be a problem nowadays, but won't work if you still need support for Windows XP. In that case, you'll need to use CreateFile to open the port for overlapped I/O. Then you can use CancelIo or CancelIoEx. You'll need to replace all your Write calls since the built-in Delphi functions don't support overlapped operations.

How to run a exe Asynchronously with two arguments in ruby?

exe should run when i am open the page. Asynchronous process need to run.
Is there any way for run exe Asynchronously with two arguments in ruby?
i have tried ruby commands - system() , exec() but its waiting the process complete. i need to start exe with parameter no need to wait for the process complete
is any rubygems going to support for my issue?
You can use Process.spawn and Process.wait2:
pid = Process.spawn 'your.exe', '--option'
# Later...
pid, status = Process.wait2 pid
Your program will be executed as a child process of the interpreter. Besides that, it will behave as if it had been invoked from the command line.
You can also use Open3.popen3:
require 'open3'
*streams, thread = Open3.popen3 'your.exe', '--option'
# Later...
streams.each &:close
status = thread.value
The main difference here is that you get access to three IO objects. The standard input, output and error streams of the process are redirected to them, in that order.
This is great if you intend to consume the output of the program, or communicate with it through its standard input stream. Text that would normally be printed on a terminal will instead be made available to your script.
You also get a thread which will wait for the program to finish executing, which is convenient and intuitive.
exec switches control to a new process and never returns. system creates a subprocess and waits for it to finish.
What you probably want to do is fork and then exec to create a new process without waiting for it to return. You can also use the win32ole library which might give you more control.

Sleep Lua script without halting entire program?

I'm writing a GUI that's meant to be easily customizable by the end-users. The functions are in C++ and are called from Lua. I'm trying to make a Sleep() type function that will pause the script but not the program itself.
I was able to get it working by using threads and making one for each function. However, I want it to be an individual function. As in, instead of having it part of the CreateButton function and every other function, simply having a Delay or Sleep function that only halts the script, not the entire program.
Me being a novice at Lua, I really don't know how to go about this. Any help is appreciated.
I'd look into making a state machine using coroutines and message passing. Treat each button push like a c++ string that gets passed into coroutine resume. You can then build a little state machine that switches on the message. You can then do some UI work and then put the coroutine back to sleep till something sends it another message.
This is pretty handy if you have a state machine that does UI.
pseudo code:
c_obj:wait_for_message("mouse_down");
local message = coroutine.yield();
if(message == "mouse_down") then
update draw function.
end
c_obj:wait_for_message("mouse_up");
local message = coroutine.yield();
if(message == "mouse_up") then
Update UI..
update draw function.
end
etc...
To make your busy-waiting solution more efficient, how about using select() or similar to wait for some GUI events to process, rather than spinning? It seems like something you would need to do in the GUI regardless of the scripting side of things.

Resources