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 / Get address array for dll

Author
Message
VisualProg
17
Years of Service
User Offline
Joined: 31st Mar 2009
Location: RussianFederation, Smolensk
Posted: 29th Apr 2014 15:32 Edited at: 30th Apr 2014 09:58
Hi all!
IDE: DBPv7.2
Can i do pointer or address on array from DBP to C++? And what be do it?

I would like to just about:


But, this not work... Any manipulation with array item - destroy application.

Help to resolve this!

Sorry for my russglish )

MZђ[NUL]
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 1st May 2014 12:38
If you use Matrix1Utilities you can use get arrayptr(myArray()) from DBPro in order to get the pointer.
The DBPro engine keeps track of all arrays though so doing more with the pointer than changing the elements you already know are there isn't safe.
If you're writing a DLL plugin you can make DBPro automatically give you the pointer if you use the H* letters as parameter type hint in your string table. It seems that DBPro only ever accepts such array pointer conversion if you put it as the first argument of your function however. If you want to resize it, your dll can depend on DBProCore.dll being loaded and thus use LoadLibrary on it and then call the built-in dbEmptyArray, dbInsertArrayElementAtBottom and so forth.

The DBPro arrays contain pointers to their elements so once you have the array of your desired size you can traverse it like so (assuming the array contains DWORD's):

Also remember that you must return the new array pointer from your function, should it have changed (which it may if you resize it). Again only use the built in dbpro functions from DBProCore.dll for creating / resizing / releasing arrays or you'll get crashes when the engine tries to access your freed / can't access your unknown memory.


"Why do programmers get Halloween and Christmas mixed up?"
VisualProg
17
Years of Service
User Offline
Joined: 31st Mar 2009
Location: RussianFederation, Smolensk
Posted: 1st May 2014 13:12
Quote: "Matrix1Utilities you can use get arrayptr(myArray())"

Yes! This is what I need!

Why DWORD? Not enough for him Char? Or DBP can encode Unicode?

In the evening I will try to use Matrix1Utilities. Thank you very much for your help!

MZh[NUL] <--
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 1st May 2014 14:29
Quote: "Why DWORD? Not enough for him Char?"

I just took DWORD for an example. You can use chars, however I believe DBPro internally uses 4-byte alignment for all its variables besides double integers / double floats and strings.

Quote: "Or DBP can encode Unicode?"

No, it uses 1-byte ASCII character values.

If you are going to be modifying string arrays you will also need to call dbCreateDeleteString for creating / releasing DBP strings.


"Why do programmers get Halloween and Christmas mixed up?"
VisualProg
17
Years of Service
User Offline
Joined: 31st Mar 2009
Location: RussianFederation, Smolensk
Posted: 1st May 2014 22:11
Quote: "I just took DWORD for an example."

Ok, I thought it was a String))
Quote: "Matrix1Utilities you can use get arrayptr(myArray())"

Once again I say Thank you! Everything turned out!
Issue has been resolved.

MZh[NUL] <--
VisualProg
17
Years of Service
User Offline
Joined: 31st Mar 2009
Location: RussianFederation, Smolensk
Posted: 1st May 2014 22:13
Quote: "I just took DWORD for an example."

Ok, I thought it was a String))
Quote: "Matrix1Utilities you can use get arrayptr(myArray())"

Once again I say Thank you! Everything turned out!
Issue has been resolved.

MZh[NUL] <--

Login to post a reply

Server time is: 2026-07-07 08:42:20
Your offset time is: 2026-07-07 08:42:20