We have developed an application to control and scan any file like images, etc as a C# Winform App and it works under x86 OS platform successfully. In the app, we use C# twain class which to send a command to scanner so we can achieve what we want. As you all know, Twain_32.dll file is used to run the app and scan without failure.
My question is, in x64 OS platforms, we can not run the app and get an error called BadImageFormatException that tries to tell us it's all about OS type! So this error points me that i try to run the app under uncompatible OS type.
I have experienced that 32 bit twain dll work under x64 systems but another problem cross my way. We run our all applications under one parent form which is MDI Parent form. So The form that I wanna use as scan purposes will be an MDI Client form. So well, while my program is compiled as ANYCPU, CLR will run it as x64 bit app in Windows x64 OS. That's why, I can not run the app even if I compiled my scanning form as x86 platform target in x64 Win OS.
Till here, I hope you all got what i mean!!!
As a solution, I tried to install Twack64 setup file to get TWAINDSM.dll file and to run my app both in x86 and x64 OS machines. Also, in my custom twain source project, I changed to dll import attribute TWAINDSM.dll instead of Twain_32.dll but it didn't work out.
So am i missing something here or Twain C# app does not recognize TWAINDSM.dll as twain dll? I got stuck at this step and can not go forward any further!!! pulling my hair for 3-4 days!!! :(
A quick hand will be great help to me guys! Looking forward to hearing from you!!!
Best How To :
We have found out another way instead of looking for TwainDSM dll for x64 which we couldn't actually within my company.
I had posted a subject to twainforum about it, after some time an answer has been returned to me - the link is below:
TwainForum Link That I posted about the issue!
well, it was not good enough to find my way out at that time. Before getting an answer, we got an agreement that we can solve this using System.Diagnostics.Process class to work in x64 platforms depending our needs. The code I have used is in below:
var proc = new System.Diagnostics.Process();
String path = "";
var pathArray = System.Windows.Forms.Application.StartupPath.Split('\\');
for (int i = 0; i < pathArray.Count() - 1; i++)
path += pathArray[i] + "\\";
path = path + "fileName.EXE";
proc.StartInfo.FileName = path;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
string result = proc.StandardOutput.ReadToEnd();
MessageBox.Show("No Response from Scanner Screen!", "ERROR!");
But how to pass parameters from that exe to use it in my project? There's a way to do that! Just put one line code in Program.cs file of FileName.Exe like below: (I have also put a vertical line to seperate parameters)
Console.Write(FilePathAndName + "|" + PicFormArsivOK.ToString() + "|" + TarayiciFormArsivOK.ToString());
and finally i read values from result value like this:
if (result.Split('|').First() != "" && (Convert.ToBoolean(result.Split('|')) == true | Convert.ToBoolean(result.Split('|')) == true))
I hope you got the idea here and the answer is useful for your needs!