Solved

CreateObject alike for WIA

Posted on 2006-07-11
5
949 Views
Last Modified: 2008-10-01
Hi,

This is a code-snippet from a VB.NET print module

Dim dialog As Object = CreateObject("WIA.CommonDialog")
dialog.ShowPhotoPrintingWizard(vector)

I've tried this in C# as follows:
Type t = Type.GetTypeFromProgID("WIA.CommonDialog");
object dialog=Activator.CreateInstance(t);

But then I cannot access dialog.ShowPhotoPrintingWizard();

I've referenced the waauit.dll now and add using WIA at top.
But still I want to get the other way(without referencing WIA).

kGenius
0
Comment
Question by:kGenius
5 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 17088141
Hi kGenius,
----------

you could try
object dialog = CreateObject("WIA.CommonDialog");
dialog.ShowPhotoPrintingWizard(vector);

----------
bruintje
share what you know, learn what you don't
0
 
LVL 44

Accepted Solution

by:
bruintje earned 500 total points
ID: 17088172
disregard my first comment, what you are trying to do is not completely possible in C# because it is not in line with the strong typing used in C#

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20855783.html

adapted from the comment of _TAD_

using System.Runtime.InteropServices;

Type myObjType;
object myObjValue;

myObjType = Type.GetTypeFromProgID("WIA.CommonDialog");
myObjValue = Activator.CreateInstance(myObjType);

myObjType.InvokeMember("ShowPhotoPrintingWizard", BindingFlags.InvokeMethod,null,myObjValue,vector);
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17090437
Is it possible to add a reference, and use early-binding, instead of the late-bound Activator call?

Bob
0
 
LVL 7

Author Comment

by:kGenius
ID: 17106334
It is possible in my app. I've done it that way (add the reference)
But I was so curious how C# could handle this one.

Thanks bruintje for sharing...
kGenius
0
 

Expert Comment

by:olecb
ID: 22612544
tmp is like this..: "c:/users/me/pictures/abc.jpg"...

What the compiler says is "argument can not be converted from string to "ref object"
If've refered to http://msdn.microsoft.com/en-us/library/ms630492(VS.85).aspx
where is said that also could used a path to afile....
WIA.CommonDialog myprintDialog = new WIA.CommonDialogClass();

String tmp = theBasisPfad + currentDateiname;

theDruckListe.SetFromString(tmp,false,true);

myprintDialog.ShowPhotoPrintingWizard( tmp );

Open in new window

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now