Qt - write to registry 32/64 issue - qt

I'm writing a Qt application for windows, and using windows 7 64 bit.
The application has to write to the registry, I tried to use QSettings class, but as I found in the documentation:
On Windows, for 32-bit programs running in WOW64 mode, settings are
stored in the following registry path:
HKEY_LOCAL_MACHINE\Software\WOW6432node\MySW
Is there a way to override it and write to: HKEY_LOCAL_MACHINE\Software\MySW directly?
Clarification:
The application is writing to the registry, the keys written are to be used by other application, which I cannot know if running on 64 or 32 bit mode.
I know it is possible in C#, so it must be possible in C++.

See this article on MSDN:
32-bit and 64-bit Application Data in the Registry
It appears that using some of the Win32 API you might be able to change how this behaves. Although I'm not sure why the default behavior won't work for you.

I suppose that if you want to do it in Qt then this would be the most appropriate way:
[ Source: http://doc.qt.digia.com/4.7/qsettings.html#accessing-the-windows-registry-directly ]
Accessing the Windows Registry Directly On Windows, QSettings lets you access settings that have been written with QSettings (or settings in a supported format, e.g., string data) in the system registry. This is done by constructing a QSettings object with a path in the registry and QSettings::NativeFormat.For example:
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Office", QSettings::NativeFormat);
All the registry entries that appear under the specified path can be read or written through the QSettings object as usual (using forward slashes instead of backslashes).For example:
settings.setValue("11.0/Outlook/Security/DontTrustInstalledFiles", 0);

Related

Qt Use Same Settings Between Two Apps

I have two projects that both use the settings:
QSettings settings(
QSettings::SystemScope,
QCoreApplication::organizationName(),
QCoreApplication::applicationName());
I was under the impression that with SystemScome and the same application and organization names that these settings would be linked. But they aren't. What's the best approach for this?
Thanks!
EDIT:
It was on Linux, and I believe sudo needed to be used for SystemScope. UserScope did however work.
As it is thoroughly written in documentation - QSettings: Platform Specific Notes the path which QSettings use to store settings is uniquely determined by application and organization name parameters.
The First thing you could do is to check is settings are truly being written in location mentioned in link above for your system and what is different for those two applications. For example, there is a singular case that for windows their will be different for x86 and x64 applications.
Also if you try to use them simultaneously for both applications you should remember to use sync () function or create new QSettings instances when it's needed so the apps wouldn't conflict in operating on them.

how to zero copy in a Qt C++ programme?

I have to implement zero copy method in a program in Qt C++,I read about it and got transferto() method.as described below:
public void transferTo(long position, long count, WritableByteChannel target);
but i can't understand how it works.It is written that Internally, it depends on the underlying operating system's support for zero copy.
So I tried to write a function but i didn't get the meaning of "position" and "channel" here.
Can anyone help me?
There is no cross-platform way to do zero copy in C++, and there is no zero-copy API in Qt. You can implement it for your target OS using provided API:
Linux supports zero copy through system calls such as sys/socket.h's
sendfile, sendfile64, and splice. Windows supports zero copy through
the TransmitFile API.
Source

How can I automatically start application at booting

I'm using Qt.
I could not find the function or class to start application at booting time.
In windows, for example, add register to HKMU/Software/Microsoft/Windows/CurrentVersion/Run.
I wanna know the function/class like above example.
You can use QSettings in order to set a value at Windows Registry.
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run",
QSettings::NativeFormat);
and then use the setValue function.
However this will work only in Windows so it is better to use an #ifdef before calling it.
The only thing I can think of is the QtService framework. It is available for all the major platforms (look here). It might not be exactly what you were looking for but it may help.
It is also important to mention that a Windows service has no direct access to the graphical interface. This means that if the application is graphical, you'll probably have to redesign it.
There is no such API in Qt, you have to search for 3rdparty library or write whole code on your own.

What does regsvr32 filename.ax actually do?

regsvr32 filename.ax
I just see it said something installed successfully,but what's the whole story?
COM that is widely used in Windows relies on registration. A component will provide type libraries, interfaces and classes. Each of these are defined by a GUID to uniquely name them. COM components can also defined ProgID's that are kind of shortcuts to the unwieldy GUID's.
All this information is stored in a special registry hive on the computer named HKEY_CLASSES_ROOT. Use RegEdit.exe to view it. In particular you can find type libraries in HKEY_CLASSES_ROOT\TypeLib, interfaces in HKEY_CLASSES_ROOT\Interface and classes in HKEY_CLASSES_ROOT\CLSID. Some of the information in the registry will contain the path of the actual DLL with the component allowing Windows to locate and load the component when it is requested.
When you install a COM component it is necessary to create the correct registry information. By convention the DLL can provide two exported functions:
DllRegisterServer
DllUnregisterServer
When you execute RegSvr32.exe MyComponent.dll the RegSvr32.exe executable will attempt to call DllRegisterServer in MyComponent.dll. The DLL is then supposed to create all the necessary registry entries to allow the component to be used.
In a similar way you can use RegSvr32.exe /u MyComponent.dll to unregister the component. That will remove all the information previously added to the registry.
Windows relies heavily on COM and it is very important that COM registrations are up to date. Unfortunately there is nothing that blocks you from deleting an already registered COM component. This will leave dangling pointers in the registry pointing to the no longer existing DLL. You can't even unregister it since it no longer exists.
Another problem is when two different applications requires different versions of the same component. The registry can only point to one of the two versions, and this may cause one of the applications to fail.
Microsoft has created fixes for these problems. It is much better to provide an installer for the COM component that is able to repair and uninstall the component if it has been deleted. You are also able to create side-by-side installation of the same component in different versions.
It basically calls into your dll (named filename.ax in this case) and call its "DllRegisterServer" method.
In the case of directshow filters, it might "register" those filters in the windows registry so that directshow knows about them.
ex: https://github.com/rdp/directshow-demo-audio-input-open-source/blob/master/acam/virt_audio_all.cpp#L698 calls
https://github.com/rdp/directshow-demo-audio-input-open-source/blob/master/acam/virt_audio_all.cpp#L631
Though there are more simple versions out there.
regsvr32 registers DLL's and EXEs into the Windows Registry (usually COM Type Libraries, Class IDs, Interface IDs etc). You can use regedit to navigate the registry.

InstallShield: Setting a Custom Action's Property Value from a Release Property

I'm trying to automate InstallShield from my build process, and I need to set a type 51 Custom Action's Property Value from my Release's Product Configuration Flags property. What is the syntax (something in square brackets?) to do that?
From here...
...to here:
You'll probably need to do a string replace on the InstallShield project to pull this off:
1) Under General Information | Project File Format, set the format to "XML", and save the project.
2) Next write a script to search the xml file for the name of your custom action, and replace the value with your Product Configuration Flags.
We've used this straightforward technique to change a number of properties at build time, including version numbers.
InstallShield also has an automation interface. FYI:
http://kb.flexerasoftware.com/doc/Helpnet/installshield12helplib/IHelpAutoISWiProject.htm
For advanced developers, InstallShield
exposes a COM interface that allows
you to perform many of the same tasks
from a program, such as a Visual
Basic� executable, or a script, such
as a VBScript file in Windows
Scripting Host. By calling methods,
setting properties, accessing
collections, and so on, through the
automation interface, you can open a
project and modify its features and
component data in many of the same
ways that you would in the
InstallShield interface.
MSI Tip: Building Releases with the InstallShield Automation Interface
There's a bit of a learning curve, but once you've got it, it more reliable and robust than editing the XML file manually.

Resources