ActiveX Viewer in Windows service application not working

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Post Reply
docu-track99
User
Posts: 518
Joined: Thu Dec 06, 2007 8:13 pm

ActiveX Viewer in Windows service application not working

Post by docu-track99 »

Hi Tracker,

We would like to use ActiveX Viewer in Windows service application. Our service will try to fix malformed pdf using the activeX viewer. Service calls a class that includes a form with a tracker control.


Our code to Initialize the class

Private Sub TrackerPDFInitialize()
Try

If oTrackerPDF Is Nothing Then
oTrackerPDF = New PDFClasses.cTrackerPDF
End If

Catch ex As Exception
mGenericError(ex)
End Try
End Sub



We got an error:

System.Threading.ThreadStateException = {"ActiveX control 'fe36f0f3-f082-41b7-9eed-772505a7c054' cannot be instantiated because the current thread is not in a single-threaded apartment."}
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2353
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: ActiveX Viewer in Windows service application not workin

Post by Vasyl-Tracker Dev Team »

Hi docu-track99.

It occurs because your current thread isn't STA. To fix it you may change attribute of main thread by:

[STAThread]
static void Main()
{
...
}

or you may create new additional thread that creates and shows the form with our ActiveX but with specified STA-apartment:

Thread newThread = new Thread(new ThreadStart(MyThreadFunc));
newThread.SetApartmentState(ApartmentState.STA);

Our ActiveX requires STA apartment...

HTH
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
docu-track99
User
Posts: 518
Joined: Thu Dec 06, 2007 8:13 pm

Re: ActiveX Viewer in Windows service application not workin

Post by docu-track99 »

I created a new additional thread and specified STA-apartment. This fixed my previous issue. I'm getting a new error loading a document to tracker control.

code:
tPDF.OpenDocument(sInputPath, sOpenPassword, nActiveDocID, 2)

Error:
COM object that has been separated from its underlying RCW cannot be used.
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2353
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: ActiveX Viewer in Windows service application not workin

Post by Vasyl-Tracker Dev Team »

Hi, docu-track99.

It is difficult to say what is the reason of this problem, having only one code-line.. ;)
Is this error thrown at the moment of executing this code-line OR a bit later?

Please look there:
http://stackoverflow.com/questions/2260 ... ot-be-used

HTH
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Post Reply