简体   繁体   English

Twain驱动程序-Windows OS x64中的TWAINDSM.DLL错误

[英]Twain Driver - TWAINDSM.DLL Error in Windows OS x64

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. 我们开发了一个应用程序来控制和扫描任何文件,例如图像等,如C#Winform App,它可以在x86 OS平台上成功运行。 In the app, we use C# twain class which to send a command to scanner so we can achieve what we want. 在应用程序中,我们使用C#twain类向扫描器发送命令,从而实现所需的功能。 As you all know, Twain_32.dll file is used to run the app and scan without failure. 众所周知, Twain_32.dll文件用于运行应用程序并进行扫描而不会失败。

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! 我的问题是,在x64 OS平台上,我们无法运行该应用程序,并得到一个名为BadImageFormatException的错误,该错误试图告诉我们有关操作系统类型的所有信息! So this error points me that i try to run the app under uncompatible OS type. 所以这个错误指出我尝试在不兼容的OS类型下运行该应用程序。

I have experienced that 32 bit twain dll work under x64 systems but another problem cross my way. 我已经体验到32位twain dll在x64系统下工作,但是另一个问题困扰着我。 We run our all applications under one parent form which is MDI Parent form. 我们在一个父表单(即MDI父表单)下运行所有​​应用程序。 So The form that I wanna use as scan purposes will be an MDI Client form. 因此,我要用作扫描目的的表单将是MDI客户表单。 So well, while my program is compiled as ANYCPU , CLR will run it as x64 bit app in Windows x64 OS. 很好,尽管我的程序被编译为ANYCPU ,但CLR将在Windows x64 OS中将其作为x64位应用程序运行。 That's why, I can not run the app even if I compiled my scanning form as x86 platform target in x64 Win OS. 这就是为什么即使我将扫描表单编译为x64 Win OS中的x86平台目标也无法运行该应用程序的原因。

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. 作为解决方案,我尝试安装Twack64安装文件以获取TWAINDSM.dll文件并在x86和x64 OS计算机上运行我的应用程序。 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. 另外,在我的自定义twain源项目中,我将dll导入属性TWAINDSM.dll替换为Twain_32.dll,但没有成功。

So am i missing something here or Twain C# app does not recognize TWAINDSM.dll as twain dll? 那么,我是否在这里丢失了某些内容,或者Twain C#应用程序无法将TWAINDSM.dll识别为twain dll? I got stuck at this step and can not go forward any further!!! 我被困在这一步,无法继续前进!!! pulling my hair for 3-4 days!!! 拉我的头发3-4天!!! :( :(

A quick hand will be great help to me guys! 快速的手将对我大有帮助! Looking forward to hearing from you!!! 期待您的回音!!!

We have found out another way instead of looking for TwainDSM dll for x64 which we couldn't actually within my company. 我们找到了另一种方法,而不是为x64寻找TwainDSM dll,而这实际上是我公司内部无法做到的。

I had posted a subject to twainforum about it, after some time an answer has been returned to me - the link is below: 经过一段时间的回复后,我在twainforum上发布了一个主题,其链接如下:

TwainForum Link That I posted about the issue! 我发布的有关该问题的TwainForum链接!

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. 在得到答案之前,我们已经达成协议,可以使用System.Diagnostics.Process类来解决此问题,以便根据需要在x64平台上工作。 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? 但是如何从该exe传递参数以在我的项目中使用它? 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) 只需在FileName.Exe的Program.cs文件中放入一行代码,如下所示:(我也将竖线用于单独的参数)

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! 希望您在这里有了主意,答案对您的需求很有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM