Controlling ffdshow from .Net - c#

ffdshow has this awesome little API for controlling playback of video files. It allows you to change subtitles, fast forward, get the name of the file playing, etc...
Its implemented as a windows message loop that accepts user messages and posts data back using WM_COPYDATA.
I would like a c#/vb class that will allow me to perform all the control. (send and receive messages). I know how to write this. I'll probably create a hidden window hook up a windows message loop and send messages back and forth.
I would like to know if someone has already done this, cause implementing it is a bit fiddly, and this is for an open source project anyway so I have very limited time to work on it.
This question remains unanswered, the bounty system chose a wrong answer for this question.

Looks like the FFDShow-tryout guys already built a wrapper. I haven't tested it out (probably tonight), but it looks promising.
FFDShowAPI at FFDShow's wiki page

A plugin in class has been created and is available here:
http://damienbt.free.fr/Information.htm

Related

World of Warcraft image processing

As I´ve looked for a way to create an addon, which checks the WoW-PvP-Queue-Status, for creating a REST service, I was told that it`s not possible to have a real-time connection between an addon and a REST service. So I was thinking about another way to solve my problem and came to the point, where I thought about analyzing the WoW-Window and searching for a visual pattern to accomplish for what I´m looking for.
My program should check and tell me, whenever a user of the program is queuing for an battleground and should also tell me on which battleground he/she is queuing, so I can gather the data and post it to my service/website. I could create some visual feedback with an WoW-Addon, for the events I´m looking for ... like a signal, which tells my program what to do.
So I´d like to know, how I would accomplish to create such signal-interpreter( so like an Screen Grabber). I was thinking about OpenCV, but dont know where to start, especially I´m kinda curious in how Warden(Anti Cheat Engine) would interpret such program, I really don`t want my users to get banned for such a thing. It should really just interpret visual feedback of the addon I´d create.
So for example:
If user queues for Arathi Basin, a yellow signal should pop and if the yellow signal pops up, the program tells my service that player xyz has queued up, which should be displayed later on ... on my homepage in real-time. If the user queues up for Warsong, another signal pops up, etc.
I´m currently just experienced with C#/.NET in an early stage and would start a little project with such an service, so what I need to learn to get this thing build up?
I really just would love to have a little guide on which knowledge I need, to solve this problem.
for Windows it is doable but grabbing WinAPI is a bit unstable.
So write new App that:
you need to find the WoW Client window (its handle)
grab its canvas as bitmap
If gfx driver allows it if not try to take the desktop image instead. So create canvas with:
Canvas->handle = GetDC(WOW_window_handle);
its size you get like this:
RECT r; GetWindowRect(WOW_window_handle,&r);
so now just copy rectangle from canvas to your bitmap for processing ...
then you can do what ever you need to
as the image is computer generated it will not be too much noisy only scaled +/- some filters so it should be relatively easy to detect if the image contains battleground info or not. Also detect/read text in it should be easy enough
if searched event/info was detected
then just send the data to your WEB
if you need to have this info also inside the ADDON
then you need to search for some way to receive it. I am not familiar with WoW addon programming so have no clue...
but I would try:
if you got any IPC capability from Addon use it
if you have access to files
then continuosly scan a file from addon and send the info there (be careful with multiple file access conflicts)
can try to send keystrokes to your WoW client
if you can detect them from Addon or specific actions like wrote specific text message (not conflicting your movement keys)
if you can hack in your Server/Clienet TCP/IP stream
you could inject packets with specific meaning like incoming private message etc but you would need to be familiar with WoW Server/Client communication (WoW uses SRP6 if I remember correctly) and it would increase the ping lag ... You still need to be able to detect it from Addon on the other hand you should be able to detect packets related to battleground and do not need to OCR/CV the WoW image ...
see these related Q/A's:
list windows handle from outside app
simple OCR
How to recognize UI elements in image
Putting an application in between client and server ... contains example of WoW SRP6 protocol packets in mine post there
MaNGOS source repository ... can learn much about WoW from this
[Notes]
Each of the bullets is suitable for separate question so start coding and when hit a problem ask specific question about it

How can I know if the user has made a screenshot?

