View Full Version : Convert C header to Pascal (to use dll in project)
WhatJac3
04-08-2010, 07:15 PM
Hello,
I am trying to convert a C header file to Pascal to use the dll (gl2ps) in my application. I have a 3 little problems with it. Maybe any of you can help me with this.
The C header file is:
typedef GLfloat GL2PSrgba[4];
GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer,
GLint viewport[4], GLint format, GLint sort,
GLint options, GLint colormode,
GLint colorsize, GL2PSrgba *colormap,
GLint nr, GLint ng, GLint nb, GLint buffersize,
FILE *stream, const char *filename);
My current conversion is:
GL2PSrgba = array[0..3] of GLfloat;
function gl2PSBeginPage(const title: PAnsiChar; const producer: PAnsiChar;
GLint viewport[4]; // <--- PROBLEM 1
format,sort,options,colormode,colorsize: GLInt;
GL2PSrgba *colormap; // <--- PROBLEM 2
nr, ng, nb, buffersize: GLInt;
FILE *stream; // <--- PROBLEM 3
const filename: PAnsiChar): GLInt;
stdcall; external 'gl2ps.dll';
My 3 problems are:
1) How to pass an array[4] of type GLInt?
2) How to pass *var as GL2PSrgba?
3) What is a compareable type in Pascal with FILE?
jdarling
04-08-2010, 07:42 PM
PGL2PSrgba = ^GL2PSrgba;
function gl2PSBeginPage(const title: PAnsiChar; const producer: PAnsiChar;
viewport: array[0..3] of GLint; //array of 4 glint elements
format,sort,options,colormode,colorsize: GLInt;
colormap : PGL2PSrgba; // pointer to colormap information
nr, ng, nb, buffersize: GLInt;
stream : TStream; // this may be wrong, but should be a file stream pointer
const filename: PAnsiChar): GLInt;
stdcall; external 'gl2ps.dll';
WhatJac3
04-08-2010, 08:00 PM
If I change the
viewport: array[0..3] of GLint;
into
GLVWarray = array[0..3] of GLInt;
viewport: GLVWarray;
the compiler accepts it. Now let me check whether it works. Thanks so far, I'll get back to you.
WhatJac3
04-08-2010, 08:14 PM
The program completely crashes if I put any code anywhere which calls any of the dll functions.
Let's take a more easier function first. I have converted:
GL2PSDLL_API GLint gl2psEndPage(void);
into
function gl2psEndPage(): GLInt; stdcall; external 'gl2ps.dll';
Now if I add the code:
var
state: GLInt;
begin
state := gl2psEndPage();
The application completely crashed before even showing any of the information. Compiling works but executing gives me an error and won't start, until I comment those lines.
Here is what the compiler says:
Module Load: COMDLG32.dll. No Debug Info. Base Address: $75E30000. Process General.exe (3976)
Module Load: UNKNOWN_MODULE_11. No Debug Info. Base Address: $67660000. Process General.exe (3976)
Module Load: MSVCR100D.dll. No Debug Info. Base Address: $5F4D0000. Process General.exe (3976)
Debug Output: *** A stack buffer overrun occurred in "C:\...\General.exe" : Process General.exe (3976)
Debug Output: This is usually the result of a memory copy to a local buffer or structure where the size is not properly calculated/checked. Process General.exe (3976)
Debug Output: If this bug ends up in the shipping product, it could be a severe security hole. Process General.exe (3976)
Debug Output: The stack trace should show the guilty function (the function directly above __report_gsfailure). Process General.exe (3976)
Debug Output: *** enter .exr 770B9310 for the exception record Process General.exe (3976)
Debug Output: *** then kb to get the faulting stack Process General.exe (3976)
WhatJac3
04-08-2010, 08:34 PM
I found out with DLL export viewer that I might not have the correct DLL, since it does not export any functions. I'll check into that first
paul_nicholls
04-08-2010, 08:42 PM
Hi WhatJac3,
Perhaps you also have an incorrect calling convention defined?
Maybe
function gl2psEndPage(): GLInt; stdcall; external 'gl2ps.dll';
should be?
function gl2psEndPage(): GLInt; cdecl; external 'gl2ps.dll';
hmm...if the DLL doesn't export any routines, the code wouldn't compile, would it?
cheers,
Paul
WhatJac3
04-08-2010, 09:02 PM
I have recompiled the dll and changed all sorts of things and now it does show the export functions.
After this I got errors again and I changed the calling convention and now I dont get any errors. Now keep my fingers crossed to see if it really works.
WhatJac3
04-08-2010, 09:16 PM
Now it does not accepts the GL2PSBeginPage function. If I let that one in, it just crashes. This is my current code:
type
GL2PSrgba = array[0..3] of GLfloat;
GLVWarray = array[0..3] of GLInt;
PGL2PSrgba = ^GL2PSrgba;
function gl2PSBeginPage(const title: PAnsiChar; const producer: PAnsiChar;
viewport: GLVWarray;
format,sort,options,colormode,colorsize: GLInt;
colormap: PGL2PSrgba;
nr, ng, nb, buffersize: GLInt;
stream: TStream;
const filename: PAnsiChar): GLInt;
cdecl; external 'gl2ps.dll';
This is how I call the code:
const cExportTitle = 'test';
const cExportCreator = 'test';
var
buffsize, state: GLInt;
viewport: GLVWarray;
fp: TFileStream;
FileName : PAnsiChar;
begin
FileName := PAnsiChar(Name);
fp := TFileStream.Create(Name, fmOpenWrite or fmCreate);
buffsize := 0;
state := GL2PS_OVERFLOW;
glGetIntegerv(GL_VIEWPORT, @viewport);
gl2psBeginPage (cExportTitle, cExportCreator, viewport,
GL2PS_EPS, GL2PS_NO_SORT, GL2PS_SILENT OR
GL2PS_SIMPLE_LINE_OFFSET OR GL2PS_OCCLUSION_CULL OR
GL2PS_BEST_ROOT,
GL_RGBA, 0, nil, 0, 0, 0, buffsize,
fp, FileName);
The dll and the unit that I created can be found at htpp://www.jsv6.nl/gl2PS.zip (http://htpp://www.jsv6.nl/gl2PS.zip).
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.