CreateObject alike for WIA

Posted on 2006-07-11
Last Modified: 2008-10-01

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

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

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).

Question by:kGenius
LVL 44

Expert Comment

ID: 17088141
Hi kGenius,

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

share what you know, learn what you don't
LVL 44

Accepted Solution

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#

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);
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?


Author Comment

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...

Expert Comment

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
where is said that also could used a path to afile....
WIA.CommonDialog myprintDialog = new WIA.CommonDialogClass();

String tmp = theBasisPfad + currentDateiname;


myprintDialog.ShowPhotoPrintingWizard( tmp );

Open in new window


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

14 Experts available now in Live!

Get 1:1 Help Now