Friday, August 29, 2014

WINAPI Keyword

Wonder whether to add "WINAPI" keyword in a function prototype or not? Here is the main differences:

Specifying WINAPI indicates the __stdcall calling convention; not specifying WINAPI indicates the __cdecl calling convention by default (unless you have set the default calling convention to __stdcall via project settings).

Low-level wise, these calling conventions indicate how parameters are pushed onto the stack when the function is called and indicate whether the calling function or the called function performs stack cleanup.

A unique feature of the __cdecl calling convention is that for such functions, variable argument lists can be used, e.g. :

int __cdecl MyFuntion(int i, ...);

and client code can be written as follows :

int i = MyFuntion(4, 1, 2, 3, 4);

int j = MyFunction(2, 5, 100);

This is not possible for __stdcall functions.

Now because a variable number of arguments can be passed into such a function, only the caller code (i.e. client code) will know how many parameters were actually passed to the function. Hence it is the caller that is responsible to perform stack cleanup. This can result in a larger overall code size because each call to a __cdecl function requires stack cleanup code.

For a __stdcall function, the number of parameters are fixed always and so the called function can perform the stack cleanup operation. This saves code space because cleanup code need be emitted only once for each __sdcall function.

For more information on calling conventions, pls refer to :

Argument Passing and Naming Conventions
http://msdn.microsoft.com/en-us/library/984x0h58(VS.71).aspx

Note that for a function to be exported, it does not have to be specified as WINAPI (i.e. __stdcall). It can also be specified as __cdecl.

Thursday, May 19, 2011

How to add, modify, or delete registry subkeys and values by using a registration entries (.reg) file

View products that this article applies to.
System TipThis article applies to a different version of Windows than the one you are using. Content in this article may not be relevant to you.Visit the Windows 7 Solution Center
This article was previously published under Q310516
To continue receiving security updates for Windows, make sure you're running Windows XP with Service Pack 3 (SP3). For more information, refer to this Microsoft web page: Support is ending for some versions of Windows
On This Page
Expand all | Collapse all
SUMMARY
Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:
322756 How to back up and restore the registry in Windows
This step-by-step article describes how to add, modify, or delete registry subkeys and values by using a Registration Entries (.reg) file. Regedit.exe uses .reg files to import and export registry subkeys and values. You can use these .reg files to remotely distribute registry changes to several Windows-based computers. When you run a .reg file, the file contents merge into the local registry. Therefore, you must distribute .reg files with caution.

Back to the top
Syntax of .Reg Files
A .reg file has the following syntax:

RegistryEditorVersion
Blank line
[RegistryPath1]
"DataItemName1"="DataType1:DataValue1"
DataItemName2"="DataType2:DataValue2"
Blank line
[RegistryPath2]
"DataItemName3"="DataType3:DataValue3"

where:

RegistryEditorVersion is either "Windows Registry Editor Version 5.00" for Windows 2000, Windows XP, and Windows Server 2003, or "REGEDIT4" for Windows 98 and Windows NT 4.0. The "REGEDIT4" header also works on Windows 2000-based, Windows XP-based, and Windows Server 2003-based computers.

Blank line is a blank line. This identifies the start of a new registry path. Each key or subkey is a new registry path. If you have several keys in your .reg file, blank lines can help you to examine and to troubleshoot the contents.

RegistryPathx is the path of the subkey that holds the first value you are importing. Enclose the path in square brackets, and separate each level of the hierarchy by a backslash. For example:
[HKEY_LOCAL_ MACHINE\SOFTWARE\Policies\Microsoft\Windows\System]
A .reg file can contain several registry paths. If the bottom of the hierarchy in the path statement does not exist in the registry, a new subkey is created. The contents of the registry files are sent to the registry in the order you enter them. Therefore, if you want to create a new subkey with another subkey below it, you must enter the lines in the correct order.

DataItemNamex is the name of the data item that you want to import. If a data item in your file does not exist in the registry, the .reg file adds it (with the value of the data item). If a data item does exist, the value in your .reg file overwrites the existing value. Quotation marks enclose the name of the data item. An equal sign (=) immediately follows the name of the data item.

DataTypex is the data type for the registry value and immediately follows the equal sign. For all the data types other than REG_SZ (a string value), a colon immediately follows the data type. If the data type is REG_SZ , do not include the data type value or colon. In this case, Regedit.exe assumes REG_SZ for the data type. The following table lists the typical registry data types:
Data Type DataType in .reg
REG_BINARY hexadecimal
REG_DWORD dword
REG_EXPAND_SZ hexadecimal(2)
REG_MULTI_SZ hexadecimal(7)
For more information about registry data types, click the following article number to view the article in the Microsoft Knowledge Base:
256986 Description of the Microsoft Windows registry
DataValuex immediately follows the colon (or the equal sign with REG_SZ) and must be in the appropriate format (for example, string or hexadecimal). Use hexadecimal format for binary data items.