I'm writing a small c# program, I don't want the final user to take screenshots while using my program, is it possible? Or even if he takes one, how can I know it?
Thanks in advance and sorry if this is a poor-content question due to my lack of experience in c# coding.
You can create a system-wide keyboard hook using the low-level keyboard filter and cancel any printscreen keyboard combination. But if someone has also installed a helper application (like Gadwin or something) it'll become a lot more difficult because you won't know beforehand what keyboard shortcut you should catch (most tools allow to specify your own hooks).
Here's an article on using hooks in C#
and here's a ready-made keyboard hook library for .net that uses global mouse and keyboard hooks (use Google to find more freeware and commercial libraries and tools).
On a side note: it's generally not preferred to change the system behavior. Screenshots are system behavior and serve a distinguished purpose for trouble shooting. If you prevent this, users will not be able to show you a screenshot of something wrong. But if you must do it, you can do it.
EDIT: on a deeper level, you can install an API hook. All screenshot applications use API calls to get the content of a (part of) the screen. But API hooks are hard to get right. A more trivial way is probably by writing a user-level driver. While you can prevent all this, it is really worth all the trouble?
You might want a keyboard hook. But it'll tell you if the user pressed the "print screen" key, not if someone programmatically take a screenshot using some GDI function.
I doubt it's possible to prevent all the ways of taking a screenshot.
General answer: No. It's not possible to detect this - especially from C#. There are dozens of ways to take screenshot and even applications written in C++/WinAPI can only detect some of them, but not all.
Also consider - what if user is running your app in virtual machine? He'll be able to take screenshots at host machine and you can do absolutely nothing to detect (not even prevent) this.

How to simulate keyboard input in ALL applications?

I'm writing an app (in C#) which as a part of it must simulate and send some key strokes to another application. I'm using http://inputsimulator.codeplex.com/ project for simulating keys, and it works in many applications, but in some it doesn't - i.e. Mortal Combat 4.
I've googled about it, and found many answers varying from 'it's impossible' to 'you must use XXX library' etc. Those answered scared me a lot, and even nearly convinced I'm not able to do it at that time, BUT...
M$ Virtual Keyboard works. It works in ALL applications. So it IS possible... Does anyone of you, clever guys, know how can I achieve this?
Ok, I think I finally got it to work. I used API Monitor recommended by Neal P and it showed just minimal differences between OSK calls and mine. A bit later I've tried to make my calling thread sleep some time between sending messages with press and release key and that was it.
Although you were able to achieve your purpose, the way you achieved it does not fundamentally answer your question: How to simulate keyboard input in ALL applications?
There's a bunch of situations where the common user mode Microsoft API already mentioned does not work, like game applications that use the DirectInput API or protected games.
I have built a library that can help in this situations, it provides a simple C API that internally communicates with device filter drivers. It is able to send input for DirectInput based games and also is able to bypass some game protections. I have checked and it is still able to bypass some known game protections by using the x64 version of the library. Game protections commonly hook only the x86 system's api. Well, at last now, 18 February 2012, this is what I'm seeing happening.
Take a look at SendKeys on MSDN

Getting input into a process

