global static pointer variable in DLL
Zarathustra
adam.chrapkowski at gmail.com
Sun May 18 05:33:54 PDT 2008
torhu Wrote:
> Zarathustra wrote:
> > torhu Wrote:
> >
> >> Zarathustra wrote:
> >> > I have a C DLL whih global static pointer variables.
> >> > When I use this DLL with C everything is ok, but when I try to use it (DLL) with D I receive Acces Violation errors.
> >> > I do not have any idea what is wrong. If something is inexplicable, You will ask. Please help.
> >> >
> >> > simple example code in dll
> >> > gl2ps is global pointer
> >> > [code]
> >> > if(gl2ps){/*
> >> > never true in C but true in D*/}
> >> > [/code]
> >> >
>
> > gl2ps is not exported because it is not necessary beyond DLL.
> > gl2ps declaration in DLL is following:
> > static GL2PScontext *gl2ps = NULL;
> > for example:
> > The crash occurs in exported gl2psBeginPage function. (in attachment)
> > Declaration of above function in D is following:
> > extern (C) GLint gl2psBeginPage; // static linking
> >
> > DLL is little long but very simple, so I can send it to you.
>
> When you say 'crash', do you mean that gl2ps is NULL on line 11 of the
> attached file? Then the problem is likely be in the code that
> initializes gl2ps, not in the gl2psBeginPage function.
Oh, I find out something.
The most crashes occur in similar calls (in DLL) like following:
________________________________________________________
offs += fprintf(gl2ps->stream, "%%PDF-1.4\n");
________________________________________________________
it looks like DLL haven't got access to FILE(gl2ps->stream), but why?
The FILE is operand of gl2psBeginPage.
Call of gl2psBeginPage function in my D code is in following function:
________________________________________________________
extern (C) void
SaveFile(){
FILE* fp;
int state = GL2PS_OVERFLOW;
int buffsize = 0;
try{
fp = fopen("out.pdf", "wb");
while(state == GL2PS_OVERFLOW){
buffsize += 1024*1024;
gl2psBeginPage(
"test",
"gl2psTestSimple",
null,
GL2PS_PDF,
GL2PS_SIMPLE_SORT,
GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT,
GL_RGBA,
0,
null,
0,
0,
0,
buffsize,
fp,
"out.pdf"
);
RenderFrame();
state = gl2psEndPage();
}
fclose(fp);
MessageBoxA(null, "File saved", "Information", MB_OK | MB_ICONINFORMATION);
}
catch(Object o){
MessageBoxA(null, cast(char*)o.toString(), "Critical Error", MB_OK | MB_ICONERROR);
}
}
________________________________________________________
exactly: gl2ps->stream = fp;
More information about the Digitalmars-d-learn
mailing list