Cloud | Andreano Lanusse | Technology and Software Development Where Andreano Lanusse talk about technology, software development, programming techniques, databases, games and more through articles, tutorials and videos Fri, 28 Dec 2012 08:34:23 +0000 en hourly 1 https://wordpress.org/?v=6.3.4 Shell Extension for Windows 32-bit and 64-bit with Delphi XE2 or XE3 http://www.andreanolanusse.com/en/shell-extension-for-windows-32-bit-and-64-bit-with-delphi-xe2/ http://www.andreanolanusse.com/en/shell-extension-for-windows-32-bit-and-64-bit-with-delphi-xe2/#comments Wed, 14 Nov 2012 23:37:55 +0000 http://www.andreanolanusse.com/en/?p=702 Compile Delphi code for 64-bit platform is possible now with Delphi XE2 and XE3, developers can go beyond Windows 32-bit and start creating Windows Shell Extension for Windows 64-bit. Shell Extensions are in-process COM objects which extends the abilities of Windows OS. In this post I’m going to add two new context menu items in […]

Andreano Lanusse | Technology and Software Development Follow me on Twitter: @andreanolanusse

]]>
Compile Delphi code for 64-bit platform is possible now with Delphi XE2 and XE3, developers can go beyond Windows 32-bit and start creating Windows Shell Extension for Windows 64-bit. Shell Extensions are in-process COM objects which extends the abilities of Windows OS. In this post I’m going to add two new context menu items in Windows Explorer. The menus will allow users to upload files to Microsoft Azure and Amazon S3. This post will go through how to create the extension, register and compile for 32-bit and 64-bit. I’m preparing another post, in which I will explain how to upload files to Amazon S3 and Microsoft Azure.

Creating the CloudUpload Shell Extension

In order to start creating a Shell Extension in Delphi, you first need to create an ActiveX Library project and after that create a new Automation Object. In the example I use for this post, the project name is CloudUpload and the Automation Object is called TCloudUploadContext. The TCloudUploadContext class must implement the interfaces IShellExtInit and IContextMenu in order to integrate the Context Menu in Windows Explorer.

    { IShellExtInit Methods }
    { Initialize the context menu if a files was selected}
    function IShellExtInit.Initialize = ShellExtInitialize;
    function ShellExtInitialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
      hKeyProgID: HKEY): HResult; stdcall;

    { IContextMenu Methods }
    { Initializes the context menu and it decides which items appear in it,
      based on the flags you pass }
    function QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst, idCmdLast,
      uFlags: UINT): HResult; stdcall;

    { Execute the command, which will be the upload to Amazon or Azure}
    function InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult; stdcall;
    { Set help string on the Explorer status bar when the menu item is selected }
    function GetCommandString(idCmd: UINT_PTR; uFlags: UINT; pwReserved: PUINT;
      pszName: LPSTR; cchMax: UINT): HResult; stdcall;

The ShellExtInitialize defines if the Context Menu will appear or not in Windows Explorer. In this sample the context menu only shows up if one file has been selected, otherwise no Context Menu. In case only one file was selected the FFileName variable will receive the name of the file.

function TCloudUploadContextMenu.ShellExtInitialize(pidlFolder: PItemIDList;
  lpdobj: IDataObject; hKeyProgID: HKEY): HResult;
var
  DataFormat: TFormatEtc;
  StrgMedium: TStgMedium;
  Buffer: array [0 .. MAX_PATH] of Char;
