Results 1 to 8 of 8

Thread: Convert C header to Pascal (to use dll in project)

  1. #1

    Convert C header to Pascal (to use dll in project)

    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:
    Code:
    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:
    Code:
    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?

  2. #2

    Re: Convert C header to Pascal (to use dll in project)

    Code:
    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';

  3. #3

    Re: Convert C header to Pascal (to use dll in project)

    If I change the

    Code:
    viewport: array[0..3] of GLint;
    into

    Code:
     
    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.

  4. #4

    Re: Convert C header to Pascal (to use dll in project)

    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:

    Code:
    GL2PSDLL_API GLint gl2psEndPage(void);
    into

    Code:
    function gl2psEndPage(): GLInt; stdcall; external 'gl2ps.dll';
    Now if I add the code:

    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)

  5. #5

    Re: Convert C header to Pascal (to use dll in project)

    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

  6. #6

    Re: Convert C header to Pascal (to use dll in project)

    Hi WhatJac3,
    Perhaps you also have an incorrect calling convention defined?

    Maybe

    Code:
    function gl2psEndPage(): GLInt; stdcall; external 'gl2ps.dll';
    should be?

    Code:
    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

  7. #7

    Re: Convert C header to Pascal (to use dll in project)

    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.

  8. #8

    Re: Convert C header to Pascal (to use dll in project)

    Now it does not accepts the GL2PSBeginPage function. If I let that one in, it just crashes. This is my current code:

    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:

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •