Hi,
I am having an issue with creating a DLL with calls to (among other
things) the C standard library within.
I have reduced my problem to the following pieces of code:
/***************** dll.c ***************/
#include <stdio.h>
#include <stdlib.h>
int dt_read(FILE *f)
{
int status = EXIT_FAILURE;
char buf[100];
if (f != NULL)
{
if (NULL != fgets(buf, sizeof buf, f))
{
buf[sizeof buf - 1] = 0;
puts(buf);
status = EXIT_SUCCESS;
}
}
return status;
}
/****************** end of dll.c **************/
This code is compiled and linked into a DLL with the following .def file:
/*************** begin dll.def ****************/
LIBRARY DLL
DESCRIPTION "dll test dll"
VERSION 1.0
EXPORTS
dt_read
/*************** end dll.def *******************/
Then another application uses the code (dynamically linking to the DLL)
as follows:
#include <stdio.h>
#include <stdlib.h>
#include "dlltestdll.h"
int main(void)
{
int status = EXIT_FAILURE;
FILE *f;
f = fopen("main.c", "r");
if (NULL != f)
{
char buf[100];
if (NULL != fgets(buf, sizeof buf, f))
{
buf[sizeof buf - 1] = 0;
puts(buf);
}
status = dt_read(f);
}
fclose(f);
return status;
}
As the code shows, there are two similar calls to fgets, one from the
program itself, and the other one from the DLL. While the first call
succeeds, the second one fails somewhere deep into fgets. I can only
imagine that this is cause by some corruption due to bad calling
conventions, but am at lost as to how to correct/manage it. Any hints ?
--
Bertrand Mollinier Toublet
int main(){char*strchr();int j=1234;char t[]=":@abcdefghij-lmnopqrstuv"
"wxyz.\n",*i="iqgbgxmbbla.llsvoaz:zdxylaxejivnidhd@ttopnjeftuh-i";while
(*i){j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);}return 0;}