Solved

CreateObject alike for WIA

Posted on 2006-07-11
5
954 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 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