venerdì 29 agosto 2008

NSIS and MFC dependency

Hi all, I've post here a way wich NSIS can support an automatic distribution for the MFC ( in my case v8). You can use the Clickonce part with other installer e.g. Inno Setup.

Introduction
The NSIS not support an automatic distribution for the MFC program . This post solve this problem.

Backgroung
First of all I use Visual Studio 2005 to deploy my MCF application and I use NSIS installer to redistribute it. The SO target are Windows Xp and Vista.

I solve the problem in a very easy way.
I build a ClickOnce setup on my solution, and i use it in silent mode inside the NSIS.

Info: I use the ClickOnce to install all the redistributable file instead vcredist_x86.exe becouse with the vcredist_x86.exe you need other istructions, like register some files.
With my solution after install it the program is ready to use.

The step needed are 2
1 Create the ClickOnce setup and modify it a bit.
2 Add it to NSIS

1 ClickOnce
Create the ClickOnce setup on your solution. Simply I add a new project to my solution I use the Setup Wizard Project inside Other Project Types. I follow the steps needed and I only add the primary output to the output group at step 3 (Figure 1).
Figure 1

I've left all the other page as default. At the end the result solution is like this (Figure 2).
Figure 2

Now I don't need to distribute the the primary output, and I exclude it (Figure 3), Unfortunatly this not avoid the creation of installation dir.
Figure 3

I don't install anything else, and I don' need the default location for the app. I haven't find a way to delete this key but a way to change it to an existing one, i choose the root, so to do that i change in the File sistem editor the property of the application folder to c:\ (Figure 4) you can change it with %TEMP% or %APPDATA% or what you want.
Figure 4

The last step is to delete all the page inside the wizard. Go to the UI editor (Figure 5)
Figure 5

and delete all the page (Figure 6) .
Figure 6

2 NSIS
Silent mode:
Now you have the installation ready but the progress bar before the start of the installation still appears. To hide that dialog I use the msiexec comman. For the Installation command :'msiexec /quiet /i MicrosoftMFC8Runtime.msi'.For the unistall command 'msiexec /quiet /x MicrosoftMFC8Runtime.msi'
Adding the command line to NSIS
:
The process is very simple. I need to copy the file MicrosoftMFC8Runtime.msi and execute it waiting the installer til the installer finish, after i Delete it.
Section MFCRUNTIME
SetOutPath "$INSTDIR"
File "MicrosoftMFC8Runtime.msi" "Step 1 Install Microsoft MFC8 Runtime"
ExecWait "msiexec /quiet /i MicrosoftMFC8Runtime.msi"
"Step 2 Install Microsoft MFC 8 Runtime"
delete
"MicrosoftMFC8Runtime.msi" #Step 3 Install Microsoft MFC 8 Runtime"
SectionEnd
For the uninstall section you only need to uninstall the MicrosoftMFC8Runtime like you can do in the Add/Remove program. You can do this with the right GUID of MicrosoftMFC8Runtime.
The Guid is the
'ProductCode' In your ClickOnceSetup, is a property value.

In my case I need only this line for unistall it
Section unMFCRUNTIME
ExecWait "msiexec /quiet /i{843A5D8A-2FD3-4E51-AFBA-A1551D8F41B9}"
SectionEnd

Well now compile your NSIS file and try it.

Conclusion
I've try it under few Windows Vista and a lot of Windows Xp without problem.
Have fun.
Let me know if you have any problems regarding this short tutorial.
Kind regards.

giovedì 7 agosto 2008

Convert string to Hex

A chunk of code how to convert string (unicode or not) to long Hexadecimal (base-16)

CString sUnicode = _T("A123F");

CStringA sASCII(sUnicode);
char * pNotConverted=NULL;
long lHex = strtol (sASCII.operator LPCSTR(),&pNotConverted,16);
if(strlen(pNotConverted)>0)
return false;

  • For unicode directly without conversion use wcstol the wide-character version
  • For better range (__int64) use _strtoi64 or _wcstoi64
Remarks

Remember the long limits

Type Name

Bytes

Range of Values

long4–2,147,483,648 to 2,147,483,647
__int648–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807










sabato 2 agosto 2008

Creating Vista Gadgets



This is my first book review on amazon, take a look here[^].

New blog style

Before it begins, my presonally arrange (a little bit) to this blog.
Hope you like it.