English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 04 March 2008, 09:43   #1
redhair
 
Posts: n/a
Easiest way to insert a file into an ADF? (Delphi)

Hello!

I have a big problem. I need to insert a single file into an ADF with Delphi, as simple as possible.

I've downloaded Big-Byte's ADF Toolkit from http://eab.abime.net/showpost.php?p=170677&postcount=2 but there is a problem: The file seems to be inserted and I can see it in the directory listing, but if I try to access it with Amiga or with ADFView, I get a "file not found" error.

I've attached two ADFs, a working (inserted with ADFView) and the not working disk (with Big-Byte's code). Maybe someone can compare the files where the error is and maybe how I can fix it or at least a hint?

My next idea was to use adflibd.dll from the Win32 console app of UnADF (ADFLib), I've checked http://lclevy.free.fr/adflib/api.html but this is a bit difficult in Delphi Is someone able to give me a hint how I can insert a file into an existing ADF with the help of this dll? As I am able to see, the necessary functions seem to be available in this dll file, but I have big problems to use them in Delphi.

Or are there other alternatives, for example commando line commands for ADFView or something else?

Can someone help me, somehow?
Thank you
Attached Files
File Type: zip Disks.zip (5.9 KB, 186 views)
File Type: zip binw32.zip (176.0 KB, 221 views)
 
Old 06 March 2008, 16:10   #2
eLowar
Citizen of Elthesh
 
eLowar's Avatar
 
Join Date: Sep 2003
Location: UK
Posts: 949
The only thing "tricky" about ADFLib is that you have to open Device, Volume and finally File in the right order.

Unfortunately I don't have time to write a long explanation right now, but if you want to see a little example (albeit in C++), check out the source code of my Little Computer People serial number editor: http://eab.abime.net/showthread.php?p=275636#post275636

The source code is included in the archive. The interesting bits are in MainWindow.cpp, in particular under void MainWindow::open() and void MainWindow::save(QString fileName). The ADFLib functions all start with adf*, I think.

This doesn't show how to insert a new file, but I think all you have to do is open a file with the right mode. Sorry, it's been a while since I looked at it. The ADFlib docs should tell, though.
eLowar is offline  
Old 06 March 2008, 19:40   #3
redhair
 
Posts: n/a
Thanks a lot, checked your source code, but, although it looks so simple, I am still not able to convert it to Delphi...

I need somehow to declare the necessary functions of this C++ dll in Delphi, so I could use them, but I am not able to translate them. The only thing I reached yet is to show version number and date...
Code:
const
   adflib = 'adflibd.dll';
   function adfGetVersionNumber(): PChar; external adflib;
   function adfGetVersionDate(): PChar; external adflib;
 
procedure TForm1.FormCreate(Sender: TObject);
   begin
      Label1.Caption:=adfGetVersionNumber();
      Label2.Caption:=adfGetVersionDate();
      Label3.Caption:=adflib;
   end;
But now I need to inject a file into an ADF with a click of a button. And if I check the docs of ADFLib again, then I wonder how this here
Code:
struct Device* adfMountDev( char* name)
would look in Delphi?
 
Old 07 March 2008, 18:56   #4
eLowar
Citizen of Elthesh
 
eLowar's Avatar
 
Join Date: Sep 2003
Location: UK
Posts: 949
The library itself is plain C and only uses plain C datatypes. My Pascal is a little shaky (haven't used it in years and years), so I'm not sure how to properly translate the prototype.

What I can tell you is that the Device pointer (Pascal has pointers and/or references too, right?) you get is just a handle, probably 32 bits (depending on what architecture the DLL was compiled for, but 32 bits are likely), and you only have to store it and pass it to the appropriate functions. The contents of the pointer are completely irrelevant to you and only matter to the library, so I assume any datatype with the right size will do (maybe a 32-bit integer type).

As for the name parameter, that's a plain C string (address of a character array), which may be tricky because Pascal (as far as I remember) stores strings differently than C. While C stores them \0 (null character) terminated, Pascal (again, as far as I remember) prefixes them with their length instead. I'm sure if you look up general information about accessing C libraries from Pascal that problem will be addressed, though.

Edit: I reformulated some things after thinking after writing.

Last edited by eLowar; 07 March 2008 at 19:08. Reason: Clarified some things.
eLowar is offline  
Old 07 March 2008, 20:49   #5
so.
Registered User
 
Join Date: Dec 2007
Location: Sweden
Posts: 33
PChar is the Pascal pointer-to-char, if I recall correctly. You could translate the header files, I'm sure there exists a tool for this problem.
so. is offline  
Old 26 March 2008, 22:37   #6
Feltzkrone
Junior Member
 
Feltzkrone's Avatar
 
Join Date: Apr 2002
Location: Germany
Posts: 103
  • When declaring external functions you should use the keyword "stdcall". It is the most common calling convention for DLL functions. A calling convention defines how CPU registers and how the stack is used to pass function parameters. This should solve your problems when trying to call ADFLib functions.(German Wikipedia)
  • PChar (=PAnsiChar) is the Pascal equivalent of char*. Lets say variable A is declared as String and variable B is declared as PChar. To assign one to another you can use: A := B and B := PChar(A). In that way Pascal strings must be casted to PChar prior using it as parameters passed to ADFLib functions. For the other direction there's no problem as you already assign a PChar to a label caption.

Hopefully I could help a little bit...
Feltzkrone is offline  
Old 25 April 2008, 21:29   #7
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
Hey, a Delphi programmer! Good man.

Looked at elowar's thread for 5 seconds, didn't find a link to the c source or a snippet, otherwise I could help - I've had to learn a bit of c to get going on the gp2x.
Photon is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fastest,Easiest,Cheapest way to transfer adf images between PC and Amiga(mostly 500) ikonsgr support.Hardware 129 14 September 2017 10:08
ADF File Comparison Radertified request.Apps 17 29 July 2013 00:50
Command line tool to insert files into an ADF? cdoty Coders. General 1 07 December 2009 10:53
Copy CF card file to ram:, insert other CF card, copy over? Photon support.Hardware 16 21 July 2009 22:05
Running non .adf file, .info file?? ypestis New to Emulation or Amiga scene 5 29 March 2006 18:53

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:59.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.11015 seconds with 16 queries