Problems accing COM component from 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
 
Hi,

I think the problem is that you are using the printing functionality and the
Word automation from a Windows service. Try to create a simple "testbed"
desktop app which would use the same VB COM dll and see what happens.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

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
 
Also, Willy Denoyette has given a very solid explanation in the "Why this
fails in C#" thread.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

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
 
Hi,

Thanks for your reply. Yes the problem was because of a different security
context for services.

I was desperately hunting for the answer so posted the same query with
another subject and it worked (new subject is : Why this fails in C#.) Willy
Denoyette replied to my query and it did give me a start.

Thanks,

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