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.

DarkBASIC Professional Discussion / DarkBASIC TPC dev: string return values

Author
Message
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 17th Jun 2003 21:07
I have a very strange problem,

I have a function which needs to return a string to DBP which comes from an internal Delphi object (The caption of an edit box), if I set the return type in the DLL's stringlist to integer, I can "read" this value in the DLL's function.

Eg:

ShowMessage(EditBox1.Caption);

Works fine and shows a message box with the caption in.

However, if I set the return type to STRING (S) in the DLL's stringlist, I cannot read the EditBox1.Caption from inside the DLL's function, I just get a nul string.

ShowMessage(EditBox1.Caption);

Shows an empty message box.

The DLL is written in Delphi, does anyone know if DBP does anything different to the stack or something when expecting a string return value rather than an integer return value?
Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_103.zip
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 17th Jun 2003 21:11
i dunno howto do it in Delphi, but there is no doubt an equivilant someone knows




Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Jun 2003 21:30
Raven, that works great for old-style DLLs, but you have a bit more to do for strings in TPC DLLs.

Rob, the Caption property is not a C-style string - it's a class, so you can't return the string value like that. You need to extract the string data somehow. Even then, you can't just return the string pointer - give me a few hours and I'll work out what you need to do.
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 17th Jun 2003 21:59
Thanks - I would would be really grateful

An alternative would be EM_GETLINE and SendMessage, I couldn't get it to work, but I assume it is possible. Anyhow, being able to do this would have many uses, and it isn't just edit boxes then, combo boxes and list items all work in the same way presumably.

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_103.zip
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Jun 2003 00:18
Here's the code with all the correct string handling. Have a look and see if it does what you want.

Here's the resource file:



One thing to notice is that if you are returning a string, the first argument is the string that you are replacing, followed by all the arguments that you specify.
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 18th Jun 2003 03:45
bleck!... i think that source is a good example to why i don't like Pascal, such a messy language lol

I pride myself that i don't kill...
well not without a good reason
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 18th Jun 2003 13:51 Edited at: 18th Jun 2003 13:53
The neatness of the code depends on the programmer usually, not the language.

Thanks for the help IanM, I'll try it when I get home tonight

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_103.zip
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Jun 2003 15:16
No probs Rob.

I was amazed at how much I forgot after a few weeks of not using Delphi ... and how much came back when I jumped in the deep end

It looks cluttered to me too, but thats because I'm a C++ coder. All those extra words make the code look denser than I'm used to.
n3t3r453r
23
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Russia
Posted: 18th Jun 2003 16:43
I thought that you just need to:
1) declare function as DWORD
2) say function in string table to return string "S"
3) simply return (DWORD)&str (there "str" was declared as char array)

I'd like to change the world, but God doesn't want to give me sources!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Jun 2003 17:17
That's true for all types that you return, *except* for strings.

You have to 'play nice' with the BASIC runtime, which means using the runtime memory allocation routines for strings to both allocate new memory and return unwanted memory.
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 18th Jun 2003 21:00 Edited at: 18th Jun 2003 21:02
Just found out something which was another reason why it did not work, when specifying integer parameters, use the LongInt type in the Delphi DLL, I was trying to use Integer.

Thanks Ian, this forum needs the worship smilie (I can probably find one on Toady's site )

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_103.zip
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 18th Jun 2003 21:26
No, there's only me on my site...
... I dont mind being worship though...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Jun 2003 22:08
As long as no-one shows me that picture from your site, I'll be OK

Rob, I'm confused now. According to the Delphi help, Integer and LongInt have exactly the same ranges.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Jun 2003 23:29
Git!
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 18th Jun 2003 23:48
To whom is your three letter message directed at ??

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Jun 2003 23:53 Edited at: 18th Jun 2003 23:53
I typed it in a moment of madness

Ooh look. For some reason your site seems to be blocked for me - You look much better as a broken link ... quite appropriate
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 19th Jun 2003 00:16
First off, you can try my site again... Secondly, at least I'm not the missing link.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 19th Jun 2003 00:56
IanM, I cannot explain it either, but it definately makes a difference.

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_103.zip
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Jun 2003 01:53
Rob, I'll take your word for it and remember the next time I delve into Delphi.

Nick, it could have something to do with your site having an IP address of 127.0.0.1 in my host file ...
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 19th Jun 2003 02:13
Maybe it is a compiler bug in Delphi or something?

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_103.zip
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 19th Jun 2003 11:01
Why would my site have a local IP address in your host file ? Dont you like my site !?

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 19th Jun 2003 19:55
I don't believe this!

If I specify S (for string) as the return type eg: [%SL in the string table, I cannot read any of the integer parameters sent to the program, when I do try and access them inside the DLL, I get the values of the result of the function (a pointer to a C-String). However when I set L (for integer) as the return type eg: [%LL in the string table, I CAN read the integer parameters sent to the function.

Does anyone know what on earth is going on?

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_103.zip
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Jun 2003 20:02
Quote: "One thing to notice is that if you are returning a string, the first argument is the string that you are replacing, followed by all the arguments that you specify"


For '[%SL', you need to define your function like this:

function MyFunc(OldString : PChar, OtherArg : LongInt) : PChar; cdecl;
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 19th Jun 2003 20:16 Edited at: 19th Jun 2003 20:18
Thanks - I found out that the parameter was out by four bytes which makes sense given this.

Finally I can get into more interesting aspects of the development.

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_103.zip
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 19th Jun 2003 21:46 Edited at: 19th Jun 2003 21:48
Here is a pic from a test project using the GUI DLL if anyone wonders what this is all in aid of:



There will be list boxes, progress bars and all sorts of other GUI gadgets in addition to what is in this screenie.

The command system has been shamelessly nicked off Blitz' Gadget system (except that you have IDs instead of handles)

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_103.zip

Login to post a reply

Server time is: 2026-07-11 14:56:37
Your offset time is: 2026-07-11 14:56:37