Skip to content

RegFreeCOM raise error 0x80040154: Class not registered #17

@ToniKoehler

Description

@ToniKoehler

Expected behavior

If I try to run ParallelFox as out of Process Worker in SetRegFreeCOM = true, the worker should start with Parameter "/automation -Embeding" and the CreateObjectEx() can instantiate the COM server without registration.

Local Parallel as Parallel

Parallel = NewObject("Parallel", "ParallelFox.vcx")

Parallel.SetRegFreeCOM(.t.)
Parallel.StartWorkers(FullPath("RegFreeCom.prg"))

MessageBox("Workers are now running.")

Parallel.StopWorkers()
Parallel.SetRegFreeCOM(.f.)

Error occurs

0x80040154: Class not registered
Image

Description

VFP becomes from the old RUN /n command the control faster back, than the parallelfox.exe is ready as COM server. So the CreateObjectEx() will fail.

Reproduce the problem easy

#DEFINE PARALLELFOX_CLSID "{76DE0CE0-CE45-491B-9EDF-6F91CDBD9880}"

* Ensure that no running instanz of parallelfox.exe is running
* CMD.exe: taskkill /im parallelfox.exe /f

LOCAL loParallel
lcParallelFoxApp = "C:\Dev\parallelfox.exe"

lcRun = [Run /n "] + lcParallelFoxApp + [" /automation -Embedding]
&lcRun
* VFP becomes the control faster back, than the parallelfox.exe is ready as COM server
* So the CreateObjectEx() will fail.

loParallel = CREATEOBJECTEX(PARALLELFOX_CLSID, GETENV("COMPUTERNAME"))

Solve the issue

#DEFINE PARALLELFOX_CLSID "{76DE0CE0-CE45-491B-9EDF-6F91CDBD9880}"

* Ensure that no running instanz of parallelfox.exe is running
* CMD.exe: taskkill /im parallelfox.exe /f

LOCAL loParallel
lcParallelFoxApp = "C:\Dev\parallelfox.exe"

lcRun = [Run /n "] + lcParallelFoxApp + [" /automation -Embedding]
&lcRun
* VFP becomes the control faster back as the parallelfox.exe COM server is ready
* So the CreateObjectEx() will fail.
 

* Solution: Spend the COM server up to 3 seconds to stay ready for instantiation

LOCAL llExit, ltStarttime, lnWaitSeconds, loException

lnWaitSeconds = 3	&& Wait maximum 3 seconds
ltStarttime	  = DATETIME()
llExit		  = .F.

DO WHILE !llExit
	TRY
		loParallel = CREATEOBJECTEX(PARALLELFOX_CLSID, GETENV("COMPUTERNAME"))
	CATCH TO loException
	ENDTRY
	IF VARTYPE(loParallel) = "O" OR DATETIME() > ltStarttime + lnWaitSeconds
		llExit = .T.
	ENDIF
ENDDO

You need to implement the solution into:

CLASS workerproxy of X:\ENTWICKLUNGSVERZEICHNIS\xclasses\parallelfox.vcx METHOD INIT

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions