当前位置:编程学习 > C#/ASP.NET >>

C#调用DLL的问题

//这里是对DLL导出方法的声明
        [DllImport(@"D:\Internet Explorer\BankFormOcr.dll", EntryPoint = "start")]
        static extern void start(string ocr_path);

        [DllImport(@"D:\Internet Explorer\BankFormOcr.dll", EntryPoint = "ocr")]
        static extern string[] ocr(string img_path);

        [DllImport(@"D:\Internet Explorer\BankFormOcr.dll", EntryPoint = "end")]
        static extern void end();

//这里是调用的过程

       private void Recognition(DataSet ds)
        {
            start(@"D:\Internet Explorer\multimodfEx\multimodf.mod");

            string img_path = "";

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                img_path = localFolder + "\\" + row["fileName"].ToString();
                string[] values = ocr(img_path);
            }
            end();
        }
错误信息如下:
无法在 DLL“D:\Internet Explorer\BankFormOcr.dll”中找到名为“start”的入口点。

以下是通过dll查看器查看到的方法名,请问问题是啥子咧?


C# dll 调用 --------------------编程问答-------------------- EntryPoint = "start"这里面写成
EntryPoint = "_Java_ocr__Ocr_start@12"
这不是标准的导出的dll,这是C++中的 --------------------编程问答-------------------- 谢谢wmingcsharp。追加一个问题啊,回传的值,string[] values = ocr(img_path);这句话报错,我知道在java里它是写成了 String[]的返回值。那在C#我应该怎么写呢?

无法封送处理“return value”: 无效的托管/非托管类型组合。

引用 1 楼 wmingcsharp 的回复:
EntryPoint = "start"这里面写成
EntryPoint = "_Java_ocr__Ocr_start@12"
这不是标准的导出的dll,这是C++中的
--------------------编程问答-------------------- C#可以用一个指针接收,然后拷贝到缓冲区后再处理。 --------------------编程问答-------------------- java调用是这么写的:

package ocr;

 public class Ocr {
  public Ocr() {
  }
  static
  {
  System.loadLibrary("BankFormOcr");
  }
  public native void start (String ocr_path);
  public native String [] ocr(String img_path);

  public native void end();
}

请各位大侠给点意见啊,呵呵呵
--------------------编程问答-------------------- 无法封送处理“return value”: 无效的托管/非托管类型组合(Int/UInt 必须与 SysInt 或 SysUInt 成对出现)。

        //声明的代码        
        [DllImport(@"D:\Internet Explorer\BankFormOcr.dll", EntryPoint = "_Java_ocr_Ocr_ocr@12")]
        [return: MarshalAs(UnmanagedType.LPArray)]
        static extern IntPtr ocr(string img_path);

        //调用的代码
        private void Recognition(DataSet ds)
        {
            start(@"D:\Internet Explorer\multimodfEx\multimodf.mod");
            string img_path = "";
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                img_path = localFolder + "\\" + row["fileName"].ToString();
                IntPtr result = ocr(img_path);  //错在这一行
                MessageBox.Show(result.ToString());
            }
            end();
        }

特别想追问一下,该如何debug该问题咧?
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,