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 / Modal dialogs and delphi stuff

Author
Message
zog
16
Years of Service
User Offline
Joined: 13th Dec 2007
Location: Southport UK
Posted: 14th Dec 2007 00:46
I have managed to create my own dark basic commands using delpi2007. I have also managed to convert the c header files to pascal code. If I display a modal dialog box from within my dll and drag it about the screen the dark basics window does not repaint itself so I get left with a nasty trail of unpainted areas on the screen. Is there anyway to get dark basic to repaint its window correctly while dragging my dialog box across the top of it ?
I have also had a bit of trouble returning strings from my dll functions, the variables seem to get messed up on the stack when I am passing them for example the delphi function, do I need to add a dummy parameter?

function GetString(i:integer):LPSTR;cdecl;

the variable i gets messed up and the wrong value is passed in i

Also I would like to be able to debug my dll using delphi by attaching delphi's debugger to the exe that DarkBasic creates when it compiles a program. Some how the exe darkbasic creates is managing to disable the debugger in delphi I think, any ideas ?

Thanks Jack Taylor

Jack Taylor
Copper Head
18
Years of Service
User Offline
Joined: 10th Dec 2005
Location:
Posted: 26th Dec 2007 16:58
Seems to me that you got somekind of pointer trouble here. Your calling convention "cdecl" should be changed to "stdcall" since the DLL is used as a standard DLL-file. This might not make such a diffrence in your specific declaration here since you got only one parameter in it but i still felt it might be worth mentioning.

Further, how do you return the result value? Seeing it's a mere pointer returned you need to make sure the actual data it is pointing to is not destroyed as the function exists. Also, do you point to the actual data or just the pointer to the data?

Then to my question.. if you know how to use delphi then why are you using DarkBASIC anyway? Have you never heard of DelphiX?
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 26th Dec 2007 19:09
isnt the modal dialog pausing dbp's thread? if thats the case wouldnt it make sense that it wont repaint, and if so not sure how you would get around it. I have plugins for dbp that have some modal dialogs and such but I cant recall ever testing that aspect. that might be interesting for me to try but since dbp's dead on gone on all my machines - dont know if I can

My DBP plugins page is now hosted [href]here[/href]
zog
16
Years of Service
User Offline
Joined: 13th Dec 2007
Location: Southport UK
Posted: 27th Dec 2007 08:45
I have solved the calling problem with dark basic pro. As I am writing new commands the functions must be declared cdecl as it says in tec documentation. If you have a function passing a string back to dbp then you have to include a dummy parameter in the function call.

Thus


function GetString(i:integer):LPSTR;cdecl;
should be

function GetString(dummy:LPSTR,i:integer):LPSTR;cdecl;

although you have declared a function with two parameters you only pass the integer from db pro. DBpro sorts this out when you make your function declaration in the import string table for new commands.

Why I am programming in dbPro.

Simply because I like it, it is simple and easy to use. The printed documentation is excellent. I can protype code in dbpro that might take weeks to construct in an other programming languages. I can test 3d models easily. It is a function based language that does not contain a huge clutter of complex, over encapsulated nested classes and objects such as .net or java. It compiles to native 32bit code. I am new to 3D games programming so dbpro is giving me the opportunity to learn the techniques without getting bogged down in the DirectX SDK to start with

I can program in C++, VB6 and delphi.

C++ acheives excellent results, but is a ball ache to program in.
Delhi is very good for certain things, but the digital documentation is v bad.

VB6 is very good for business software but is now obsolete.

dbpro is a good language because it allows you to create your own functions in other languages so you can leaverage in advanced techniques when you need them. I also like dbpro because it is cheap and accessible to the little guy. The other programming languages cost a lot of money. If I wanted to teach somebody to program from scratch I would pick dbpro every time.

Jack Taylor
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 27th Dec 2007 14:57
@zog
There is one way to create a dialog, while allowing DBP to repaint. Firstly, you should disable the DBP window, using the windows api, then show the dialog in a separate thread from the DBP window, and return. You should add another command that checks if the thread for the dialog is still running, and if it is, return the result and enable the DBP window again. I have done it, and it seems to work

Copper Head
18
Years of Service
User Offline
Joined: 10th Dec 2005
Location:
Posted: 28th Dec 2007 13:03
So you mean that you need to supply the result as the first parameter aswell in order to make DBPro able to read it? Makes you wonder how DBPro handles things underneath the surface really. Well, as long as it works.

I do agree with you that C++ is a grindtastic language, i do not prefer it either. I don't know what Delphi version you got really but my version has excellent digital documentation and i find it to be a very powerful language indeed. Then again, for a small scale programmer and/or project Delphi certainly is not in the same pricerange as DBPro, that's for sure. It's way more expensive.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 28th Dec 2007 19:14
@Copper Head
DBPro only does that for strings. This is to avoid memory leaks, because string are actually pointers to arrays. If you just returned a string, DBP wouldn't know whether to free the old string. It is the same way that winapi and C++ string commands work: you pass the return string as a parameter, so that allocations and deallocations stay within their own function in the function stack.

zog
16
Years of Service
User Offline
Joined: 13th Dec 2007
Location: Southport UK
Posted: 29th Dec 2007 04:59
Thanks Diggsley for the advice. I think your approach is probably the best way to tackle this problem, especially if your code, calls windows code that might generate its own dialog for example a twain driver.

Mr Copper Head, I own three version of delphi D7, D8 and D2007 pro. D2007 pro uses microsoft's document explorer. See how long it takes you to locate information about basic data types. I prefer to use D7 windows 3.1 help system over this program as it's a lot faster. In my opinion the ultimate online help system from programmers still has to be written. A poor help system leads to poor programmer productivity.


Jack Taylor
zog
16
Years of Service
User Offline
Joined: 13th Dec 2007
Location: Southport UK
Posted: 4th Mar 2008 16:52 Edited at: 4th Mar 2008 16:54
After further experimentation, I found that certain windows dialogs don't like being run under their own threads in windows. What I do now is that if dark basic is running in a non windowed enviroment. I create another window to sit on top of dark basics pros window and copy the image of dark basics window to my own. However I have discovered another problem, and that is, that when execution returns back to dark basic after displaying certain windows dialogs the inkey$ , and the wait key functions loose some key strokes. How do I sort this problem out ?

thanks for any help

Jack Taylor

Jack Taylor
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 4th Mar 2008 17:56
You want to use modeless dialogs as opposed to modal dialogs.
zog
16
Years of Service
User Offline
Joined: 13th Dec 2007
Location: Southport UK
Posted: 5th Mar 2008 07:32
I can't use modeless dialog boxes because the dialogs are generated by windows. You may be aware,by now that I have been working on a printing plug-in called Dark Ink. Some of the printer drivers generate modal dialog boxes, notably fax printers. I can not control every aspect of a printer through code, as each and every printer has different capabilites. It is therfore necessary to show these custom printer dialogs, and then to find a work around to keep the dark basic pro enviroment happy and functioning corectly.

Best Regards,


Jack Taylor

Jack Taylor
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 5th Mar 2008 11:15
Since Win95, i have noticed that the focus does not automatically return to the correct window after modal dialogs. I would start by making a call to SetFocus(DBPro window handle) on return from the dialog.

Login to post a reply

Server time is: 2024-11-23 03:03:56
Your offset time is: 2024-11-23 03:03:56