Windows Mobile package process

Source: Internet
Author: User

My blog was just launched, and my thoughts were messy. I couldn't remember what to write at the moment! I will write out my recent experiences on packaging ppc applications and share them with you! In fact, I think many experts know how to build a complete package program, but for various reasons, no one has written a complete article, so the younger brother has achieved basic functions after a few days of study. So that we can avoid detours ,! The basic functions I mentioned are as follows:
1) on the ppc today's screen, you have a program shortcut (today's plug-in );
2) ability to establish Chinese shortcuts;
Haha, that's all! I can't tell you more! In fact, there is no technical content. Don't laugh! OK. Let's get started. You can follow the steps below to build a project and write code step by step. You can also download the Demo Source Code directly (the previous one is recommended )!

Step 1: Create an application. Open VS2005 to create a SmartDevice application project, which is currently called CabSample. Then, continue until the program is established, and finally compile and generate the execution program. OK. Step 1 is complete. (Figure omitted)

Step 2: Create a plug-in for today. I don't want to talk about how to write the plug-in today. There are also a lot of code on the Internet. Here I will give you a link to elaborate on today's plug-ins. Http://www.codeguru.com/cpp/w-p/ce/pocketpc/article.php/c9269__1/

The procedure is as follows: 1) create a project in the project you just created. This project is a dll project based on SmartDevice. We set the project name as MyToday. As shown in:

Next, go down until the project setting option, select dll in the project type, and click Finish.
Now let's complete today's plug-in code:
First, we add an icon (ID_ICON1) to the current plug-in project to indicate your application.
Then, we add the. def file to the source folder of the project, and the name can be used, for example, MyToday. def.
Write down the following content in the file you just added:
EXPORTS
InitializeCustomItem @ 240
Then, we can complete the plug-in to execute the code. I posted the main Code. For details, see the demo. Note that you must add the header file <todaycen. h> before writing code.
Finally, compile and generate MyToday. dll.

MyToday source code:
Lresult callback WndProc (HWND hWnd, UINT uimessage, WPARAM wParam, LPARAM lParam)
{
Switch (uimessage)
{
Case WM_TODAYCUSTOM_QUERYREFRESHCACHE:
{
TODAYLISTITEM * ptli = (TODAYLISTITEM *) wParam;

If (NULL = ptli)
Break;

If (0 = ptli-> cyp)
{
Ptli-> cyp = PLUG_HEIGHT;
Return TRUE;
}
}
Break;

Case WM_CREATE:
Break;

Case WM_LBUTTONUP:
{
// 1 determine whether the application is in the valid region, 2 query the registry, obtain the program path, and 3 start the program
RECT rect;
POINT point;
Point. x = LOWORD (lParam );
Point. y = HIWORD (lParam );
: GetClientRect (hWnd, & rect );
If (PtInRect (& rect, point ))
{
HKEY hOpenKey;
Long lResult = 0;
DWORD iValueType = 0;
DWORD iLen = 0;
PROCESS_INFORMATION procInfo;

TCHAR szPath [MAX_PATH] = {'\ 0 '};

LPCTSTR keyName = _ T ("Software \ CabSample"); // This registry stores the execution path of your application
LPCTSTR csAppPath = _ T ("AppPath ");

LResult =: RegOpenKeyEx (HKEY_CURRENT_USER, keyName, 0, 0, & hOpenKey );

ASSERT (lResult = ERROR_SUCCESS );
If (lResult! = ERROR_SUCCESS)
{
MessageBox (hWnd, _ T ("failed to read Registry"), _ T ("prompt"), MB_ OK );
// MessageBox (hWnd, _ T ("Open Regedit Faild"), _ T ("prompt"), MB_ OK );
Break;
}
ILen = MAX_PATH * sizeof (TCHAR );
LResult =: RegQueryValueEx (hOpenKey, csAppPath, 0, & iValueType, (BYTE *) szPath, & iLen );
If (lResult! = ERROR_SUCCESS)
{
MessageBox (hWnd, _ T ("failed to read Registry"), _ T ("prompt"), MB_ OK );
// MessageBox (hWnd, _ T ("Read Regedit Faild"), _ T ("prompt"), MB_ OK );
Break;
}
: RegCloseKey (hOpenKey );

BOOL bSuc =: CreateProcess (szPath, NULL, FALSE, 0, NULL, & procInfo );
If (bSuc)
{
: CloseHandle (procInfo. hThread );
: CloseHandle (procInfo. hProcess );
}
Else

{
MessageBox (hWnd, _ T ("failed to start the program"), _ T ("prompt"), MB_ OK );
// MessageBox (hWnd, _ T ("start App Failed"), _ T ("prompt"), MB_ OK );
// MessageBox (hWnd, szPath, _ T ("prompt"), MB_ OK );
}
}
}
Break;

Case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
Hdc = BeginPaint (hWnd, & ps );
PaintAll (hWnd, hdc );
EndPaint (hWnd, & ps );
}
Break;

Case WM_ERASEBKGND:
Return TRUE;

Case WM_TODAYCUSTOM_RECEIVEDSELECTION:
G_bSelected = TRUE;
Return TRUE;

Case WM_TODAYCUSTOM_USERNAVIGATION:
Break;

Case WM_TODAYCUSTOM_ACTION:
Break;


}
Return DefWindowProc (hWnd, uimessage, wParam, lParam );
}

