C程序写的API:
OCRSKIN_API unsigned long MMM_GetOCR_ImageItem(char *label, char *format, unsigned char *data, unsigned long *dataLength);C#中对API的申明:
        [DllImport("OcrSkin.dll")]
        public static extern int MMM_GetOCR_ImageItem(string label, string format, out int[] data, ref uint dataLength);C#程序中的调用:
        uint size = 0;
        int[] buffer;
        int l = OCRReader.MMM_GetOCR_ImageItem("@photo", "JPG 30", out buffer, ref size);错误提示Buffer太小,什么地方出问题了?帮忙看看吧,老板急着要答案,API的提供方是美国3M公司AIT证件刷卡机,在中国好像没有技术支持部门。

解决方案 »

  1.   

    补充一下,3M提供的示例程序也使用C写的,他的调用方法如下:
    res = MMM_GetOCR_ImageItem("@photo", "JPG 30", NULL, &size);
    if (res == 0){
    printf("GetPhoto size = %d\n", size); pBuffer = (unsigned char *) malloc(size);
    if (pBuffer != NULL){
    res = MMM_GetOCR_ImageItem("@photo", "JPG 30", pBuffer, &size);
    printf("GetImage photo = %d\n", res);
    if (res == 0){
    FILE *fd;
    fd = fopen("photo.jpg", "wb");
    if (fd != NULL){
    fwrite(pBuffer, 1, size, fd);
    fclose(fd);
    }
    } free(pBuffer);
    }
    }我现在就是在把这段代码翻译成C#的过程中出现了问题,求教!
      

  2.   

    data或buffer是不是定义的太小了
      

  3.   

    (char *label, char *format, unsigned char *data, unsigned long *dataLength);  [DllImport("OcrSkin.dll")] 
            public static extern int MMM_GetOCR_ImageItem(string label, string format, string data, uint dataLength); 
      

  4.   

     uint size = 0; 
    为什么是0?这个参数是不是应该是预期的输出大小?既然他用Ref,就是期待你在外面赋值。
      

  5.   

    unsigned char *data 应该是由调用者来准备。你这样试试:[DllImport("OcrSkin.dll")] 
    public static extern int MMM_GetOCR_ImageItem(string label, string format, byte[] data, ref uint dataLength); C#程序中的调用: // 取得数据的大小
    uint size = 0; 
    OCRReader.MMM_GetOCR_ImageItem("@photo", "JPG 30", null, ref size); // 取数据
    byte[] buf = new byte[size];
    OCRReader.MMM_GetOCR_ImageItem("@photo", "JPG 30", buf, ref size); 
      

  6.   

    你的buffer没有初始化大小 
    int size =0;
    res = MMM_GetOCR_ImageItem("@photo", "JPG 30", null, ref size); 
    int[] buffer = new int[size];
      

  7.   

    不知道c里面函数怎么实现的
    刚才测试了一下
    (char *label, char *format, unsigned char *data, unsigned long *dataLength);   
     [DllImport("OcrSkin.dll")]   
            public static extern int MMM_GetOCR_ImageItem(string label, string format, string data, uint dataLength);   
     
    是没有问题的,看来是函数里的问题了
    这个函数是做什么的?还有里面的参数都用什么意义?