Register ActiveX via PureBasic (REGSVR32)

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Register ActiveX via PureBasic (REGSVR32)

Post by BackupUser »

Code updated For 5.20+

Restored from previous forum. Originally posted by Rings.

Code: Select all

;
;RegSVR32 Sample register any activeX.DLL in System

;Converted from VB to PureBasic
; by Siegfried Rings (SIGGI)
;
; coded for further use with SelfX (Installer) from xTract-Technologies
; (Selfmerchendising hehe )

Procedure RegSVR32(File$,Flag)
  
  hLib = LoadLibrary_(File$) ;Load the DLL into memory
  If hLib =0
    ProcedureReturn 0
  EndIf
  
  If Flag=1
    RegProcName.s = "DllRegisterServer"
  Else
    RegProcName.s = "DllUnregisterServer"
  EndIf
  
  ; Find And store the DLL entry point, i.e. obtain the address
  ; of the “DllRegisterServer” or "DllUnregisterServer" function
  ; (to register or deregister the server’s components in the registry)
  
  lpDLLEntryPoint = GetProcAddress_(hLib, RegProcName) ;Find Procedure in DLL
  
  If lpDLLEntryPoint = 0
    FreeLibrary_(hLib)
    ProcedureReturn -1 ;This is not a ActiveX
  EndIf
  
  ;Create a thread To execute within the virtual address space of the calling process
  hThread = CreateThread_(0, 0,lpDLLEntryPoint, 0, 0, lpThreadID)
  
  If hThread = 0
    FreeLibrary_(hLib)
    ProcedureReturn -2 ;failed threading
  EndIf
  
  ;Use WaitForSingleObject To check the Return state (i) when the specified object is in
  ;the signaled state Or (ii) when the time-out interval elapses. This function can be
  ; used To test Process And Thread.
  mResult = WaitForSingleObject_(hThread, 10000)
  If mResult <> 0
    FreeLibrary_(hLib)
    lpExitCode = GetExitCodeThread_(hThread, lpExitCode)
    ExitThread_(lpExitCode)
    ProcedureReturn -3 ;failed threading
  EndIf
  
  ;We don't call the dangerous Terminate Thread(); after the last handle to an object
  ;is closed, the object is removed from the system.
  
  CloseHandle_(hThread)
  FreeLibrary_(hLib)
  ProcedureReturn 1 ;failed threading
EndProcedure

MessageRequester("INFO","REGSVR32:"+Str(RegSVR32("c:\test.dll",0)),0)
Siggi