Step 3: Create and install the dll. Now, let's proceed to step 3.
First, like step 2, we add a dll project named setupdll to the project. Add a. def file to the project and add the following content:
EXPORTS
Install_Init
Install_Exit
Uninstall_Init
Uninstall_Exit
Then, we complete the Execution Code of setupdll. I posted the main Code. For details, see the demo. Note: before writing code, you must add the "ce_setup.h" and <shellapi. h> header files, including "ce_setup.h" in the demo.
Finally, compile and generate Setupdll. dll.

Setupdll source code:
CodeINSTALL_EXIT Install_Exit (HWND hwndparent,
LPCTSTR pszinstalldir,
WORD cfaileddirs,
WORD cfailedfiles,
WORD cfailedregkeys,
WORD cfailedregvals,
WORD cfailedshortcuts)
{
HKEY hOpenKey = NULL;
Long lResult = 0;
DWORD dwOpenStyle = 0;
DWORD iValueType = 0;
DWORD iLen = 0;
DWORD iTemp = 0;
TCHAR szPath [MAX_PATH] = {'\ 0 '};
TCHAR szLinkPath [MAX_PATH] = {0 };
TCHAR szAppPath [MAX_PATH] = {0 };
 
LPCTSTR keyName = _ T ("Software \ CabSample ");
LPCTSTR csAppPath = _ T ("AppPath ");
LPCTSTR csTodaykey = _ T ("Software \ Microsoft \ Today \ Items \" Packaging example \"");
LPCTSTR csPlugName = _ T ("MyToday. dll"); // your plug-in name
LPCTSTR csAppName = _ T ("CabSample.exe"); // your program name

If (cfaileddirs | cfailedfiles | cfailedregkeys
| Cfailedregvals | cfailedshortcuts)
Goto Failed;

// Obtain the installation path of the main program
_ Tcscpy (szPath, pszinstalldir );
_ Tcscat (szPath, _ T ("\\"));
_ Tcscat (szPath, csAppName );

// Set the execution path of the main program shortcut
_ Tcscpy (szAppPath, _ T ("\""));
_ Tcscat (szAppPath, szPath );
_ Tcscat (szAppPath, _ T ("\""));

// Write the installation path of the main program to the Registry
 
LResult =: RegCreateKeyEx (HKEY_CURRENT_USER, keyName, 0, _ T (""), REG_OPTION_NON_VOLATILE,
0, NULL, & hOpenKey, & dwOpenStyle );
If (lResult! = ERROR_SUCCESS)
Goto Success;
: RegSetValueEx (hOpenKey, csAppPath, 0, REG_SZ, (BYTE *) & szPath, sizeof (TCHAR) * _ tcslen (szPath ));
: RegCloseKey (hOpenKey );

Memset (szPath, 0x00, sizeof (TCHAR) * MAX_PATH );
_ Tcscpy (szPath, pszinstalldir );
_ Tcscat (szPath, _ T ("\\"));
_ Tcscat (szPath, csPlugName );
: CopyFile (szPath, _ T ("\ Windows \ MyToday. dll"), FALSE );

// Install "Today's plug-in"
HOpenKey = NULL;
LResult =: RegCreateKeyEx (HKEY_LOCAL_MACHINE, csTodaykey, 0, _ T (""), REG_OPTION_NON_VOLATILE,
0, NULL, & hOpenKey, & dwOpenStyle );

If (lResult! = ERROR_SUCCESS)
Goto Success; // if the registry fails to be read/written, discard the "Today's plug-in" installation"

 

// Register the plug-in
ITemp = 0;
: RegSetValueEx (hOpenKey, _ T ("Flags"), 0, REG_DWORD, (BYTE *) & iTemp, sizeof (iTemp ));
: RegSetValueEx (hOpenKey, _ T ("Options"), 0, REG_DWORD, (BYTE *) & iTemp, sizeof (iTemp ));
ITemp = 1;
: RegSetValueEx (hOpenKey, _ T ("Enabled"), 0, REG_DWORD, (BYTE *) & iTemp, sizeof (iTemp ));
: RegSetValueEx (hOpenKey, _ T ("Order"), 0, REG_DWORD, (BYTE *) & iTemp, sizeof (iTemp ));
: RegSetValueEx (hOpenKey, _ T ("Selectability"), 0, REG_DWORD, (BYTE *) & iTemp, sizeof (iTemp ));
ITemp = 4;
: RegSetValueEx (hOpenKey, _ T ("Type"), 0, REG_DWORD, (BYTE *) & iTemp, sizeof (iTemp ));
: RegSetValueEx (hOpenKey, _ T ("DLL"), 0, REG_SZ, (BYTE *) _ T ("\ Windows \ MyToday. dll "), sizeof (TCHAR) * _ tcslen (szPath ));
// Send system messages
: SendMessage (HWND_BROADCAST, WM_WININICHANGE, (WPARAM) 0xF2, 0 );
: RegCloseKey (hOpenKey );
 
// Create a shortcut
If (SHGetSpecialFolderPath (NULL, szLinkPath, CSIDL_PROGRAMS, FALSE ))
{
_ Tcscat (szLinkPath, _ T ("\\"));
_ Tcscat (szLinkPath, _ T ("Packaging example. lnk "));

If (SHCreateShortcut (szLinkPath, szAppPath) = FALSE)
{
MessageBox (NULL, _ T ("installation shortcut failed"), _ T ("prompt"), MB_ OK );
}

}
Else
MessageBox (NULL, _ T ("failed to get the system file path"), _ T ("prompt"), MB_ OK );

// Return value
Success:
Return codeINSTALL_EXIT_DONE;

Failed:
Return codeINSTALL_EXIT_UNINSTALL;
}

