Fighting with pointers

Started by
4 comments, last by zix99 19 years, 4 months ago
Hi all I'm having some trouble with pointers, and it's annoying the heck out of me. I'm creating a DLL in C++ and then using the calls in VB. This is a small example to return the random value of 54, for vb to put in a textbox. Working Code:

int ReturnValue(){
return 54;
}



Returns the memory address:

int ReturnValue(){
int ret=54;
return ret;
}



Call from VB:

public declare function ReturnValue lib "test.dll"() as long
sub Main()
Msgbox ReturnValue
end sub
This has been bugging me for a day now, so i would appreciate any help you could give (possibly alternate methods) Thanks ~zix~ EDIT: hate UBB
---------------------------------------------------Game Programming Resources, Tutorials, and Multimedia | Free Skyboxes
Advertisement
Your two code samples are equivalent. In both cases you are returning a value (int) not an address (and returning the address of a local variable is a bad idea anyway).
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
They are equivilent, yes, but the second one doesnt work.

Can you see why it's bothering me?

~zix~

EDIT: I know it's an address because it returns a somewhat random number each time... in the millions.
---------------------------------------------------Game Programming Resources, Tutorials, and Multimedia | Free Skyboxes
how is the second one not working? are you expecting it to be a pointer, which it is most certainly not? and just for clarity, at no point in either of those functions are you doing anything with pointers. please post the code you are using to test those functions, that is most likely where the error lies.

-me
Maybe i'm just being stupid...
I think it is my code not the pointers, one sec, let me see if i can find the problem
---------------------------------------------------Game Programming Resources, Tutorials, and Multimedia | Free Skyboxes
It was my stupid mistake, but thanks for trying to help...

It was here:
ret+=(ny*ZoneWidth+x)*MAXOBJ;
and it's suppose to be
ret+=(ny*ZoneWidth+nx)*MAXOBJ;

(Not that that means anything to you guys)

Thanks anyway
~zix~
---------------------------------------------------Game Programming Resources, Tutorials, and Multimedia | Free Skyboxes

This topic is closed to new replies.

Advertisement