While talking with a friend over yahoo messenger, I told him would be really cool to make a bot to answer with generic messages when someone starts a conversation. Upon thinking about what I told him, I realized it would be quite interesting to do something like that. The problem is that I don't know much about win32.
So my question is this: how do you 'link' a process to both another one and the windows environment? The goal would be to have an application running in the background which makes some sort of a query to see what windows are opened and when a new yahoo messenger conversation window appears it should send a list of keystroke events to that window.
I could use either C# or VC++ for the programming part and I can use any help: either specific answers or tips that could help me - e.g.: what to google for. So far my google research only came up with some apps/dlls/code that do that for you and some scripting stuff and I'm not exactly searching for that. I want to do all the work myself so I can learn from it.
It seems like you basically want to control other applications.
There are roughly 2 ways to do this on windows
1 - Use the low level windows API to blindly fire keyboard and mouse events at your target application.
The basic way this works is using the Win32 SendInput method, but there's a ton of other work you have to do to find window handles, etc, etc
2 - Use a higher level UI automation API to interact with the application in a more structured manner.
The best (well, newest anyway) way to do this is using the Microsoft UI Automation API which shipped in windows vista and 7 (it's available on XP as well). Here's the MSDN starter page for it.
We use the microsoft UI automation API at my job for automated UI testing of our apps, and it's not too bad. Beware though, that no matter how you chose to solve this problem, it is fraught with peril, and whether or not it works at all depends on the target application.
Good luck
Not quite the same domain as what you're looking for, BUT this series of blog posts will tell you what you need to know (and some other cool stuff).
http://www.codingthewheel.com/archives/how-i-built-a-working-poker-bot
If you really want to learn everything from scratch, then you should use C++ and native WIN32 API functions.
If you want to play a bit with C#, then you should look the pinvoke.net site and Managed Windows API project.
What you'll surely need is the Spy++ tool.
http://pinvoke.net/ seems to be the website you are looking for. The site explains how to use Windows API functions in higher level languages. Search on pinvoke for any of the functions I've listed below and it gives you the code necessary to be able to use these functions in your application.
You'll likely want to use the FindWindow function to find the window in which you're interested.
You'll need the process ID, so use GetWindowThreadProcessId to grab it.
Next, you'll need to use OpenProcess allow for reading of the process's memory.
Afterwards, you'll want to use ReadProcessMemory to read into the process's memory to see what happening with it.
Lastly, you'll want to use the PostMessage function to send key presses to the window handle.
Welcome to the wonderful world of Windows API programming.
Check out Autohotkey. This is the fastest way to do what you want.

What is a good project to learn Windows Forms programming in C#?

I want to learn c# so I can do some desktop developing. I've developed command-line C# applications and wanted to expand to Desktop applications.
I was thinking of create a screenshot tool like Jing or maybe a plugin for outlook to sync contact information with a service like Google.
What are your thoughts? My past experience is with web applications built in PHP.
I would try to start with something fairly contained, which only touched a few new technologies. For instance, if you want to learn Windows Forms, write something which uses that but doesn't need to talk to Outlook, Google, or the Win32 API. Once you've got the hang of Windows Forms, try one extra technology - try displaying your Google Contacts and do offline editing, for example. Then add another technology... etc.
In my experience it's hard enough to learn one new technology at a time - but that's far quicker than trying to learn two or more in one go. You inevitably get to the stage where you don't know where the problems are, and you have no confidence in any of your code because it's all new. This is particularly important if you're still fairly new to the language as well - although I'm glad to hear you started with some console apps :)
Sorry if that sounds like I'm being a wet blanket, and I realise it sounds like you'll take far longer to get to something useful that way, but I think you're more likely to be successful in the long run.
Find something that most importantly interests and excites you. If you pick something too boring that you don't care about you'll only give up before you get anywhere, and won't benefit at all. Don't do a rubbish project for the sake of learning a language. Do a good project, and do it in a new language as a side effect.
Make a notepad clone. While being fairly simple it will give you a primer in some basic Windows Forms mechanisms such as using menus and reacting on their events, getting input from controls for storage on disk, reading from disk and updating controls, using Docking and Anchoring and so on.
Twitter clients are the new hello world.
I read that somewhere the other day. I can't personally comment on its fitness for your goal.
Do something that you did before, but in another language. Then you won't have to think about most of the architecture of the particular task again, but you'll be able to compare the languages, the frameworks and their approaches.
I bet you'll learn a lot about your previous language as well doing this excercise.
A good project would be a simple windows form. You simply have a chance to put everything together. Or at least see a bigger picture.
You can make it as complicated as you want, without sticking to one area.
Suggesting a specific project is pointless. Think of something that interests you, or an application you want/need, then start making it - searching Stackoverflow/Google/MSDN/etc whenever you can't guess how to do a specific task.
For example, I had to make kiosk application that allowed customers to signup to a companies mailing-list. I tried using the Ruby framework Shoes, but it didn't work correctly on the laptop the application was to run on. Visual C# seemed like a better fit, and would almost certainly run correctly..
So I installed Visual C# Express, added a few labels and a button. I double clicked the button, and realised I didn't know the code to create a new WinForm window.. So I searched Google for "visual C# open new dialogue" or something, and I found out I had to add a new form, then call NewForm newwindow = new NewForm(); newwindow.show(); or similar.
Then, I added the username/email fields, then searched for "how to display an alert box" and checked I could display the form values.
That all worked, so now I had to decide how to store the emails. I had heard good things about LINQ to SQL, so looked into that, decided I wanted to use SQL Server CE (so I didn't have to install/run SQL Server on the laptop). That resulted in more searching around for how to make LINQ to SQL work with SQL Server CE..
Finally, I wanted to have a configuration panel to change the title/button strings etc (accessible via a certain keyboard shortcut).. A Google search revealed how to catch keystrokes, and I asked a Stackoverflow question about representing the settings (using a PanelView or something)
..anyway, the point of that slightly long, rambling and not terribly interesting story is.. You can learn many new technologies at once, as long as you have a specific application in mind (and you're determined to finish it!)
I learned C#, WinForms, SQL Server CE, LINQ to SQL, and simple application publishing stuff in a day - creating a functioning, useful application in the process - simply with a combination of prodding around, Google searches and Stackoverflow..

Categories