Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why does my code fail when using COM?
Message
De
01/03/2012 23:50:21
 
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
01536990
Message ID:
01537017
Vues:
51
>Hi
>
>Can anyone explain why "Do dcvfpsrvc.prg" works when I use CreateObject("dcvfpsrvc") but locks up VFP when I try CreateObject("dcvfpsrvc.dcvfpsrvc")?
>
>I created both dcvfpsrvc.exe and dcworker.exe marked both as OLEPublic.
>
>
>
>Public go
>
>Set Step on
>
>*go=CreateObject("dcvfpsrvc.dcvfpsrvc")
>go=CreateObject("dcvfpsrvc")
>For ln=1 to go.nWorkerCount
>   go.aWorkers(ln).Test
>EndFor
>go.StopWorkers
>go.DestroyWorkers
>
>Return
>
>Define Class dCVFPSrvc As Session OLEPublic
>
>
>   Protected nProcessQueue,cStartin,cAppBase,dNow,nServerOffset,height,width
>   Dimension aWorkers[1]
>   aWorkers(1) = NULL
>
>   Height = 63
>   Width = 100
>   *-- Process Task Queue Flag
>   nProcessQueue = 0
>   *-- The number of work COM Objects Created.
>   nworkercount = Iif(Version(2)=0,2,4)
>   *-- The folder from which the application was started.
>   cstartin = ""
>   *-- The base Directory for Customer Applications
>   cappbase = ""
>   *-- The time the service was run.
>   dNow = Datetime()
>   *-- The server's time zone offset.
>   nServerOffset = ""
>   
>   Name = "dCVFPSrvc"
>   
>   *-- Creates the Worker COM Objects
>   Protected PROCEDURE createworkers
>      Local ln
>      Dimension This.aWorkers(This.nWorkerCount)
>      For ln=1 to This.nWorkerCount
>         This.aWorkers(ln)=CreateObject("dcworker.dcWorker")
>         This.aWorkers(ln).oMain = This
>      EndFor
>   ENDPROC
>...
>EndDefine
>
My understanding is if you have built an EXE COM server named "dcvfpsrvc" with the above code, the call CREATEOBJECT("dcvfpsrvc.dcvfpsrvc") should work. But, I never name the EXE and its included classes the same, maybe that isn't allowed in COM. You could test by naming your EXE or class to something else.

No sure answer, just a few SWAGs:

- Are you working with Windows 7 (or Vista, is probably the same)? When you build an EXE COM server, the final step of the build is where VFP registers the server in your computer's registry. If you are not running your VFP dev environment as an administrator (even if your account is nominally an admin), this step will fail. If your newly built server isn't registered properly it won't work properly

- Related to the above, you may think you can get around that by running a CMD window as administrator, then running dcvfpsrvc.exe /regserver at the prompt. I tried that a couple of times - it appears to work, but the servers I was testing with didn't work properly. Bottom line, to minimize headaches when building EXE COM servers, I run VFP9.EXE as an administrator (right click, run as admin).

- Is it possible you have another dcvfpsrvc.exe earlier in your PATH, or somehow being accessed, that does not contain the dcvfpsrvc class?

- Just an observation, your test code doesn't include a call to go.CreateWorkers( ), so the .Test's will fail
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform