//C 接口
extern "C"
{
    TESSDLL_API  int __cdecl  GetTessText(const char *imagefile, char *text);  
}//我在C#中声明
//调用C DLL 中的函数
[DllImport("OCRapi.dll", EntryPoint = "GetTessText", CharSet = CharSet.Ansi,
           CallingConvention = CallingConvention.Cdecl)]
 public static extern int GetTessText(char[] imagefile, char[] text);
调用代码:
char[] imagefile = "D:\\My Documents\\\baidu\\1.bmp".ToCharArray();
char[] textResult = new char[256];
int i = OCRAPI.GetTessText(imagefile,  textResult);出现的问题:textResult 得不到返回值

解决方案 »

  1.   

    [DllImport("OCRapi.dll", EntryPoint = "GetTessText", CharSet = CharSet.Ansi, 
              CallingConvention = CallingConvention.Cdecl)] 
    public static extern int GetTessText(string imagefile, StringBuilder text); 
      

  2.   

    类型不对 const char * --> byte[]    char * -->  string  ,试试下面代码
    [DllImport("OCRapi.dll", EntryPoint = "GetTessText", CharSet = CharSet.Ansi, 
              CallingConvention = CallingConvention.Cdecl)] 
    public static extern int GetTessText(byte[] imagefile, string text); 
      

  3.   


    ?OCRapi.dll,功能是什么? 参数是输入,还是返回,楼主没说清.如果输入是图形文件,输出是文本,文字识别软件,返回的参数前加 ref string 输入应该是 byte[] 实际如何,这些在函数原型的文档中应该有说明的.
      

  4.   

    [DllImport("OCRapi.dll", EntryPoint = "GetTessText", CharSet = CharSet.Ansi, 
              CallingConvention = CallingConvention.Cdecl)] 
    public static extern int GetTessText(string imagefile, string text); 
      

  5.   

     Const char*        System.String 或 System.StringBuilder
      

  6.   

    类型不对是不行的,c和c#的char的类型大小是不一样的,所以你得不到返回值。char* 一般对应 StringBuilder,