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.

Dark GDK / Storing a pointer as an integer

Author
Message
Michael P
18
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 28th Nov 2008 15:51
The purpose of this is for writing a plugin for DarkBASIC Pro so that a function can return a pointer as an integer and users can then pass this pointer to other related functions.

Is the following code valid for all systems?
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 28th Nov 2008 22:13
Let me ask if you really mean DarkBasic Pro. This is a DarkGDK forum and the code you're showing is in C++ so I'm not sure what you're trying to do.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 28th Nov 2008 23:02
Quote: "Let me ask if you really mean DarkBasic Pro. This is a DarkGDK forum and the code you're showing is in C++ so I'm not sure what you're trying to do."


Quote: "writing a plugin for DarkBASIC Pro"


Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 29th Nov 2008 02:33
Do you want to pass on what the pointer is pointing to, or do you want to pass on the memory address?

My C++ is a little shaky, but I don't think you can store a hex address in an integer =P Of course, if you are trying to pass on what the address is storing, then yes, it should be simple.

Quote: "so that a function can return a pointer as an integer and users can then pass this pointer to other related functions"


But then, I'm a little confused; are you trying to pass on the Pointer or the Integer?


Tux is my guildmaster.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 29th Nov 2008 04:29
If it's the pointer then I can imagine that it can be returned as an unsigned int. But I would think that it would be safer and, perhaps, more portable to return it as a DWORD type.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 29th Nov 2008 12:07 Edited at: 29th Nov 2008 12:09
It's better to return it as an INT_PTR, that way it's 64-bit-compatible.

Cipher77
15
Years of Service
User Offline
Joined: 17th Nov 2008
Location:
Posted: 30th Nov 2008 01:18
Quote: "It's better to return it as an INT_PTR, that way it's 64-bit-compatible."


long long or long long int is a 64-bit pointer. Microsoft also supports _Int64
Quote: "
so that a function can return a pointer as an integer
"


All pointers are integers. char* float* MyStructure* are all the same type. They are all pointers. The type before * tells the compiler how to dereference it and the size of the object pointed to.

Since, you are casting it anyway to a char* you could easily declare it a void*. Note: void* pointers can point to any type, but you have to cast them before you try to dereference them.

Login to post a reply

Server time is: 2024-09-30 11:21:46
Your offset time is: 2024-09-30 11:21:46