Step 4: create a complete package. Add a new project named CabSampleCab to the project. For details, refer:

Click OK. Next we will go to the cab packaging stage. (I only write steps. For more details, refer to Microsoft msdn)
First, click "properties" in the "View" menu or open the "properties" window.
In the "ProductName" Field of the property grid, change the value to "CabSample ".

Then, in the "local file system" browser, select "application folder", right-click and select "what is new", and click "main project output, in the project drop-down box of the displayed dialog box, select "CabSample", repeat the preceding steps, and add the preceding three project master outputs in sequence. For example:

Then, in the solution browser, select the cab project and view the property bar. Click the "CE Setup Dll" attribute in the property bar, select Browse in the pop-up drop-down box, and click in the pop-up dialog box to enter the "Application

Folder, select the main output of the dll installation, and click OK:

Then, add a registry key to the cab project to save the application execution path. The registry string is initially empty. Enter the correct path in setupdll.

Finally, we should not create shortcuts for the program, because we have already created a shortcut in setupdll. Why not let the cab be created automatically?
1. the shortcut created automatically cannot be created for some reason;
2. A shortcut created automatically. It is not deleted when the program is uninstalled;
3. We have created a shortcut before, so you don't have to bother pulling the cab !! :-)

Step 5: Compile the entire installation scheme, generate a cab package, and install the package on ppc. The running interface is as follows:

OK !! If you don't understand it, go back to study in demo !! What ?? My packaging process is incomplete ?? You also need to be able to automatically install it on the pc through ActiveSync. I'm dizzy and I'm exhausted tonight. Let's go to msdn on your own. I wrote my post for the first time. If you are not mature, please ask your friends, Hai Han !!
Because the demo is too large to upload, I want to save the Email for the demo! Or go to the http://www.winbile.net/BBS/1015441/ShowPost.aspx to download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.