Int pointer? Byte pointer?

Community Forums/General Help/Int pointer? Byte pointer?

sswift(Posted 2009) [#1]
Can anyone tell me what type of pointer I need to use for this windows function declaration:

http://msdn.microsoft.com/en-us/library/ms645600%28VS.85%29.aspx

BOOL RegisterRawInputDevices(
PCRAWINPUTDEVICE pRawInputDevices,
UINT uiNumDevices,
UINT cbSize
);

I think it may be a byte pointer, as another function that uses an int pointer in user32.bmx has the letters lp before it. But there are also short pointers and I can't figure out what the naming method is for those.



Also, why do most of the win32 delared function look normal, but some look like this:

Function GetParent_(hwnd)="GetParent@4"

What determines if you need that bit on the end? Is it perhaps the name of the function being different from the actual function name? It seems that way. But why do you then have to calculate the number of bytes passed to the function? And what if there's a return value, does that get counted somehow?


And god I love Microsoft...

What size is a variable of type BOOL?

http://msdn.microsoft.com/en-us/library/tf4dy80a.aspx

This page indicates that BOOL could be an int or a byte. It depends on what version of their compiler a DLL was compiled with. So how am I supposed to know what version user32.dll was compiled with, and what if they ever change it?


[edit]

BOOL is two bytes http://blogs.msdn.com/oldnewthing/archive/2004/12/22/329884.aspx

No wait, BOOL is four bytes: http://support.microsoft.com/kb/199315

No it's one byte: http://bytes.com/groups/net-c/256480-bool-32-bit-integer

ARGH!

[/edit]


sswift(Posted 2009) [#2]
Hm.. that last link says:
"As the windows BOOL is defined as: typedef int BOOL; in WINDEF.H"

So maybe it's an int. MAYBE.


Dabhand(Posted 2009) [#3]

What size is a variable of type BOOL?



sizeof() is your friend.

http://www.cppreference.com/wiki/keywords/sizeof

Dabz


sswift(Posted 2009) [#4]
Um... yeah, I suppose, if I had C++, SizeOf would help me determine the size of a particular windows variable type. But I don't.


Dabhand(Posted 2009) [#5]
Well, lets be fair... You havent actually stated what your using, I just hazarded a guess since...

A) There are actually BlitzMax help forums, which you havent posted this in and..

B) You can plonk C++ into your BlitzMax projects, so actually, you do do have C++ available.

;)

Dabz


markcw(Posted 2009) [#6]
Treat BOOL as Int.


Dabhand(Posted 2009) [#7]
Import "test.cpp"

Rem contents of TEST.CPP
extern "C" int SizeOfBool()
{
	return(sizeof(true));
}
End Rem

Extern
	Function SizeOfBool:Int()
EndExtern

Print SizeOfBool()


Which prints the size of 'true' as 1

If you use an int:-

Import "test.cpp"

Rem contents of TEST.CPP
extern "C" int SizeOfInt()
{
        int parp;
	return(sizeof(parp));
}
End Rem

Extern
	Function SizeOfInt:Int()
EndExtern

Print SizeOfInt()


It returns 4

Dabz


sswift(Posted 2009) [#8]
See you guys can't even agree with eachother. :-)


sswift(Posted 2009) [#9]
Also, a bool taking up 1 byte disagrees with the official documentation, assuming this is in fact the official documentation:

This says it's defined in Windef.h:
http://bytes.com/groups/net-c/256480-bool-32-bit-integer

This is supposedly windef.h:
http://doc.ddart.net/msdn/header/include/windef.h.html

Of course, now I don't know what INT is supposed to even be, because 4 bytes implies it's a long, but I would have thought it would be a short and most ints windows functions take seems to be shorts.

Ugh.


sswift(Posted 2009) [#10]
Well this seems to be the official word. I don't know why this article didn't come up when I searched MSDN for "BOOL".

Here it is defined as an INT:
http://msdn.microsoft.com/en-us/library/aa383751%28VS.85%29.aspx

And an INT is defined as having 32 bits.


But if that's the case, why does your code say it's a byte?


sswift(Posted 2009) [#11]
Building ctest
Compiling:test.cpp
Build Error: failed to compile C:/Program Files/BlitzMax/myprojects/test.cpp
Process complete

You can plonk C++ into your BlitzMax projects, so actually, you do do have C++ available.


BZZT! wrong. :-)


There are actually BlitzMax help forums, which you havent posted this in and.


The original question was more of a windows specific question than a blitzmax specific question.


Orca(Posted 2009) [#12]
Granted I don't do c/c++, but in general, with win32 I would assume most typedefs resolve to signed 32 bits.

( but then again im drunk beyond allr reeasoning )

no joke

:D

War 4th of july


Ian Thompson(Posted 2009) [#13]
Max expects a Bool to be 4 bytes when passed from a C DLL. The exact size of the Bool is set by the C compiler options, so it has to be set to 4 as Max does not allow the same flexibility. No long INTs in Max, there all signed but a signed INT will hold a long INT value for passing information back and forth to a DLL as long as you dont try any INT comparison/maths as the sign could be random depending on the returned value. But for a place to put some long INTs temporarily Max's signed types work fine.


sswift(Posted 2009) [#14]
Treat BOOL as Int.


That seems like the wisest course of action at the moment.

But I still need to know how to treat the pointer to that array.


Dabhand(Posted 2009) [#15]

BZZT! wrong. :-)



Okay, you need MinGW installed... Lets just say I'm half-right then! ;)

And I still didnt know what you were using! :P Hehehe


The original question was more of a windows specific question than a blitzmax specific question.



http://www.blitzbasic.com/Community/topics.php?forum=108

:P

Anyhoo, pleased you sorted it! ;)

Dabz


_JIM(Posted 2009) [#16]
It was clear it was an Int if it was defined like that in WINDEF.h.

The problem with Dabhands example is that he uses "true" which gets converted to "bool" which is different than "BOOL" which is 4 bytes :)


sswift(Posted 2009) [#17]


I didn't even know that forum existed.


markcw(Posted 2009) [#18]
Function GetParent_(hwnd)="GetParent@4"

What determines if you need that bit on the end? ...

This is actually explained very well in the Blitz3D DLL spec file here which says this.

VisualC decorates symbols quite heavily! If you are coding in 'C', the necessary stdcall specifier will cause a '_' to be prepended, and a '@' (followed by the number of bytes passed to the function - ie: number of parameters*4) to be appended. So, something like: 'void _stdcall MyFunc( int x )' will end up as '_MyFunc@4'. In C++, the name decoration is even messier! But you can supress it by using the 'extern "C"' feature (see examples below) so you're just left with the 'C' stdcall mess.

Other languages such as Delphi and Purebasic don't appear to suffer from this feature, but it can be worthwhile looking through dll symbols if you're having problems. Check out PEview at http://www.magma.ca/~wjr Open your dll and select 'SECTION .rdata'/'EXPORT address table' to have a look at the exported symbols your compiler has seen fit to bestow upon your dll.



sswift(Posted 2009) [#19]
Mark:
That tells me what @4 is, the number of bytes passed, but it doesn't explain why most of the extern function declarations don't have something like ="GetParent@4" appended, but a few do.


sswift(Posted 2009) [#20]
But anyway... forget that. I don't care about that right now. Or the boolean thing. I'll assume boolean is an int and I don't need that equals thing on my function.

What I really need to know now is the answer to my original question:
http://msdn.microsoft.com/en-us/library/ms645600%28VS.85%29.aspx

Should I use an int pointer or a byte pointer for that array that has to be passed to that function?


sswift(Posted 2009) [#21]
I posted the code I'm working on in the Win32 forum:
http://blitzmax.com/Community/posts.php?topic=85589

The code's almost to the point where it'll work, but there's still several windows related things that I need help porting over.

The code is for reading raw mouse data.


sswift(Posted 2009) [#22]
So, correct me if I'm wrong, but I think this is how Mark decided on the type of pointer to specify in user32.bmx.

Apparently, the pointer type doesn't matter. It's a long pointer, the LP prefix tells us this, and on 32 bit systems all pointers are long pointers.

The type however Mark simply chose to make the data as easy as possible to access in BlitzMax. So he chose Int for pointers to structs like this:
http://msdn.microsoft.com/en-us/library/ms912843.aspx

Where all fields are long.

But he chose byte for pointers to structs like this:
http://msdn.microsoft.com/en-us/library/dd162768%28VS.85%29.aspx

Where the fields are all different types of variable.

Actually, I'm not really sure that declaring a pointer to be one type or another makes anything easier or not becuase I haven't used pointers much in BlitzMax. But that's the only reason I can see that he might have done it that way.


Dabhand(Posted 2009) [#23]

The problem with Dabhands example is that he uses "true" which gets converted to "bool" which is different than "BOOL" which is 4 bytes :)



#include <windows.h>

extern "C" int SizeOfBool()
{
	BOOL parp;
	return(sizeof(parp));   //Does indeed return 4
}


If I'm honest, I never realised that, I just took it on face value that bool and BOOL were one and the same. :)

I never really check sizes manually, if a function wants to know the size of something, like a structure, I just pass the instance to sizeof() and forget about it!

Me bad! ;)

Dabz


markcw(Posted 2009) [#24]
Read the C for Blitzers tutorial by Otus (found here http://www.blitzmax.com/logs/userlog.php?user=8652&log=1737) it covers pointers in BMax much better than the docs.


sswift(Posted 2009) [#25]
Note the case! [...] in C case matters.


Ah, yet another reminder of why I hate C. :-)

PS:
I now have TWENTY tabs open just to cross reference all the crap I need to know in order to just read raw mouse data events in Windows.

WTF.


big10p(Posted 2009) [#26]
Why is case sensitivity for idiots?


sswift(Posted 2009) [#27]
Why isn't it?

What kind of lunatic would want two variables or functions named the same thing, differing only in case? It's absurd.

The only argument you could possibly make for it is if you NEVER use it for that purpouse and instead use it only as an additional layer of protection against typos. Or I guess, as a way to force people to format their variable names in a readable manner.

But you know if you give people that power they will use it only for evil and have function Bob() function BOB() and function bob().