Why this fails in C#

  • Thread starter Thread starter Niloday
  • Start date Start date
N

Niloday

Hi All,

I have COM dll developed in VB.6 that exposes a method to print a word
document. The method accepts the name of the printer and the fully
qualified name of the document to be printed. In the DLL, it loops through
the printers collection to check if the printer name is valid and sets the
requested printer as default printer. Secondly it uses late binding for
Word Application and prints the document on the default printer.

This DLL works properly when used from a VB application. Now I wanted to
use the same DLL from my C# class library (this is used by the windows
service application) to have the documents printed.

When I attempt to use this from C#, firstly it fails to loop through the
Printers collection. (Printers collection is not nothing) and Second issue
is that, it opens the document when called as
wordObject.documents.Open fileName
but fails to print when called as
wordObject.PrintOut
with an error as "File path access error"

Could anyone please provide me some pointers on what this could be the
issue.

Thanks in advance

Niloday
 
The problem is not C#, the problem is your COM object which was not designed
to run in a windows service.
Services run in the security context of a restricted user, which has no way
to access an interactive user is profile (if there is any). Printer info is
part of interactive user profiles, so if you really need to enumerate and
access printers from windows service applications, you have to load the
appropriate user profile (registry hive), the FCL doesn't account for this
so you'll need to call LoadUserProfile using PInvoke.

Willy.
 
Hi Willy,

First of all a lots of thanks to you. I should have realized this earlier.

I am putting in some workarounds and hope it works.

-Niloday
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top