How to share image data between applications? - c++

I already have an application called "old" which renders an image in which the image data is stored in form of session, and I need to read that data from this existing "old" application to an application called "new".
How do I pass this data? Do I need to get the memory address of the session and pass it to my other application?
And even if I have the memory address how do I read the entire data? It has loads of data stored.
Named pipes and all the others create a link between two processes and when one process writes to a memory location the other process reads it.
But I have a memory address of one process as an input, isn't the only thing that I have to do is just read the data from that memory address from the other process?

You have quite a few options to communicating between two processes
Save the data to a file and read if from the other application
Use a named pipe to establish a connection
Use a named shared memory created using win32 API calls
Use a shared memory area within a DLL loaded from both applications

As you are using C++ I would strongly suggest that you take a look at Boost interprocess. It provides nice platform independent access to interprocess communication, where most of the tedious and error prone low level details are shielded from you.

Given the leanings of your question, I would suggest #shoosh's named shared memory suggestion. I've used that before for images from cameras and such as well.

Related

Access the RAW disk using C/C++

I have a large storage device (flash memory) plugged onto my computer via the PCIe bus, I want to access such device directly, i.e., without any file system (e.g., NTFS or ext4) on it.
How can I do this using C/C++? (on both Windows 7 and Linux)
I am wondering if I can 1) open the device just as a file, and then read and write binary data to it, or 2) allocate the whole device using some function like malloc, then each byte on the device have an address so that I can access them based on the addresses.
I prefer the second way if it possible, but I don't know if the OS supports this since it seems the address space needs to be shared with the main memory.
According to Microsoft documentation:
On Windows you can open a physical drive using CreateFile using a path of the form
\\.\PhysicalDriveN
where N is the device number or a logical drive using a path of the form
\\.\X:
You will need to seek, read and write in multiples of the sector size which can be retrieved using DeviceIoControl() with IOCTL_DISK_GET_DRIVE_GEOMETRY.
On Linux each storage device ends up getting a device entry in /dev. The first storage device is typically /dev/sda, the second storage device, if one is present, is /dev/sdb. Note that an optical disk is a storage device, so a CD-ROM or a DVD-ROM drive, if one is present, would get a device node entry.
Some Linux distributions may use a different naming convention, but this is what it usually is. So, you'll need to figure out which device corresponds to your flash disk, and just open the /dev/sdX device, and simply read and write from it. Your reads and writes must be for even block (sector) sizes, and seeking the opened file governs which disk blocks/sectors the subsequent read or write will affect.
Generally, /dev/sdX will be owned by root, but there are usually some Linux distribution-specific ways to fiddle the userid that owns a particular device node.

Can a SYSTEM process share data with a non-SYSTEM process?

I'm trying to use QSharedMemory and QClipboard to share data between a SYSTEM process (running on the WinSta0\\Winlogon desktop) and a normal user process, but both fail to share data with others non-SYSTEM processes running on the normal desktop. I belive this is because the WinSta0\\Winlogon desktop is a isolated desktop.
My app is a program that takes shots of the Windows Secure Desktop and send it to clipboard.
The question is: Is there any way to share memory data between that process and non-SYSTEM processes? (Actually I'm using a file to do the job).
On Windows Vista and later, system services run in an isolated session ("session 0"). This is the most likely cause of your problem. (Note that all system services run in session 0, regardless of whether they are running in the SYSTEM security context or not. Similarly, it is possible to launch processes as SYSTEM in an arbitrary session.)
Each session has a separate WinSta0 workstation, and hence a separate clipboard. So clipboard functionality is not going to work here.
It is possible for file mapping objects (shared memory) to work across session boundaries. However, I don't know whether it is possible to do this with Qt. The best bet would appear to be to use setNativeKey which presumably determines the name of the file mapping; to make a file mapping cross session boundaries, use a name that begins with Global\ as described in the MSDN article on CreateFileMapping. If possible, consider using the Win32 API directly rather than Qt.

Flex4/AIR with NativeProcess: How to pass an image to the native process?

I am trying to make an AIR application, that needs to pass an image (.jpg/.png) to a C++ app, that does number crunching.(this needs to be done very often, like every 2-3 seconds.) I've managed to pass the image by saving it to disk via AIR, then opening this file with the C++ program (and passing the filename as an argument to the C++ program), but this method is really slow, because it involves lots of disk I/O.
Is there a method to send an image directly to a native process?
Edit: There is a good Flash-C++ communication example at http://www.marijnspeelman.nl/blog/2008/03/06/face-detection-using-flash-and-c-revisited/ using sockets. The big problem with this method is, that some firewall settings can block the communication (i get a windows firewall warning, when i start the app).
There are several ways to transmit data between two processes.
One of the most efficient, and easy to setup, is to use TCP sockets.
It means that your C/C++ will for (TCP/HTTP) requests, and that your AIR program will send the request with all data inside.

Read data in executable on run

G'Day!
I have an executable (Unix or Windows - it should be cross-compiling). If one opens this executable by any editor and write some stuff to the end - the application would still run perfect.
On execution, the application with all its data loads to the RAM. So, the user-written part of file is also loaded into memory.
Is there any chance to read this data?
I need this data in fast access. Other workarounds are not OK, because it takes too much time:
Reading directly from file (on hard disk) or mapping it is not fine, because the application have to read this file on each run, but this application has lots of launches per sec.
Using shared memory with another process (something like server, which holds data) is not cross-compiling
Using pipes between app and so-called server is not fast enough, imho.
That's why I decided to write some stuff to the end of application.
Thanks in advance!
Are you re-inventing
exe packers (see http://en.wikipedia.org/wiki/Executable_compression)
embedded resources? A portable approach was described here Is there any standard way of embedding resources into Linux executable image?
I also think you're might be optimizing the wrong things.
Reading directly from file (on hard disk) or mapping it is not fine, because the application have to read this file on each run, but this application has lots of launches per sec.
The kernel[1] is way smarter than we are and is perfectly capable of caching the mapped stuff. Heck, if you map it READ-ONLY there will be no difference with directly accessing data from your program's base image.
[1]: this goes for both WIndows and Unix

SQL CE OutOfMemoryException consuming web service

We are continually receiving OutOfMemory exceptions when trying to download documents via a web service. We are storing the documents byte array data as part of a serialized mesage object and the original documents are all ~500kb in size. The only other thing in the message's object graph are two string properties for correlation.
We have tried retrieving the document compressed and uncompressed with the same issues. Now I believe that the exception is been raised when trying to deserialize the message and not while downloading the stream.
I know this is a vague question, but do any of you have any idea what could be causing this? The amount of data transferred here seems very small and there is little else happening on the device at the time of transfer.
Memory is VERY tight on Windows Mobile devices -- it really is a world of pain to work with. First of all, your total memory for a process is (if I remember right) 32 MB. Now that gets filled up not just with in-code memory allocations, but also loaded code from DLLs, the EXE and such.
Now when you're downloading the 500KB into a byte array, it doesn't just need 500KB. It needs 500KB of CONTIGUOUS MEMORY, something it's very unlikely to find once the app has been running for a short while.
My recommendation would be to download the files directly with an HttpRequest rather than the web service. Maybe the web service can pass back the URL that you need or something like that. But download the file directly and you can process it in chunks -- read 8K, then write that 8K to disk, then read another 8K, etc.
In order to get OutOfMemory exception the code either has a bug that consumes memory until the device has no more, or the device generally doesn't have enough memory to handle even 500Kb variations.
You say "while trying to download documents" maybe you keep them in memory and you get the exception.