从 dll 访问 .csv 文件

问题描述

我试图访问我的 DLL 中的文件,但 fopen 总是返回 NULL。我对 DLL 不是很熟悉,也不知道如何调试这个问题。我试图用可执行文件运行我的程序,它运行没有错误。我在下面发布了我的 .c 和 .h 文件,任何帮助表示赞赏。 ReadFile1.c:

#include "ReadFile1.h"
    #define MAX_STR_LEN 257
    #define MAX_Color_Maps 17
    int __declspec(dllexport) __stdcall ReadF(char* ColorMap)
    {
        FILE* bookFile;
        /* allocation of the buffer for every line in the File */
        char* buf = malloc(MAX_STR_LEN);
        char* tmp;
        /* if the space Could not be allocated,return an error */
        if (buf == NULL)
        {
            printf("No memory\n");
            return 1;
        }
        if ((bookFile = fopen("Colormaps2.csv","r")) == NULL) //Reading a file
        {
            printf("File Could not be opened.\n");
            printf("%s",strerror(errno));
            return 1;
        }
        struct Color_decider Colors[MAX_Color_Maps];
        int i = 1;
        fgets(buf,256,bookFile);
        tmp = strtok(buf,";");
        char* temp1;
        temp1= strdup(tmp);
        strncpy(Colors[0].Color_maps,temp1,strlen(temp1));
        while (i<17)
        {
            tmp = strtok(NULL,";");
            temp1 = strdup(tmp);
            strncpy(Colors[i].Color_maps,strlen(temp1));
            i++;
        }
        for (int k = 1; k < 17; k++)
{
    if (!strcmp(Colors[k].Color_maps,ColorMap))  // Find the input column.
    {
        for (int j = 0; j < 256; j++)
        {
            fgets(buf,bookFile);
            tmp = strtok(buf,";");
            for (int l = 1; l < k * 3; L++)
                tmp = strtok(NULL,";");

            tmp = strtok(NULL,";");
            temp1 = strdup(tmp);
            Colors->C[j][0] = atoi(temp1);
            tmp = strtok(NULL,";");
            temp1 = strdup(tmp);
            Colors->C[j][1] = atoi(temp1);
            tmp = strtok(NULL,";");
            temp1 = strdup(tmp);
            Colors->C[j][2] = atoi(temp1);
            printf("%d\t",Colors->C[j][0]);
            printf("%d\t",Colors->C[j][1]);
            printf("%d\n",Colors->C[j][2]);

        }
        break;
    }
}
free(buf);
fclose(bookFile);
return 0;
    }

ReadFile1.h

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
struct Color_decider {
    char Color_maps[10];
    int C[256][3];
};
char *strdup(char *org)
{
    int org_size;
    static char *dup;
    char *dup_offset;
    /* Allocate memory for duplicate */
    org_size = strlen(org);
    dup = (char *)malloc(sizeof(char)*org_size+1);
    if( dup == NULL)
        return( (char *)NULL);

    /* copy string */
    dup_offset = dup;
    while(*org)
    {
        *dup_offset = *org;
        dup_offset++;
        org++;
    }
    *dup_offset = '\0';

    return(dup);
}
int __declspec(dllexport) __stdcall ReadF(char* ColorMap);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...