I'm trying to write via the native fprint() ox function to a file created in an external c++ dll.
My C++ code is (inspired by the src code of the GnuDraw Package of C. Bos) :
#define OxSetOpenFile(pv,i,d,f) (pv)[i].type = OX_FILE, (pv)[i].t.ioval.fp = d, (pv)[i].t.ioval.fmode = f
extern "C" void OXCALL fopen_C(OxVALUE *rtn, OxVALUE *pv, int cArg)
{
char *sFile;
FILE *fh;
if (cArg != 1)
OxRunError(ER_ARGS, NULL);
OxLibCheckType(OX_STRING, pv, 0, 0);
sFile = OxStr(pv, 0);
fh = fopen(sFile, "w");
if (fh == NULL)
OxRunErrorMessage("Oops, I can't open the file");
OxSetOpenFile(rtn, 0, fh, 162); //162 is found in the gnudraw src code
}
I build the dll with Visual Studio 2015, however I can't write from ox to this file , the following Ox code crash at the fprint() function:
main()
{
decl fh = fopen_C("test.txt");
if(!isfile(fh))
oxrunerror("not file", 0);
fprint(fh, "test text"); /// crash here
}
I got the following error message : "Debug Assertion Error" in close.cpp Expression (_osfile(fh) & FOPEN) .
I found a similar post ( here ) but the answer (to use /MTd or /MDd -ie change the runtime) doesn't work. I can overcome this issue by creating a new fprintf function in C and calling it form Ox ( it works) but I would prefer to use the native ox fprint function. I think this problem can be linked to this one, and finally to the following question: how to pass a file pointer from c to ox in windows ?