Note You can enter several data item lines for the same registry path.

Note the registry file should contain a blank line at the bottom of the file.



Back to the top
Adding Registry Subkeys or Adding and Changing Registry Values
To add a registry subkey or add or change a registry value, make the appropriate changes in the registry, and then export the appropriate subkey or subkeys. Exported registry subkeys are automatically saved as .reg files. To make changes to the registry and export your changes to a .reg file, follow these steps:

Click Start, click Run, type regedit in the Open box, and then click OK.
Locate and then click the subkey that holds the registry item or items that you want to change.
Click File, and then click Export.

This step backs up the subkey before you make any changes. You can import this file back into the registry later if your changes cause a problem.
In the File name box, type a file name to use to save the .reg file with the original registry items, and then click Save.

Note Use a file name that reminds you of the contents, such as a reference to the name of the subkey.
In the right pane, add or modify the registry items you want.
Repeat steps 3 and 4 to export the subkey again, but use a different file name for the .reg file. You can use this .reg file to make your registry changes on another computer.
Test your changes on the local computer. If they cause a problem, double-click the file that holds the backup of the original registry data to return the registry to its original state. If the changes work as expected, you can distribute the .reg you created in step 6 to other computers by using the methods in the "Distributing Registry Changes" section of this article.

Back to the top
Deleting Registry Keys and Values
To delete a registry key with a .reg file, put a hyphen (-) in front of the RegistryPath in the .reg file. For example, to delete the Test subkey from the following registry key:
HKEY_LOCAL_MACHINE\Software
put a hyphen in front of the following registry key in the .reg file:
HKEY_LOCAL_MACHINE\Software\Test
The following example has a .reg file that can perform this task.
[-HKEY_LOCAL_MACHINE\Software\Test]
To delete a registry value with a .reg file, put a hyphen (-) after the equals sign following the DataItemName in the .reg file. For example, to delete the TestValue registry value from the following registry key:
HKEY_LOCAL_MACHINE\Software\Test
put a hyphen after the "TestValue"= in the .reg file. The following example has a .reg file that can perform this task.
HKEY_LOCAL_MACHINE\Software\Test
"TestValue"=-
To create the .reg file, use Regedit.exe to export the registry key that you want to delete, and then use Notepad to edit the .reg file and insert the hyphen.

Back to the top
Renaming Registry Keys and Values
To rename a key or value, delete the key or value, and then create a new key or value with the new name.
Back to the top
Distributing Registry Changes
You can send a .reg file to users in an e-mail message, put a .reg file on a network share and direct users to the network share to run it, or you can add a command to the users' logon scripts to automatically import the .reg file when they log on. When users run the .reg file, they receive the following messages:
Registry Editor
Are you sure you want to add the information in path of .reg file to the registry?
If the user clicks Yes, the user receives the following message:
Registry Editor
Information in path of .reg file has been successfully entered into the registry.
Regedit.exe supports a /s command-line switch to not display these messages. For example, to silently run the .reg file (with the /s switch) from a login script batch file, use the following syntax:
regedit.exe /s path of .reg file
You can also use Group Policy or System Policy to distribute registry changes across your network. For additional information, visit the following Microsoft Web site:
http://msdn2.microsoft.com/en-us/library/ms954395.aspx
Note If the changes work, you can send the registration file to the appropriate users on the network.

Monday, July 12, 2010

When A Network Doesn't Connect

Make sure to check the following:

Release and renew the IP address, using the following commend line command:
ipconfig /release
ipconfig /renew

If that doesn't work, make sure to reboot all the routers, and reboot the PC

Remote Performance Monitor for .NET CF Application

First, the .NET Compact Framework SDK is needed on the desktop PC
Second, copy the following files to the \windows directory on the remote device:

From C:\Program Files\Common Files\Microsoft Shared\CoreCon\1.0\Target\wce400\
* edbgtl.dll
* tcpconnectiona.dll

From the service pack 1 installation folder (typically C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\ )
* netcfrtl.dll
* netcflaunch.exe

Third, run the RPM executable (netcfrpm.exe) that is placed in the bin directory of Compact Framework SDK. On my machine, this directory is C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\bin

After that, run the netcflaunch.exe that is on the remote device under the \windows directory.

Come back to the PC. Since the netcfrpm.exe program is already running, to view dynamic performance statistics for your application, select the "Live Counters...." option under the File menu, it will bring up another window.

Before you can view live statistics, you must connect the RPM to your device and specify the application you'd like to run. The instructions for connecting the RPM to your device vary based on whether the connection between your desktop machine and your device is via Active Sync or an Ethernet connection. If your connection is over ActiveSync, your device will automatically appear in the Device drop down in the RPM user interface. If your desktop machine is connected to the device through a direct network connection, you must know the IP address and port number through which the RPM can connect to your device. This information can be obtained by the already running netcflauch.exe from the \windows directory of your device.
It may appear like this:
version 1.0
Connection Parameters:
127.0.0.1 6510

Before connecting to the device, you must specify the application you'd like to monitor using the Application text box. Be sure to type the fully qualified path name to the executable you wish to run on the device. For example, \Program Files\poomcominterop\poomcominterop.exe. If your applications takes command line parameters, you can specify them in the Parameters text box. If you need to specify more than one parameter, be sure to separate them with a space.

After you've selected the device to connect to, and specified the application to launch, click the Connect button in the lower right corner of RPM's user interface. The RPM will send a command to the device to remotely launch the application and start pulling back performance statistics.

Reference:
http://blogs.msdn.com/b/stevenpr/archive/2006/04/17/577636.aspx

Tuesday, September 29, 2009

How to create custom widgets

First, create your custom widget use Qt creator. To wrap up, do the following:

In Interface.h file:

#include QtDesigner
#include "PushButtonPlugin.h"
#include "AnimatedLabelPlugin.h"
#include "LabelPlugin.h"
#include "TextEntryPlugin.h"

//Interface for all Widgets
class MyCustomWidgets: public QObject, public QDesignerCustomWidgetCollectionInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)

public:
MyCustomWidgets(QObject *parent = 0) : QObject(parent)
{
widgets.append(new PushButtonPlugin(this));
widgets.append(new AnimatedLabelPlugin(this));
widgets.append(new LabelPlugin(this));
widgets.append(new TextEntryPlugin(this));
}

virtual QList customWidgets() const
{
return widgets;
}

private:
QList widgets;
};

In Interface.cpp file:
#include "Interface.h"

Q_EXPORT_PLUGIN2(customwidgetsplugin,MyCustomWidgets);

Monday, August 10, 2009

How to build Qt

Steps on how to build Qt:

1. Download Qt version 4.5 from the web server (google it):

search for "qt-win-opensource-src-4.5.0-rc1.zip"

2. If you happened to find Qt4.5 on the website, make sure to download the “zip” version instead of the “exe” version. This will ensure “nmake” to compile under windows operating system.

3. Extract the zip file into a folder, for instance, C:\Qt\qt4.5\

4. Install DirectX 9.0 on your computer under, let’s say C:\DXSDK directory. The installation file for DirectX 9.0 can be found in the following server directory:

\\lab-542\GM\Software Releases\TOOLS\DirectX\dx90bsdk.exe

5. Install the most updated version of Microsoft DirectX SDK on your computer.

6. Bring up a Dos command prompt from Visual Studio 2005

7. Add the following to the environment variables: ( attention!! follow the order, the include and lib directory of Direct X 9 should be in front of any other include and lib directories )

DXSDK_DIR = C:\Program Files\Microsoft DirectX SDK (February 2007)\

(February 2007)

Path = C:\Qt\qt4.5\bin
Include = C:\DXSDK\Include; DXSDK_DIR\Include
LIB = C:\DXSDK|Lib; DXSDK_DIR\Lib

8. At the dos command prompt, goto C:\Qt\qt4.5\

9. type “configure –platform win32-msvc2005 -phonon” to include phonon module in the build process. choose “y”. This will create makefiles for each related module.

10. Type “nmake” under C:\Qt\qt4.5, this will build all the modules, such as “Demo Examples”, “Network”, “Sql”, “Phonon”, etc. one by one.

11. Make sure the phonon module is built successfully, and then go to
C:\Qt\qt4.5\src\plugins\phonon, and type “nmake”. This will build phonon backend plugins.

The following audio and video format will be supported under Qt4.5
For Audio:

AIFF
BASIC
MID
MIDI
MP3
MPEG
MPGURL
MPG
WAV
X-AIFF
X-MID
X-MIDI
X-MP3
X-MPEG
X-MPEGURL
X-MPG
X-MS-WAX
X-MS-VMA
X-WAV

For Video

AIV
MPEG
MPG
MSVIDEO
X-MPEG
X-MPEG2A
X-MS-ASF
X-MS-ASF-PLUGIN
X-MS-WM
X-MS-WMV
X-MS-WMX
X-MS-WVX
X-MSVIDEO

Friday, July 31, 2009

The Qt Resource System

Go to http://doc.trolltech.com/4.5/resources.html

to produce a binary rcc file, use the following command:

rcc -binary myresrouce.qrc -o myresrouce.rcc