Solved

CreateObject alike for WIA

Posted on 2006-07-11
5
971 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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 describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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