To use input and output functions you don't need a console. You just need to use the pipe like squidge said.
But, there's another way too. You can use shared memory. To do this you can use QSharedMemory in the Qt application and in the second process you can use the combination of CreateFileMapping, OpenFileMapping, MapViewOfFile.
You can find an example here:
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
But read the comments, try to change the name to a name that doesn't use the Global namespace.
Use Local\ or simple don't type use a name that doesn't have the Global\ or Local\ like "myappsharedmem"
*edit:
And you have the alternative to create a dll with a shared section. So you load the .dll in the two processes and use a function in the dll that returns a pointer to a shared section variable.
To have a shared section you just need to do this.
#pragma data_seg(".shared")
char sharedMemBuf[1024] = ""; //This buffer will be the shared memory used for read/write.
#pragma data_seg()
char* pointerToSharedMem() // Just get a pointer to the buffer.
{
return sharedMemBuf;
}
#pragma data_seg(".shared")
char sharedMemBuf[1024] = ""; //This buffer will be the shared memory used for read/write.
#pragma data_seg()
char* pointerToSharedMem() // Just get a pointer to the buffer.
{
return sharedMemBuf;
}
To copy to clipboard, switch view to plain text mode
To see the changes in the buffer just add a timer or check if in some event.
To write just use change it by the normal way.
You can use a function in the dll that copies memory for write and send a message to registered windows, so you can simple find when the buffer is changed.
Example:
/*Dll code*/
#define MYAPP_SHARED_EVENT WM_USER + 36
// Just typed a WM_USER (custom message) and a random number lol
vector<HWND> wndList;
void registerShareEventForWindow(HWND wndList)
{
wndList.push(wndList);
}
void copyMemoryToBuffer(char* data, int size)
{
memcpy(sharedMemBuf, data, size);
vector<HWND>::iterator wnds = wndList.begin();
for (; wnds != wndList.end(); wnds++) SendMessage(*wnds, MYAPP_SHARED_EVENT, (WPARAM)sharedMemBuf, 0);
// Here i'm using wparam to store the pointer for the buffer.
}
/*Dll code*/
#define MYAPP_SHARED_EVENT WM_USER + 36
// Just typed a WM_USER (custom message) and a random number lol
vector<HWND> wndList;
void registerShareEventForWindow(HWND wndList)
{
wndList.push(wndList);
}
void copyMemoryToBuffer(char* data, int size)
{
memcpy(sharedMemBuf, data, size);
vector<HWND>::iterator wnds = wndList.begin();
for (; wnds != wndList.end(); wnds++) SendMessage(*wnds, MYAPP_SHARED_EVENT, (WPARAM)sharedMemBuf, 0);
// Here i'm using wparam to store the pointer for the buffer.
}
To copy to clipboard, switch view to plain text mode
/* qt and non-qt application code */
switch(msg->message) // use this inside winEvent or wndProc function
{
case MYAPP_SHARED_EVENT:
onSharedBufferChanged((char*)msg->wParam);
break;
}
/* qt and non-qt application code */
switch(msg->message) // use this inside winEvent or wndProc function
{
case MYAPP_SHARED_EVENT:
onSharedBufferChanged((char*)msg->wParam);
break;
}
To copy to clipboard, switch view to plain text mode
NOTE: This isn't thread-safe function so you can use a "wait" system or just only respond to the events without changing the buffer in the same time.
It's just a normal array pointing to a heap section that's shared between all processes that load that dll.
To prevent other processes from loading the dll you can just use a signature system to check if it's your process.
Bookmarks