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.

Author
Message
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 29th Oct 2010 17:08
Hi!

This code doesnt't work:


the result is: memory can't be "written".

Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 29th Oct 2010 17:52 Edited at: 29th Oct 2010 17:52
Strings are usually returned with a pointer. You have to create a chunk of memory and use the pointer to that memory.

Something like this:



Cheers!
Sven B

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 2nd Nov 2010 10:20 Edited at: 3rd Nov 2010 09:39
It did not work
len(username$) is 0

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Nov 2010 21:53
It probably didn't work because the 'ptr' parameter is an in/out parameter - you need to set the value pointed-to to the length of the buffer (1024 in this case):


There's also an easier way to get strings from some windows API's - you can pre-size a string and simply pass that string as a parameter:


If you don't have ALLOC ZEROED/FREE then 1) Why don't you have my plug-ins ? 2) Substitute MAKE MEMORY/DELETE MEMORY as per the original snippet.

Finally, there's a WINDOWS USERNAME$ function in my plug-ins that does this for you

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 3rd Nov 2010 09:38
Thanks! Now it works
I wanted to learn to return data from dlls, and now can use your dll. Although, how I must use your dll - just put it in same
folder as program.exe? Will it work on other PCs in that case?

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 3rd Nov 2010 15:12
Follow the link in my sig and read the instructions - the DLL's compile straight into your EXE just like DBPro's own ones do.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet

Login to post a reply

Server time is: 2026-07-26 05:03:55
Your offset time is: 2026-07-26 05:03:55