Announcement

Collapse
No announcement yet.

NEWCOM will not work inside ServiceMain Function - Works in WinMAIN

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

  • NEWCOM will not work inside ServiceMain Function - Works in WinMAIN

    When I try to use the following code in ServiceMain (writing a Windows service) isobject returns false and the COM object is not initalized. If you call from within WINMAIN and use regdb as a global variable it will work.

    Why can COM objects not be referenced in servicemain?

    static regdb AS IRegDb
    DIM L AS STRING
    DIM N AS STRING
    DIM f AS STRING
    f=UCODE$("c:\temp\regdemo.regdb")
    regdb = NEWCOM $PROGID_RegDbLib_RegDb
    kill "c:\error.txt"
    IF ISFALSE(ISOBJECT(regdb)) THEN
    ' Could not create an object refrence, exit the application
    open "c:\error.txt" for output as 1
    print#1,"error"
    close 1

    END IF
    MICHAEL S. THOMASON

  • #2
    Resolved

    For those that stuggle with this:

    I found that I needed to use the CoInitialize() function or CoInitializeEX function inside of ServiceMain.
    MICHAEL S. THOMASON

    Comment

    Working...
    X