Registering a Palm Com Conduit: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library)
 
m (Updated author and download links, and changed format of some pages.)
Line 188: Line 188:
</highlight-nsis>
</highlight-nsis>


Page author: lpayne
Page author: [[User:lpayne|lpayne]]

Revision as of 12:41, 23 April 2005

Description

Here's a quick and simple script to register conduits with the Palm HotSync Manager.

The Script

!define PRODUCT_NAME "Register Conduit Sample"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "lpayne@palmdogs.com"
!define PRODUCT_WEB_SITE "http://www.palmdogs.com"
!include "MUI.nsh"
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
 
;Palm core path
Var ExecPath
 
OutFile "RegisterConduit.exe"
InstallDir "$PROGRAMFILES\ConduitRegisterTest"
ShowInstDetails show
 
Section "MainSection"
  ; Copy the conduit. In this case it's an ActiveX.exe
  ; If it was a .dll it would be registered using the UpgradeDLL macro i.e.
  ; !insertmacro UpgradeDLL "c:\MyDir\MyConduit.dll" $INSTDIR\MyConduit.dll $INSTDIR
  SetOutPath "$INSTDIR"
  File "c:\qbConduit\ConduitDemo\MyConduit.exe"
  EXECWAIT "$INSTDIR\MyConduit.exe /regserver"
 
  ; This should return with $ExecPath set to the
  ; location of the Palm core files.
  Call GetPalmExecPath
 
  ; Now we can register the conduit
  StrCmp $ExecPath "" SkipIt
    Call RegisterCOMConduit
    Call RestartHotSyncManager
  SkipIt:
 
  SetAutoClose false
SectionEnd
 
;--------------------------------------------------------------------
;
; Function: GetPalmExecPath
;
; Description: Get the exec path for the palm components
;
; Notes: Sets global  ExecPath
;
;--------------------------------------------------------------------
Function GetPalmExecPath
  SetOutpath $TEMP\ttLP
  File "c:\Program Files\Palm\CondMgr.dll"
  StrCpy $1 ${NSIS_MAX_STRLEN}
  System::Call 'CondMgr::CmGetHotSyncExecPath(t, *i) i(.r0, r1r1).r2'
  StrCmp $2 "0" GetParentString NoPath
  GetParentString:
  Push $0
  Call GetParent    ; Strip 'HotSync.exe' off of the string
  Pop $R0
  StrCpy $ExecPath $R0
  Goto ExecDone
 
  NoPath:
  MessageBox MB_OK " Unable to get Palm Components Path."
  StrCpy $ExecPath ""
 
  ExecDone:
FunctionEnd
 
;--------------------------------------------------------------------
;
; Function: RegisterCOMConduit
;
; Description: Registers a COM conduit with HotSync Manager.
;              Writes a registry entry for the conduit in:
;              HKEY_Current_User\Software\U.S. Robotics\PilotDesktop\
;
; Uses: CondMgr.dll
;
; Note: Other conduit types register essentially the same way. See
;       the Palm documentation for more information.
;
;--------------------------------------------------------------------
Function RegisterCOMConduit
 
  ; Set the path
  StrCmp $ExecPath "" RegisterDone
  SetOutPath $ExecPath
 
  strcpy $0 "ttLP"    ; Creator ID
 
  ; Delete the old conduit if any
  System::Call 'CondMgr::CmRemoveConduitByCreatorID(t) i(r0).r2'
  ; Don't really care about the return value
 
  ; First set the creator ID of the conduit
  ; 0 = Conduit_Component, 1 = Conduit_Application, 2 = future use
  System::Call 'CondMgr::CmInstallCreator(t, i) i(r0, 0).r2'
  StrCmp $2 "0" SetName RegisterErr
 
  ; Conduit Name
  SetName:
  System::Call 'CondMgr::CmSetCreatorName(t, t) i(r0, "ComConduit.dll").r2'
  StrCmp $2 "0" SetPriority RegisterErr
 
  ; Conduit Priority
  SetPriority:
  System::Call 'CondMgr::CmSetCreatorPriority(t, i) i(r0, 2).r2'
  StrCmp $2 "0" SetTitle RegisterErr
 
  ; Conduit Title
  SetTitle:
  System::Call 'CondMgr::CmSetCreatorTitle(t, t) i(r0, "MyConduit Title").r2'
  StrCmp $2 "0" SetValue RegisterErr
 
  ; It's a COM conduit so specify the entry point. In this case it's .CNotifyDll
  SetValue:
  System::Call 'CondMgr::CmSetCreatorValueString(t, t, t) i(r0, "COMClient", "MyConduit.CNotifyDll").r2'
  StrCmp $2 "0" RegisterDone RegisterErr
 
  RegisterErr:
  MessageBox MB_OK "Error installing conduit."
 
  RegisterDone:
FunctionEnd
 
;--------------------------------------------------------------------
;
; Function: RestartHotSyncManager
;
; Description: Restarts HotSync Manager.
;
; Uses: hsAPI.dll
;
;--------------------------------------------------------------------
Function RestartHotSyncManager
 
  StrCmp $ExecPath "" RestartDone
  SetOutPath $ExecPath
 
  ; If I don't call refresh before the restart, restart sometimes fails.
  ; Always seems to work this way. A refresh really should be enough
  ; for the Conduit to be picked up but...
  DetailPrint "Refreshing HotSync Manager..."
  System::Call 'hsapi::HsRefreshConduitInfo(v) i .r2'
 
  DetailPrint "Restarting HotSync Manager..."
  System::Call 'hsapi::HsSetAppStatus(i, i) i(2, 0).r2'
  StrCmp $2 "0" RestartDone RestartErr
 
  RestartErr:
  Messagebox MB_OK "Unable to restart HotSync Manager."
 
  RestartDone:
FunctionEnd
 
;--------------------------------------------------------------------
; Function: GetParent
;--------------------------------------------------------------------
Function GetParent
   Exch $R0
   Push $R1
   Push $R2
   Push $R3
   StrCpy $R1 0
   StrLen $R2 $R0
   loop:
     IntOp $R1 $R1 + 1
     IntCmp $R1 $R2 get 0 get
     StrCpy $R3 $R0 1 -$R1
     StrCmp $R3 "\" get
     Goto loop
   get:
     StrCpy $R0 $R0 -$R1
     Pop $R3
     Pop $R2
     Pop $R1
     Exch $R0
 FunctionEnd
 
;--------------------------------------------------------------------
; End RegisterConduit.nsi

Page author: lpayne