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 / Using arrays in a DLL

Author
Message
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th May 2013 07:24
I'm working on a new plugin but I don't know how to manage the objects it creates.

For example, say I had a command in DB called MakeObject() which in the C++ code would create a new object(based on whatever parameters) and add it to an array, returning the index number to user for reference with other functions. Like how AppGameKit works when you load an image or create a sprite.

How would I go about initializing an array and managing it among the DLL's functions? Since I'm not operating from a main method from within a class, I'm not sure how this works.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 4th May 2013 19:40
Assuming these numbers are supposed to be independent from any existing DBPro ID set, it depends what range of IDs you want to be valid.

If you only need a very small set of IDs (say 32) you can just make a static fixed-size array. If you need a large range of IDs you might consider using a std::map, or std::unordered_map so that you don't waste space for IDs that are not in use. Another alternative is a std::vector that you expand as needed, but obviously if IDs are not contiguous you could end up wasting quite a bit of space.

For initialization, you could have an initialization function that you call at the start of each command which checks if it has already been called and in that case just returns. Alternatively DBPro will check for an exported function named "Constructor" which it will call if it exists.

[b]
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th May 2013 19:51
Thanks, i think thats what I needed to know. So this function is literally called constructor and needs to be in the string table?

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 5th May 2013 09:50 Edited at: 5th May 2013 09:50
I think it's "Constructor" with a capital C but you might want to search the forums a bit, there are a few threads that document it better.

It shouldn't be in the string table, it should be a normal __cdecl function exported from the DLL. If you're using VC++ the name mangling will be correct (don't use extern "C" as that disables name mangling).

If you're using some other compiler you need to use a .def file to get the name right.

[b]
Davinho4
10
Years of Service
User Offline
Joined: 3rd Jul 2013
Location:
Posted: 3rd Jul 2013 11:28
So this function is literally called constructor and needs to be in the string table?

buy dvd uk: http://www.ohyeahdvd.co.uk

Login to post a reply

Server time is: 2024-03-28 21:13:38
Your offset time is: 2024-03-28 21:13:38