PowerBASIC Peer Support Forums
 

Go Back   PowerBASIC Peer Support Forums > User to user Discussions > Programming with Objects

Programming with Objects User to user discussions about programming with objects, including COM objects.

Reply
 
Thread Tools Display Modes
  #1  
Old Mar 1st, 2012, 11:20 AM
Simon White Simon White is offline
Member
 
Join Date: Mar 2009
Posts: 71
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"
...
Reply With Quote
  #2  
Old Mar 1st, 2012, 11:58 AM
Josť Roca Josť Roca is online now
Moderator
 
Join Date: Mar 2004
Location: Valencia, Spain
Posts: 6,627
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
Reply With Quote
  #3  
Old Mar 1st, 2012, 01:44 PM
Simon White Simon White is offline
Member
 
Join Date: Mar 2009
Posts: 71
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
Reply With Quote
  #4  
Old Mar 1st, 2012, 11:48 PM
Dominic Mitchell Dominic Mitchell is offline
Member
 
Join Date: Nov 1999
Posts: 1,776
Is that Visual FoxPro COM object something I can download and try?
__________________
Dominic Mitchell
Phoenix Visual Designer
http://www.phnxthunder.com
Reply With Quote
  #5  
Old Mar 2nd, 2012, 03:59 PM
Simon White Simon White is offline
Member
 
Join Date: Mar 2009
Posts: 71
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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:30 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright © 1999-2011 PowerBASIC, Inc. All Rights Reserved.
Error in my_thread_global_end(): 1 threads didn't exit