Announcement

Collapse
No announcement yet.

Why does COM Initialization Fail?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why does COM Initialization Fail?

    Hi

    I wrote a Powerbasic program to use a COM object written in Visual FoxPro. The COM object is an "exe" and it works with other environments but fails in PowerBasic. I assume I have configured something wrong in PowerBasic. Can anyone see what I have done wrong. I have tried this two ways; one using PowerBasic's Let command and secondly with the WinAPI and both fail.

    Thanks,
    Simon

    Code:
    ' Version Dependent ProgIDs
    $PROGID_dcvfpsrvc_dcvfpsrvcdCVFPSrvc = "dcvfpsrvc.dCVFPSrvc"
    
    ' Version Independent ProgIDs
    $PROGID_dcvfpsrvc_dcvfpsrvc = "dcvfpsrvc.dCVFPSrvc"
    
    ' Class Identifiers
    $CLSID_dcvfpsrvc_dcvfpsrvc = GUID$("{E3238B33-AC18-42FD-BFDF-97AD0973754B}")
    
    ' Interface Identifiers
    $IID_dcvfpsrvc_Idcvfpsrvc = GUID$("{9E0C18A3-B124-49E3-A286-A5A2709A08BE}")
    
    ' Interface Name  : Idcvfpsrvc
    ' Description     : dcvfpsrvc.dCVFPSrvc
    ' Class Name      : dcvfpsrvc
    ' ClassID         : $CLSID_dcvfpsrvc_dcvfpsrvc
    ' ProgID          : $PROGID_dcvfpsrvc_dcvfpsrvc
    ' Version ProgID  : $PROGID_dcvfpsrvc_dcvfpsrvcdCVFPSrvc
    INTERFACE Idcvfpsrvc $IID_dcvfpsrvc_Idcvfpsrvc
        INHERIT IDISPATCH
    
        METHOD destroyworkers <0> () AS VARIANT
        METHOD execute <1> () AS VARIANT
        METHOD GetWorker <2> () AS VARIANT
        METHOD ProcessQueue <3> () AS VARIANT
        METHOD startworkers <4> () AS VARIANT
        METHOD stopworkers <5> () AS VARIANT
        METHOD writetolog <6> () AS VARIANT
    END INTERFACE    
    Local loVFP AS Idcvfpsrvc  
      IF CoInitializeEx(BYVAL %NULL, %COINIT_APARTMENTTHREADED) = %S_OK THEN
    
          IF CoCreateInstance($CLSID_dcvfpsrvc_dcvfpsrvc, BYVAL %NULL, %CLSCTX_LOCAL_SERVER,$IID_dcvfpsrvc_Idcvfpsrvc,loVFP) = %S_OK  THEN
    
    
    '   LET loVFP = NEWCOM CLSID CLSID$("dcvfpsrvc.dCVFPSrvc") 'LIB "C:\Business\dCipherComputing\Applications\dCVFPSrvc\VFP9\dcvfpsrvc.exe"
    ...

  • #2
    Because you're using it wrongly.

    Instead of

    Code:
    Local loVFP AS Idcvfpsrvc  
      IF CoInitializeEx(BYVAL %NULL, %COINIT_APARTMENTTHREADED) = %S_OK THEN
    
          IF CoCreateInstance($CLSID_dcvfpsrvc_dcvfpsrvc, BYVAL %NULL, %CLSCTX_LOCAL_SERVER,$IID_dcvfpsrvc_Idcvfpsrvc,loVFP) = %S_OK  THEN
    
    
    '   LET loVFP = NEWCOM CLSID CLSID$("dcvfpsrvc.dCVFPSrvc") 'LIB "C:\Business\dCipherComputing\Applications\dCVFPSrvc\VFP9\dcvfpsrvc.exe"
    ...
    use

    Code:
    Local loVFP AS Idcvfpsrvc  
    loVFP = NEWCOM $PROGID_dcvfpsrvc_dcvfpsrvcdCVFPSrvc
    ...
    Website: http://www.jose.it-berater.org/index.html
    SED Editor, TypeLib Browser.
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      HI

      I tried your code and it still does not work. In fact sometimes PowerBasic just stops working when I try it in debug mode.

      Simon

      Comment


      • #4
        Is that Visual FoxPro COM object something I can download and try?
        Dominic Mitchell
        Phoenix Visual Designer
        http://www.phnxthunder.com

        Comment


        • #5
          Thank-you for your offer but I now have the COM object working correctly. My next problem is how to correctly build a Windows NT Service in PowerBasic that will use the VFP COM Object.

          I built a similar service in PureBasic but I am having difficulty getting the service to run in PowerBasic.

          PowerBasic installs the service and deletes the service but it will not start the service. When I try to start the service I get the first error ERROR_FAILED_SERVICE_CONTROLLER_CONNECT

          Simon

          Code:
          SUB Service_Start(tcService AS STRINGZ)
             LOCAL lnErr AS LONG
             DIM ServiceTable(0 TO 1) AS LOCAL SERVICE_TABLE_ENTRY
          
             WriteToLog("Service_Start() > Start")
             ServiceTable(0).lpServiceName = VARPTR(tcService)
             ServiceTable(0).lpServiceProc = CODEPTR(Service_MainLoop)
             ServiceTable(1).lpServiceName = %NULL
             ServiceTable(1).lpServiceProc = %NULL
          
             IF StartServiceCtrlDispatcher(BYVAL VARPTR(ServiceTable(0))) = 0 THEN
                lnErr=GetLastError()
                SELECT CASE lnErr
                   CASE %ERROR_FAILED_SERVICE_CONTROLLER_CONNECT
                      WriteToLog("Last Error FAILED_SERVICE_CONTROLLER_CONNECT")
                   CASE %ERROR_INVALID_DATA
                      WriteToLog("Last Error INVALID_DATA")
                   CASE %ERROR_SERVICE_ALREADY_RUNNING
                      WriteToLog("Last Error SERVICE ALREADY_RUNNING")
                   CASE ELSE
                      WriteToLog("Last Error "+FORMAT$(lnErr,"##########"))
                END SELECT
             END IF
             WriteToLog("Service_Start() > End")
          END SUB

          Comment

          Working...
          X