begin
  Result := E_FAIL;

  { Check if an object was defined }
  if lpdobj = nil then
    Exit;

  { Prepare to get information about the object }
  DataFormat.cfFormat := CF_HDROP;
  DataFormat.ptd := nil;
  DataFormat.dwAspect := DVASPECT_CONTENT;
  DataFormat.lindex := -1;
  DataFormat.tymed := TYMED_HGLOBAL;

  if lpdobj.GetData(DataFormat, StrgMedium) <> S_OK then
    Exit;

  { The implementation now support only one file }
  if DragQueryFile(StrgMedium.hGlobal, $FFFFFFFF, nil, 0) = 1 then
  begin
    SetLength(FFileName, MAX_PATH);
    DragQueryFile(StrgMedium.hGlobal, 0, @Buffer, SizeOf(Buffer));
    FFileName := Buffer;
    Result := NOERROR;
  end
  else
  begin
    // Don't show the Menu if more then one file was selected
    FFileName := EmptyStr;
    Result := E_FAIL;
  end;

  { http://msdn.microsoft.com/en-us/library/ms693491(v=vs.85).aspx }
  ReleaseStgMedium(StrgMedium);

end;

After the context menu handler is initialized via the IShellExtInit interface, Windows uses the IContextMenu interface to call the other methods of our context menu handler. In this case it will call QueryContextMenu, GetCommandString and InvokeCommand.

The Context Menu options (Amazon S3, Microsoft Azure) will be created through the QueryContextMenu method.

function TCloudUploadContextMenu.QueryContextMenu(Menu: HMENU;
  indexMenu, idCmdFirst, idCmdLast, uFlags: UINT): HResult;
var
  CloudMenuItem: TMenuItemInfo;
  MenuCaption: String;
  SubMenu: HMENU;
  uId: UINT;
begin
  { only adding one menu CloudMenuItem, so generate the result code accordingly }
  Result := MakeResult(SEVERITY_SUCCESS, 0, 3);

  { store the menu CloudMenuItem index }
  FMenuItemIndex := indexMenu;

  { specify what the menu says, depending on where it was spawned }
  if (uFlags = CMF_NORMAL) then // from the desktop
    MenuCaption := 'Send file from Desktop to the Cloud'
  else if (uFlags and CMF_VERBSONLY) = CMF_VERBSONLY then // from a shortcut
    MenuCaption := 'Send file from Shourtcut to the Cloud'
  else if (uFlags and CMF_EXPLORE) = CMF_EXPLORE then // from explorer
    MenuCaption := 'Send file from Explorer to the Cloud'
  else
    { fail for any other value }
    Result := E_FAIL;

  if Result <> E_FAIL then
  begin

    SubMenu := CreatePopupMenu;

    uId := idCmdFirst;
    InsertMenu(SubMenu, AmazonIndex, MF_BYPOSITION, uId, TClouds[AmazonIndex]);

    Inc(uId);
    InsertMenu(SubMenu, AzureIndex, MF_BYPOSITION, uId, TClouds[AzureIndex]);

    FillChar(CloudMenuItem, SizeOf(TMenuItemInfo), #0);
    CloudMenuItem.cbSize := SizeOf(TMenuItemInfo);
    CloudMenuItem.fMask := MIIM_SUBMENU or MIIM_STRING or MIIM_ID;
    CloudMenuItem.fType := MFT_STRING;
    CloudMenuItem.wID := FMenuItemIndex;
    CloudMenuItem.hSubMenu := SubMenu;
    CloudMenuItem.dwTypeData := PWideChar(MenuCaption);
    CloudMenuItem.cch := Length(MenuCaption);

    InsertMenuItem(Menu, indexMenu, True, CloudMenuItem);
  end;
end;

When you are in the Windows Explorer and you pass the mouse over one of the Cloud menu items a short help message is displayed in the Windows Explorer status bar, it is defined on the implementation of the method GetCommandString, which returns a string to the Windows Explorer to display.

function TCloudUploadContextMenu.GetCommandString(idCmd: UINT_PTR; uFlags: UINT;

  pwReserved: PUINT; pszName: LPSTR; cchMax: UINT): HResult;
begin
  Result := E_INVALIDARG;

  { Set help string on the Explorer status bar when the menu item is selected }
  if (idCmd in [AmazonIndex, AzureIndex]) and (uFlags = GCS_HELPTEXT) then
  begin
    StrLCopy(PWideChar(pszName), PWideChar('Copy the selected file to ' +
      TClouds[idCmd]), cchMax);
    Result := NOERROR;
  end;

end;

As the user clicks in one of the Cloud menu items, the method InvokeCommand will be called and start the process to upload the selected file to the Cloud selected. At this point we already have the file name and based on the lpici parameters we can identify what menu item the user clicked.

function TCloudUploadContextMenu.InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult;
var
  Item: Word;
begin
  Result := E_FAIL;

  if HiWord(Integer(lpici.lpVerb)) <> 0 then
    Exit;

  { if the index matches the index for the menu, show the cloud options }
  Item := LoWord(Integer(lpici.lpVerb));

  if Item in [AmazonIndex, AzureIndex] then
  begin
    try
      Upload(lpici.HWND, Item, FFileName);
    except
      on E: Exception do
        MessageBox(lpici.hwnd, PWideChar(E.Message), 'Cloud Upload', MB_ICONERROR);

    end;
    Result := NOERROR;
  end;

end;

In order for the COM object to be created whenever the CloudUpload is loaded, it’s necessary to create an instance of a class factory that specifically creates an instance of the shell extension object, the factory instance will be created on the initialization section, based on the following code, which is a replacement for the default code created by Delphi.

initialization
  TCloudUploadObjectFactory.Create(ComServer, TCloudUploadContextMenu, CLASS_CloudUploadContextMenu, ciMultiInstance, tmApartment);
end.

Since the class factory will be responsible to register/unregister the DLL, the methods ApproveShellExtension and UpdateRegistry will be invoked, it will happen when you use the regsvr32.exe.

  { the new class factory }
  TCloudUploadObjectFactory = class(TAutoObjectFactory)
  protected
    procedure ApproveShellExtension(&Register: Boolean; const ClsID: string);
    function GetProgID: string; override;
  public
    procedure UpdateRegistry(Register: Boolean); override;
  end;

{ TCloudUploadObjectFactory }

{ Required to registration for Windows NT/2000 }
procedure TCloudUploadObjectFactory.ApproveShellExtension(&Register: Boolean;
  const ClsID: string);
Const
  WinNTRegKey =
    'SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved';
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;

  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;

    if not Reg.OpenKey(WinNTRegKey, True) then
      Exit;

    { register the extension appropriately }
    if &Register then
      Reg.WriteString(ClsID, Description)
    else
      Reg.DeleteValue(ClsID);
  finally
    Reg.Free;
  end;

end;

function TCloudUploadObjectFactory.GetProgID: string;
begin
  { ProgID not required for shell extensions }
  Result := '';
end;

procedure TCloudUploadObjectFactory.UpdateRegistry(Register: Boolean);
Const
  ContextKey = '*\shellex\ContextMenuHandlers\%s';
begin
  { perform normal registration }
  inherited UpdateRegistry(Register);

  { Registration required for Windows NT/2000 }
  ApproveShellExtension(Register, GUIDToString(ClassID));

  { if this server is being registered, register the required key/values
    to expose it to Explorer }
  if Register then
    CreateRegKey(Format(ContextKey, [ClassName]), '', GUIDToString(ClassID),
      HKEY_CLASSES_ROOT)
  else
    DeleteRegKey(Format(ContextKey, [ClassName]));

end;

Compile for 32-bit or 64-bit platform

At this point we just need to compile the extension, for this sample the Win APIs and RTL methods are the same for both platforms, we don’t need any specific code. You can define the target platform through the Project Manager, by default your project target 32-bit Windows, right click on Target Platforms to add 64-bit Windows.

Delphi Project Manager - Platform

You can’t register 32-bit dll in 64-bit operation system, and you can not register 64-bit dll in 32-bit operation system. If you are using your develop machine to test, compile for the platform compatible with your OS.

 

Registering the CloudUpload Shell Extension

First, you must Run as Administrator the application you are going to use to register the shell extensions even if you are the Administrator user.

32-bit shell extensions can be registered through the IDE, and command line (cmd) can be used to register 32-bit and 64-bit.

Here the cmd line to register and unregister:

– Run as Administrator the cmd;

– Register the extension using the following command line: regsvr32 <PATH WHERE IS LOCATED THE DLL>CloudUpload.dll

– To unregister the extension using the following command line: regsvr32 <PATH WHERE IS LOCATED THE DLL>CloudUpload.dll /u

After register the DLL you can open the Windows Explorer, select one file and right click, you will see the new menu “Send file from Explorer to the Cloud”. The following screenshot show the shell extension on my Windows 7 64-bit.

Shell Extension - Windows Explorer

You can download he source code in 2 different ways:

Andreano Lanusse | Technology and Software Development Follow me on Twitter: @andreanolanusse

]]>
http://www.andreanolanusse.com/en/shell-extension-for-windows-32-bit-and-64-bit-with-delphi-xe2/feed/ 6
Amazon Web Services (AWS) is the first choice for PHP Developers http://www.andreanolanusse.com/en/amazon-web-service-aws-is-the-first-choice-for-php-developers/ http://www.andreanolanusse.com/en/amazon-web-service-aws-is-the-first-choice-for-php-developers/#respond Thu, 12 Jan 2012 08:58:13 +0000 http://www.andreanolanusse.com/en/?p=775 Today I was reading the article “Developers will flock to public cloud in 2012”, which pretty much goes over some of the results of Zend survey with 3,335 developers, and of course if not all of them the majority PHP developers. This survey brings some interesting information, the first one related with the use of […]

Andreano Lanusse | Technology and Software Development Follow me on Twitter: @andreanolanusse

]]>
Today I was reading the article “Developers will flock to public cloud in 2012”, which pretty much goes over some of the results of Zend survey with 3,335 developers, and of course if not all of them the majority PHP developers.

This survey brings some interesting information, the first one related with the use of public cloud where 61 percent said they expect to use a public cloud for their projects.

And, of those going that route, 30 percent named Amazon Web Services as their public cloud of choice; 28 percent did not yet know which cloud they would use; 10 percent named Rackspace; and 6 percent cited Microsoft Azure.  ”Other” public clouds came in at 5 percent and IBM Smart Cloud at 3 percent.

In terms of overall type of projects, 66 percent of respondents said they will be doing mobile development in 2012, this is a great opportunity for them to try RadPHP XE2 which bring integration with PhoneGap, components for jQuery Mobile and everything they need to optimize their web apps to mobile.

Also 45 percent said they will work on social media integration this year, if they are targeting Facebook another opportunity to try RadPHP XE2 and see how they can rapidly integrate web application with Facebook.

Andreano Lanusse | Technology and Software Development Follow me on Twitter: @andreanolanusse

]]>
http://www.andreanolanusse.com/en/amazon-web-service-aws-is-the-first-choice-for-php-developers/feed/ 0
Microsoft Windows Azure during 30 days FREE http://www.andreanolanusse.com/en/microsoft-windows-azure-during-30-days-free/ http://www.andreanolanusse.com/en/microsoft-windows-azure-during-30-days-free/#comments Tue, 11 Jan 2011 07:43:57 +0000 http://www.andreanolanusse.com/en/?p=444 Microsoft is offering Windows Azure platform 30 day free pass for anyone who want to try their Cloud environment. If you are Delphi or C++Builder developer and want to see how Windows Azure platform works, this is the chance. Delphi XE and C++Builder XE shipped a set of components to work with Windows Azure accounts. Windows Azure (not […]

Andreano Lanusse | Technology and Software Development Follow me on Twitter: @andreanolanusse

]]>
Microsoft is offering Windows Azure platform 30 day free pass for anyone who want to try their Cloud environment. If you are Delphi or C++Builder developer and want to see how Windows Azure platform works, this is the chance. Delphi XE and C++Builder XE shipped a set of components to work with Windows Azure accounts. Windows Azure (not to be confused with SQL Azure) allows you to store and manage Blobs, Queues of messages, and Tables of data on the Azure cloud.

You just need to access this link, select the country and use the promo code MPR001 (valid for United States 🙂 ), and of course you have to use Delphi XE or C++Builder XE, download the trial is free and valid for 30 days as well.

The available Azure VCL components are:

  • TAzureTableManagement – Window Azure Tables; these provide scalable structured storage. Think NOSQL type tables where each entry stored in a table can have a different set of properties made up of different types, such as string or int.
  • TAzureQueueManagement – unlike blobs and tables, which are used to store data, queues serve another purpose, a persistent asynchronous messaging, where each message is up to 8kb long
  • TAzureBlobManagement – Windows Azure Blob Storage; Blob storage is unstructured storage as it is used for storing large pieces of data such as images, video, documents, etc inside a defined container.

There is also a component called TAzureConnectionString, which takes into consideration information for connecting to your Windows Azure account. All these components use the Windows Azure REST API to manage the features that come with each of these services.

Azure components are useful for any developer who wants to make an application that manages a Windows Azure account. If used programmatically, the application itself could use information from the end-user’s Azure account.

Andreano Lanusse | Technology and Software Development Follow me on Twitter: @andreanolanusse

]]>
http://www.andreanolanusse.com/en/microsoft-windows-azure-during-30-days-free/feed/ 1
Test our DataSnap XE Live Server on Amazon Cloud http://www.andreanolanusse.com/en/test-our-datasnap-xe-live-server-on-amazon-cloud/ http://www.andreanolanusse.com/en/test-our-datasnap-xe-live-server-on-amazon-cloud/#comments Wed, 01 Sep 2010 00:01:37 +0000 http://www.andreanolanusse.com/en/?p=341 Here is the deal, we deployed an InterBase and simple DataSnap server application on Amazon EC2 and make available the DataSnap client in Delphi. If you would like to see how much faster DataSnap XE is, download the client application built in Delphi and navigate through the application. The Amazon instance will be running for […]

Andreano Lanusse | Technology and Software Development Follow me on Twitter: @andreanolanusse

]]>
Here is the deal, we deployed an InterBase and simple DataSnap server application on Amazon EC2 and make available the DataSnap client in Delphi.

If you would like to see how much faster DataSnap XE is, download the client application built in Delphi and navigate through the application. The Amazon instance will be running for about 24 hours for now.

Here are some guidelines to help you to understand what’s happen when you execute some of the server methods:

Tab Server Methods

  • Button Get Server DateTime – return the datetime from our Amazon server
  • Jobs available – list of the records based on ClientDataSet, you can edit, delete and insert data

 

Using ClientDataSet (Master-Detail)

  • ClientDataSet using Master-Detail (read only)

 

Reading Data from DBXReader

  • This tab has 3 buttons, the first one returns a list of department, the second tells the object to order the next request by ID and the last one order by NAME. Since this object is a singleton, if you click to receive the list ordered by ID and the results are ordered by NAME, it is because someone around the world request the order by NAME. This is simple example showing how the memory management works on DataSnap.

 

Using DBX framework to send TParams

  • Just add a record on the table Department passing to the server a TParams object

 

Object Transfer

  • Receive object from the server

 

Download the DataSnap client application here, unzip, click and run. 

This is just a small sample to show you some of the DataSnap capabilities, Anders 🙂 was responsible for the QA process.

Andreano Lanusse | Technology and Software Development Follow me on Twitter: @andreanolanusse

]]>
http://www.andreanolanusse.com/en/test-our-datasnap-xe-live-server-on-amazon-cloud/feed/ 12
DataSnap XE and Windows Azure – RAD Studio XE Preview #3 http://www.andreanolanusse.com/en/datasnap-xe-and-windows-azure-rad-studio-xe-preview-3/ http://www.andreanolanusse.com/en/datasnap-xe-and-windows-azure-rad-studio-xe-preview-3/#respond Tue, 24 Aug 2010 22:39:30 +0000 http://www.andreanolanusse.com/en/?p=336 One of the great news around RAD Studio XE is the Cloud support, in this video we show how to access Microsoft Azure through the DataSnap Server XE, as well some of the new features in DataSnap like authentication and authorization to execute the server methods. Now take some time and visit the  RAD Studio XE […]

Andreano Lanusse | Technology and Software Development Follow me on Twitter: @andreanolanusse

]]>
One of the great news around RAD Studio XE is the Cloud support, in this video we show how to access Microsoft Azure through the DataSnap Server XE, as well some of the new features in DataSnap like authentication and authorization to execute the server methods.

Now take some time and visit the  RAD Studio XE Preview to learn more about the new Delphi XE, C++Builder XE, Delphi Prism XE and RadPHP XE.

Andreano Lanusse | Technology and Software Development Follow me on Twitter: @andreanolanusse

]]>
http://www.andreanolanusse.com/en/datasnap-xe-and-windows-azure-rad-studio-xe-preview-3/feed/ 0