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.

Geek Culture / DLL dynamic memory (C/C++)

Author
Message
Arkheii
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 9th Jun 2004 20:42
I'm making a dll of string parsing/manipulating functions for DBCe. One of the functions I'm trying to emulate is the VB Left$(string$,n) function (Which returns the first n characters of the string string$). The problem is, the compiler doesn't like using a variable when defining (defining, declaring, whatever...) a char (it demands a constant, ie. 'char buffer[128]' but not 'char buffer[n]'), so I'm forced to use dynamic memory. However, I still have to delete that allocated memory, but I still have to return that string buffer. Is it alright if I do not delete that allocated memory using delete [] buffer or is there another way to return a char of variable size?

Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 9th Jun 2004 20:59
well erm not to put a chrimp in your plans but; why exactly are you trying to make functions that already exist in DarkBASIC and DarkBASIC Enhanced?

well anyways why not simply delete what you allocate in the DLL_PROCESS_DETACH?

also you a Pointer based string like LPSTR; this is the common meathod for passing strings back'n'forth in languages as your simply passing the pointer address not the actual memory allocation.



this way you can them simply create the string on the fly;



or ya know something like that

Arkheii
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 9th Jun 2004 21:02
It exists?

*checks help file*

Doh, must've missed it before because I only saw Mid$()... Thanks for the extra info, I'll also take note of that. Might come in handy next time.

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 9th Jun 2004 21:28 Edited at: 9th Jun 2004 21:29
dbp mid is a joke, as are a lot of the commands regarding strings and file functions etc (sorry to say)

if you want real string functions as well as a whole slew of other useful stuff check out our plugin by clicking image below

thanks


* DBP_NETLIB_v1.2 - NOW WITH VARIABLE WATCHER! * Click Logo
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 9th Jun 2004 21:31
I've also got a proper MID$ command, as well as search string, and rotate string left and right.


The place for wonderful plug-ins and things.
Keep your friends close, and your cats even closer.
Arkheii
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 9th Jun 2004 21:38 Edited at: 9th Jun 2004 21:40
lol, great way to advertise plugins.

I'm not using pro, what's wrong pro's mid command and the other functions?

edit: CR, does your netlib work with enhanced?

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 9th Jun 2004 21:55 Edited at: 9th Jun 2004 21:57
I don't know, I don't think anyone with dbce has tried it

dbp's string and file functions are clunky compared to what I am used to with vb/vb.net so I made a dll (along with Exeat) to make my life easier (and anyone else who wants to use it)

it has a variable watcher too


* DBP_NETLIB_v1.2 - NOW WITH VARIABLE WATCHER! * Click Logo
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Jun 2004 22:37
Your plug-in won't work with DBC - it uses a completely different string system to DBPro.

@arkheii,
The pointer that you pass back to DBC does not transfer ownership of the memory that you've allocated - it still belongs to your DLL and can be re-used by you the next time. You simply pass the pointer to DBC so that it can make a copy of the contents.

This example uses an equivalent of the SPACE$() function to show what I mean.



You simply don't need to get into dynamically allocated memory

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
Arkheii
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 10th Jun 2004 06:40
Thanks for the info about maximum string length. So I can just pass the pointer to DBC and it picks out the null terminated string for me... Thanks!

*bows to gods of DLLs*
*bow*
*bow*
*bow*

Login to post a reply

Server time is: 2024-11-25 09:34:09
Your offset time is: 2024-11-25 09:34:09