Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DLL Talk / Creating DLLs in Delphi

Author
Message
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 7th Nov 2004 00:07
Anyone have any examples of how to create a DLL for use with DBPro with Delphi. I have found an example of a simple DLL that works with Delphi, but am having trouble getting it to work with DBPro. I can't find how to create a string table either, creating a blank rc file means that the string table editor doesn't let you edit any strings. Basically, I just don't get the theory behind creating DLLs and it's making it pretty hard for me to get started . Any help, examples or resources would be appreciated. Thanks .

Isn't it? Wasn't it? Marvellous!
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 7th Nov 2004 02:05
A very basic example: Create a DLL with a SumInteger function, that simply adds two integer values:

1) Go to File->New->Other
2) In the "New Items" dialog select "DLL Wizard" and click OK
3) The generated code looks like this:

4) Remove SysUtils and Classes from the uses clause and add Windows instead. Save the project.
5) Now we write the function. We also want to "export" this function, that means other programs (in this case DBP) can access this function. So the source will now look like this

6) Now create a simple text file and call it "cmdtable.rc". Save it in the directory of this Delphi project. The file should contain:

7) Now open a console (cmd.exe) and switch to the project directory and call Borland's resource compiler:

This will create a file called cmdtable.RES. We need to bind that to our Project. So the complete source code looks like this:

8) Compile the project. Now you can copy the compile DLL in DBPro's user-plugins folder. To access the command type


Play Nice! Play Basic!
Version 1.02 available now!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 7th Nov 2004 02:49
Nice . Cheers for that empty, got your example working perfectly.

Isn't it? Wasn't it? Marvellous!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 7th Nov 2004 03:30 Edited at: 7th Nov 2004 03:31
Ok, I tried to use a string as a parameter but I'm having troubles. It doesn't seem to like it even if I use a PString like it says in the help files.

EDIT

Hmmm, maybe I have to use PChar somehow.

Isn't it? Wasn't it? Marvellous!
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 7th Nov 2004 03:36 Edited at: 7th Nov 2004 03:36
Yup for passing strings you need PChar. Returning strings is a different book, though.

Play Nice! Play Basic!
Version 1.02 available now!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 7th Nov 2004 03:39
PChar doesn't seem to work. This is my code so far. The function doesn't actually do anything, it just takes a string and returns an integer.





Isn't it? Wasn't it? Marvellous!
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 7th Nov 2004 03:42
What exactly happens when you call it?

Play Nice! Play Basic!
Version 1.02 available now!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 7th Nov 2004 03:44 Edited at: 7th Nov 2004 03:45
The instruction at "0x00000000" referenced memoryat "0x00000000". The memory could not be "read".

That message 3 times, 2 times before the window appears, and once when it appears.

Ps. I added ShareMem into the USES clause, since the dll wizard told me to .

Isn't it? Wasn't it? Marvellous!
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 7th Nov 2004 03:47 Edited at: 7th Nov 2004 03:47
I can't test it at the moment, but provided you re-compiled the rc file () try using LongInt instead of Integer as the function result. BTW, what Delphi version do you use?

Play Nice! Play Basic!
Version 1.02 available now!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 7th Nov 2004 03:57
Got it working, cheers for the help, it was the ShareMem library that was screwing everything up, you don't actually need it. I'm using Delphi 7.

Just out of interest (and I may want to do it later ), how is returning strings a different book?

Isn't it? Wasn't it? Marvellous!
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 7th Nov 2004 04:07
Quote: "you don't actually need it."

Nope, only when you want to pass and return "real" Delphi strings to the DLL (in that case you'd need the sharemem.dll as well)


Quote: "Just out of interest (and I may want to do it later ), how is returning strings a different book?"

DBpro takes care of the memory management for strings. So whenever want to return a string you get an address of an old (unused string). You need to call a DBpro function called "DeleteCreateString" which returns an address of a string you can use now. After that you need to copy the result of your function to that address.

I just remember that I made a commented example for Delphi TPCs a while ago.
http://www.dannywartnaby.co.uk/rgt/index.php?board=17;action=display;threadid=616

Play Nice! Play Basic!
Version 1.02 available now!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 7th Nov 2004 04:35
Cheers empty .

Isn't it? Wasn't it? Marvellous!
lagmaster
21
Years of Service
User Offline
Joined: 26th Aug 2002
Playing:
Posted: 7th Nov 2004 22:46
oh cool, glad there's a detailed guide on how to create a dbpro tpc dll in delphi.

been rattling my brain over this one for a few days.

cheers

lagmaster - http://www.lagmaster.net was alive! http://www.dbforums.co.uk/ - was another db forum!

Dark Snippet Pro V9.2 is still out!! somewhere
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 10th Nov 2004 04:12
Hmm, now I have the problem of calling a function within a DBPro dll. How would I do this? I presume I'd have to somehow load the dll, and besides, I can't even find the basic3D dll (which is what I'm trying to access).

Isn't it? Wasn't it? Marvellous!
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 10th Nov 2004 04:20
You would have to load the DLL (using the Delphi equivilent of LoadLibrary), get the address of the function you want to call and then call the function indirectly through the address).

Walk softly... and carry a big gun...
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 11th Nov 2004 00:06
Yes you can either use loadlibrary or you use my GlobStruct header translation (comes with the rar file linked above).

For instance to simulate the "Color Object" within the TPC, using the provided example Project, the procedure would look like this:


Play Nice! Play Basic!
Version 1.02 available now!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 11th Nov 2004 04:11
Cool thanks.....


but (I feel so stupid asking all these questions ), where can I find Direct3D9.dcu? I've googled and googled and searched some more, and I can't find it anywhere .

Isn't it? Wasn't it? Marvellous!
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 11th Nov 2004 05:47
Although you don't need it (well for my example at least), you can find the link to the DX9 header translations (which also contains Direct3D9.pas) in one of my posts in the LLRGT thread. But I'm a nice guy so here you are.
http://clootie.narod.ru/delphi/download_dx90.html

Play Nice! Play Basic!
Version 1.02 available now!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 11th Nov 2004 08:02
Cheers !

Ok, I have the example working again (color object example), but it crashes on trying to get the proc address...



I have got the dll working, and it calls the procedure, I can comment out the stuff inside and it will work, comment out just the DoColor() line and it crashes, so it's something to do with that line, but I don't know what.

Isn't it? Wasn't it? Marvellous!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 11th Nov 2004 08:27
*Slaps self on head *

I forgot to add the globcore pointer getter function thingy. Twerks perfectly now, and I'm a happy man .

Isn't it? Wasn't it? Marvellous!
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 11th Nov 2004 16:12
Great.

Play Nice! Play Basic!
Version 1.02 available now!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 11th Nov 2004 17:02
Ok, now onto my next task .

Mike has told me to reference the GetObject() function in the Basic3D dll to get a pointer to a DBO object, only I don't have a header file containing the sObject structure (Mike sent me the C++ version). Do you know if anyone has translated any of the headers? I presume there are ones for bitmaps, images, cameras and everything else. If not I guess I'll try and use my limited knowledge of C++ to try and de-cypher the structure of the DBO object .

Cheers.

Isn't it? Wasn't it? Marvellous!
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 12th Nov 2004 00:56
The only DBpro related header translation I wrote was the one for the global structure. I don't think anyone else has written translations for the other structures, so I'm afraid you'll have to do it on your own... I'll gladly try to help, if you get stuck.

Play Nice! Play Basic!
Version 1.02 available now!

Login to post a reply

Server time is: 2024-04-26 10:26:42
Your offset time is: 2024-04-26 10:26:42