3

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

Muzzy B.
  • 182
  • 4
  • 17
  • What problem do you get if you compile your whole application for x86 instead of AnyCPU? This should produce a perfectly running 32bit application in 64bit systems and, of course, you could use 32bit libraries – Steve May 10 '15 at 21:49
  • It makes sense for a minor-sized application but what you say is really difficult to make progress for a major-sized application because I am talking about around 100 or more project sources... I have to make them all compile for x86 as platform target... The problem is I gotta talk about it with my manager but instead i am trying to find out cheaper and easier way... is there not any sample for x64 apps to use another twain driver like by using TWAINDSM.dll?? – Muzzy B. May 11 '15 at 08:22

1 Answers1

0

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;

        proc.Start();
        string result = proc.StandardOutput.ReadToEnd();
        proc.WaitForExit();
        if (string.IsNullOrEmpty(result))
        {
            MessageBox.Show("No Response from Scanner Screen!", "ERROR!");
            return;
        }

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('|')[1]) == true | Convert.ToBoolean(result.Split('|')[2]) == true))
        {
          //TODO:  
        }

I hope you got the idea here and the answer is useful for your needs!

Muzzy B.
  • 182
  • 4
  • 17