Re: C Style FILE pointers from Delphi

From: Rob Kennedy (me3_at_privacy.net)
Date: 08/08/04

  • Next message: J French: "Re: Discovering variable types..."
    Date: Sun, 08 Aug 2004 02:16:04 -0500
    
    

    Shane wrote:
    > Greetings,

    Howdy. Did you post this to enough newsgroups?

    > I need to use a function in a DLL that requires a C Style FILE* to an open
    > file as a parameter.
    >
    > Does any one know how can I open a binary file in Delphi and the pass it as
    > a FILE* ?

    Very carefully. I believe the FILE type is implementation-defined, so
    each C compiler may provide its own definition to support whatever
    information that compiler needs for managing files. Usually, a FILE* is
    a pointer to a struct -- a record. But the layout of that record doesn't
    need to be the same between, say, Visual C++ and C++ Builder.

    I think your best chance of success will be if the DLL is dynamically
    linked to its C run-time library. Then, you can also link your own
    program to that same C run-time DLL and call its fopen function. Fopen
    returns a FILE* value, which you can then pass along to the other DLL.

    If the DLL was compiled with Visual C++, then use TDump to confirm that
    it links with msvcrt.dll. Then import fopen and fclose to your program
    and call them top open and class files that need to go to the DLL.

    type
       CFILE = Pointer;

    function fopen(const filename, mode: PChar): CFILE; cdecl; external
    'msvcrt.dll';
    function fclose(stream: CFILE): Integer; cdecl; external 'mscvrt.dll';

    -- 
    Rob
    

  • Next message: J French: "Re: Discovering variable types..."

    Relevant Pages

    • Re: Exposing bool to non-MS, non-C++ callers
      ... the functions in this DLL accept a structure as an argument. ... The compiler doesn't help catch places where I neglect ... the C++ bool type is defined as one byte. ... depends on whether the Exe caller will push a value larger than 1 byte. ...
      (microsoft.public.dotnet.languages.vc)
    • Re: Memory allocation methods
      ... all modules are compiled against the same CRT' DLL with the same compiler. ... that case you restrict yourself to a simple C-based API for the DLL. ... I prefer to use either exceptions (but writing exception-safe code is quite ...
      (microsoft.public.win32.programmer.kernel)
    • COBOL Compiler options
      ... calls to CICS. ... we do not document this DLL problem nor have compiler options ... use of DLL's with the integrated translator (for cases where it is valid ...
      (bit.listserv.ibm-main)
    • Re: Export class from dll
      ... Remember that C++ classes describe not only the general characteristics of ... Only when the DLL ... about the compiler not knowing the details of a CBox, ... How does the compiler know what CBox is? ...
      (microsoft.public.windowsce.embedded.vc)
    • Re: ASP.NET application load time after some change
      ... This utility combines multiple .NET dll's into one dll file. ... The speed can also be affected by how much stuff is in viewstate. ... controls such as Labels or Controls who have their value set in the Load ... because the compiler only needs to compile it once. ...
      (microsoft.public.dotnet.framework.aspnet)