Results 1 to 4 of 4

Thread: How do I properly implement the C struct FILE in ASM?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    How do I properly implement the C struct FILE in ASM?

    My situation is as follows. My software is to be written in VB6, but it will need to load images with LibPNG. The problem with LibPNG is it uses CDECL calling convention, so that means I will need to make a STDCAL wrapper for it, and the easiest way I can think of is in assembly. But even this has an issue. The LibPNG functions do not read from memory, so loading the PNG file into memory and then letting LibPNG read it from memory is not an option. Nor does it let you specify the filename and then let LibPNG load the file internally. The ONLY input you are allowed to provide to LibPNG, for loading the PNG file, is a pointer to a FILE struct (which was created when you used the fopen function in C or C++), which is EXCLUSIVELY a C and C++ feature. LibPNG is therefore strongly tied to C and C++, vastly limiting what programming languages it can be used with. I want to write my wrapper in ASM, and use the Windows API file loading function called CreateFile. In order to duplicate the C functionality that LibPNG is expecting in the FILE struct, I'm going to need to figure out EXACTLY what the structure of a FILE struct is. What fields the struct has, and exactly what each field is used for, so I can implement this in ASM.

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,854

    Re: How do I properly implement the C struct FILE in ASM?

    First, why do you think you need ASM to write a wrapper? You can also use C
    Second, the trick created a VB6 AddIn which makes it possible to use CDECL libraries directly from VB6.
    You can find it in the codebank.
    https://www.vbforums.com/showthread....ons-in-VB6-IDE
    Last edited by Arnoutdv; May 21st, 2021 at 01:13 AM.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    Re: How do I properly implement the C struct FILE in ASM?

    Quote Originally Posted by Arnoutdv View Post
    First, why do you think you need ASM to write a wrapper? You can also use C
    Second, the trick created a VB6 AddIn which makes it possible to use CDECL libraries directly from VB6.
    You can find it in the codebank.
    https://www.vbforums.com/showthread....ons-in-VB6-IDE

    Thanks. That will be a HUGE help, not only with this project with LibPNG, but others as well. However, LibPNG still has the issue of requiring as input, a pointer to a C struct called a FILE. The FILE struct is opaque, and you only pass the pointer to the LibPNG function, which is fine for programming in C. I want to use LibPNG though in a VB6 program I'm making, to give it the ability to load PNG files, and while VB6 can use the Windows API function CreateFile to create a file handle, a Windows API file handle is NOT the same thing as a FILE* (aka a pointer to a FILE struct, which is something unique to the C programming language). So unless I can write a VB6 userdefined type that is layed out the same as a C FILE struct, and also write VB6 code to properly populate that structure with the correct values (just like the fopen function in C does), I still will have the issue of needing to get a FILE* type object to pass to the LibPNG functions. That right now is the biggest hurdle, and is something that if I can't get past it, I will be limited to using LibPNG in C or C++, and I do want to use it in VB6. Unless some other option is made available with the same functionality as LibPNG, I'll be stuck trying to figure out how to use LibPNG in VB6.

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,854

    Re: How do I properly implement the C struct FILE in ASM?

    To my knowledge Olaf Schmidt has also incorporated libPNG in his RichClient library.

    And this old thread by you is also about the same topic.
    https://www.vbforums.com/showthread....LibPNG-for-VB6

Posting Permissions

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



Click Here to Expand Forum to Full Width