Posted on 17-04-2017
Filed Under (Technology) by bigbang

Once when I updating my Windows 10, I restart my computer by accident. The update doesn’t finish and I try to re-update it again but failed.

I get the Error Code 0x80070570.

The solution is very simple:

go to C:\Windows\SoftwareDistribution\Download

and delete the folder called like this: dbaba752a8aa7203217c758502d7fddd

(0) Comments    Read More   
Posted on 13-02-2014
Filed Under (Technology) by bigbang

While I am using Visual Studio 2008, there is an warning of this content:

warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

There is also this kind of warnings when you are using sprintf etc.. We can use preprocessor _CRT_SECURE_NO_WARNINGS to shutdown this warning.

(0) Comments    Read More   
Posted on 07-09-2013
Filed Under (Technology) by bigbang

When I start a Win32 service, it provides an error code of 1053.

I think It means it can’t find a dll library.

You can try to run the service exe file under it’s folder to find out what kind of library it is missing.

(0) Comments    Read More   
Posted on 30-11-2012
Filed Under (Technology) by bigbang

There are a lot of articles about how to write Windows Services for managed C++ or C# code. But for native C++ coder, the situation is more Complicated. You have to install Windows Service by command line tool in you source code, and add the command line arguments in setup projects.

Here I try to explain the whole process in two steps.

1. Write native Win32 C++ code with service installation code

Unmanaged code service installations should have a command to install as a service and also uninstall. That means you need to add the service installation code in the project.

The key point of the code is the usage of the Service Control Manager ( SCM ). Please follow this example A basic Windows service in C++ (CppWindowsService) to build basic Windows Service application.

After Compilation, then you use argument -install to install the service,

CppWindowsService.exe -install

and use argument -remove to remove the service

CppWindowsService.exe -remove

. Once the service is installed you can edit the service settings in the Windows Service Manager. To access this, run the following from the run dialog or command prompt.

SERVICES.MSC

or

services.msc

2. Add custom action in setup and deploy project to install the service while installing the application

All our application should be packaged to MSI installer to deploy to users. So they can use the setup file to install our application.

There are many third party solutions to provide this package function, like InstallShield. Visual Studio 2008 also provide Setup Projects to do this job.

The key point of unmanaged code service installations is that we should have a command to install as a service and also uninstall. In a Visual Studio setup you’d add a custom action to run your exe with that command line, probably -install and something like -remove as an uninstall custom action.

If you’re not using Visual Studio then just use the ServiceInstall / ServiceControl options in your setup tool.

Let’s use setup projects in Visual Studio as example. The key point is that you need to add custom action at the end of installation. With the above code, the argument of custom action should be -install.

By following steps, we can package the exe files for MSI installer:

To add a deployment project

  1. On the File menu, point to Add, and then click New Project.
  2. In the Add New Project dialog box’s Project Type pane, open the Other Project Types node, select Setup and Deployment Projects. In the Templates pane, choose Setup Project. In the Name box, type Custom Action Installer.

    The project is added to Solution Explorer and the File System Editor is displayed.

  3. In the File System Editor, select Application Folder in the left pane. On the Action menu, point to Add, and then choose Project Output.
  4. In the Add Project Output Group dialog box, CppWindowsService will be displayed in the Project list. Select Primary Output.

    Primary Output from CppWindowsService (Active) appears in the Application Folder.

To add the custom action

  1. Select the Custom Action Installer project in Solution Explorer. On the View menu, point to Editor, and then choose Custom Actions.

    The Custom Actions Editor is displayed.

  2. In the Custom Actions Editor, select the Commit node. On the Action menu, choose Add Custom Action.
  3. In the Select Item in Project dialog box, double-click the Application Folder. Then select Primary output from CppWindowsService.

    Primary output from CppWindowsService appears under the Commit node in the Custom Actions Editor.

  4. In the Properties window, make sure that the InstallerClass property is set to False (this is the default).
  5. In the Custom Actions Editor, select the Install node and add Primary output from CppWindowsService to this node as you did for the Commit node.
  6. On the Build menu, choose Build Custom Action Installer.

Then under the Debug or Release folder of setup project, you can find the MSI file. Just run the file, you will get the Windows service installed.

(1) Comment    Read More   
Posted on 17-10-2012
Filed Under (Technology) by bigbang

I am working on a special project with an unusual design.

In my application/process, I will create a sub process to do some work. In my process, I need to get the feedback from sub process. I want to pass the Window handle of my application/process to this sub process, so I can post message from this sub process.

How can I pass Window Handle to sub process? My sub process is a command line application without Windows UI and with the main function like this:

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       LPTSTR lpCmdLine, int nCmdShow)

I post this question in stackoverflow and get the answer:

Window handles (HWNDs) are global to the system so you can just print the handle as a decimal number into a string buffer, pass it as a string on the command line when you spawn your sub-process with CreateProcess, and call _wtoi() or similar to convert the string back to a handle again.

If you want to create the subprocess by CreateProcess API, then just pass the handle string to the sub process.

(0) Comments    Read More