@JonB
I've been trying for 2 days but I couldn't get it to work:
main.cpp
int main(int argc, char *argv[])
{
SingleApplication application( argc, argv, true);
mainWindow = new MainWindow();
if (application.isSecondary()) {
if (application.arguments().count() == 2) {
application.sendMessage( argv[1] );
}
return 0;
} else {
QObject::connect(&application, &SingleApplication::receivedMessage,
mainWindow , &MainWindow::slotReceivedMessage);
}
mainwindow.cpp
namespace Win32 {
#include "Windows.h"
}
#define BUFSIZE 4096
void MainWindow::slotReceivedMessage(int instanceId, QByteArray message)
{
Win32::DWORD retval=0;
Win32::BOOL success;
Win32::TCHAR buffer[BUFSIZE];
Win32::TCHAR buf[BUFSIZE];
Win32::TCHAR** lppPart={NULL};
// convert char * to wchar_t *
const size_t WCHARBUF = 100;
wchar_t message_t[WCHARBUF];
Win32::MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, message, -1, message_t, WCHARBUF);
// get full filename from short filename
retval = Win32::GetFullPathName(message_t, BUFSIZE, buffer, lppPart);
QString filePath = QString::fromWCharArray(buffer);
qDebug() << message;
qDebug() << filePath;
}
Since GetFullPathName needs a wchar_t as input, I have to first convert the char to wchar_t, then convert it to full path name.
But when printing out with debug, both the input(message) and output(filePath) are still the same. The GetFullPathName wasn't doing anything. What am I doing wrong?