Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: brew on August 03, 2007, 12:00 AM

Title: Function pointers
Post by: brew on August 03, 2007, 12:00 AM
So uh, I feel kind of embarrased because I'm asking a question about vb6 but eh..
I want to finish up this old project of mine. I require setting a timer using SetTimer, and you know how it requires a function pointer to what it's supposed to call, right? What if I wanted to pass a certain parameter to that function as well, how would i do this? There's no easy way out really. And I can't pass it by a global variable because I'm going to have multiple timers running at once. Does anyone have any good ideas? What i'm basically trying to do is:

        .....
        lngTimer(zxcv) = SetTimer(frmMain.hWnd, 2, lngTime, AddressOf asdfg)
    End If
End Sub
'it would be very nice if i could do AddressOf asdfg(zxcv) or something on that order
'i'm a bit suprised vb6 doesn't have this kind of functionality, considering how dumbed down it is

Public Sub asdfg(sdfg As Integer)
    On Error GoTo Err
    If UBound(qwerty(sdfg).asdf) = 0 Then
        KillTimer frmMain.hWnd, 2
        Exit Sub
    End If
Err:
End Sub
Title: Re: Function pointers
Post by: l2k-Shadow on August 03, 2007, 12:16 AM
http://msdn2.microsoft.com/en-us/library/ms644907.aspx
Title: Re: Function pointers
Post by: brew on August 03, 2007, 08:40 AM
Quote from: l2k-Shadow on August 03, 2007, 12:16 AM
http://msdn2.microsoft.com/en-us/library/ms644907.aspx
Uh, thanks
Title: Re: Function pointers
Post by: UserLoser on August 03, 2007, 05:28 PM
/me thinks brew didn't catch on
Title: Re: Function pointers
Post by: brew on August 03, 2007, 07:18 PM
I did, userloser. The third parameter kind of confused me, because I had it byref (it said UINT_PTR) but apparently it didn't like having a byref parameter and never was called? No idea. But i set it to byval and it worked. hmph, go figure. It works great, by the way.
Title: Re: Function pointers
Post by: MyndFyre on August 05, 2007, 03:46 AM
Quote from: brew on August 03, 2007, 07:18 PM
I did, userloser.
Are you sure?
Quote from: brew on August 03, 2007, 07:18 PMThe third parameter kind of confused me, because I had it byref (it said UINT_PTR) but apparently it didn't like having a byref parameter and never was called? No idea. But i set it to byval and it worked. hmph, go figure. It works great, by the way.

Doesn't look like UINT_PTR is ByRef to me...

Quote
UINT_PTR -- Unsigned INT_PTR.
  This type is declared in BaseTsd.h as follows:

#if defined(_WIN64)
typedef unsigned __int64 UINT_PTR;
#else
typedef unsigned int UINT_PTR;
#endif

Looks like it's a platform-specific data type based on the size of the machine word for the platform.

Reference (http://msdn2.microsoft.com/en-us/library/aa383751.aspx).
Title: Re: Function pointers
Post by: brew on August 06, 2007, 11:32 AM
Quote from: MyndFyre[vL] on August 05, 2007, 03:46 AM
Quote from: brew on August 03, 2007, 07:18 PM
I did, userloser.
Are you sure?
Quote from: brew on August 03, 2007, 07:18 PMThe third parameter kind of confused me, because I had it byref (it said UINT_PTR) but apparently it didn't like having a byref parameter and never was called? No idea. But i set it to byval and it worked. hmph, go figure. It works great, by the way.

Doesn't look like UINT_PTR is ByRef to me...

Quote
UINT_PTR -- Unsigned INT_PTR.
  This type is declared in BaseTsd.h as follows:

#if defined(_WIN64)
typedef unsigned __int64 UINT_PTR;
#else
typedef unsigned int UINT_PTR;
#endif

Looks like it's a platform-specific data type based on the size of the machine word for the platform.

Reference (http://msdn2.microsoft.com/en-us/library/aa383751.aspx).

hrm, maybe so!? see, i love that name, UINT_PTR. It makes you think of it as a pointer, but suprise! it isn't!!!! Honestly, you couldn't blame me for trying to make it ByRef. Anyone uninformed of that typedef would think the same thing, too.

Also, just to show how accurate that refrence page you posted is, here's an example of its quality code:

UINT64 Unsigned INT64.
This type is declared in BaseTsd.h as follows:


Copy Code
typedef usigned __int 64 UINT64;


usigned!? Hrm. must be another typedef or something.
Title: Re: Function pointers
Post by: MyndFyre on August 06, 2007, 10:05 PM
Quote from: brew on August 06, 2007, 11:32 AM
hrm, maybe so!? see, i love that name, UINT_PTR. It makes you think of it as a pointer, but suprise! it isn't!!!!
Not really that surprising.  Windows typically uses notation PTYPENAME (for instance, PINT32, or PUINT32) for pointer types.  If you were familiar with the Windows Data Types reference page, you would have known that.

Quote from: brew on August 06, 2007, 11:32 AM
Honestly, you couldn't blame me for trying to make it ByRef. Anyone uninformed of that typedef would think the same thing, too.
As I stated, all of that information is available on the Windows Data Types reference page.  That makes "anyone uninformed" rather "ignorant," wouldn't you say?  The idea behind the _PTR-nomenclature names is to provide you with data types of size relative to the machine word size.

Quote from: brew on August 06, 2007, 11:32 AM
Also, just to show how accurate that refrence page you posted is, here's an example of its quality code:

usigned!? Hrm. must be another typedef or something.
So you're going to pick on the QA ability of Microsoft on its tens of thousands of pages of material and documentation, but you can't find information on whether a data type should be passed by reference?

I mean, just so everyone's clear.
Title: Re: Function pointers
Post by: brew on August 07, 2007, 10:57 AM
Quote from: MyndFyre[vL] on August 06, 2007, 10:05 PM
Not really that surprising.  Windows typically uses notation PTYPENAME (for instance, PINT32, or PUINT32) for pointer types.  If you were familiar with the Windows Data Types reference page, you would have known that.
Oh wow, that's great that you study microsoft's datatype refrence pages. What about the people who don't?

Quote from: MyndFyre[vL] on August 06, 2007, 10:05 PM
As I stated, all of that information is available on the Windows Data Types reference page.  That makes "anyone uninformed" rather "ignorant," wouldn't you say?
Not really

Quote from: MyndFyre[vL] on August 06, 2007, 10:05 PM
The idea behind the _PTR-nomenclature names is to provide you with data types of size relative to the machine word size.
That idea is such a good idea. Much like most of microsoft's other good ideas (.NET, Windows Me, Vista, XP SP2, help and support center, VC++ 6's IDE, etc.)
Title: Re: Function pointers
Post by: UserLoser on August 07, 2007, 11:16 AM
brew, get a new hobby
Title: Re: Function pointers
Post by: Explicit on August 07, 2007, 01:57 PM
Quote from: brew on August 07, 2007, 10:57 AM
Quote from: MyndFyre[vL] on August 06, 2007, 10:05 PM
Not really that surprising.  Windows typically uses notation PTYPENAME (for instance, PINT32, or PUINT32) for pointer types.  If you were familiar with the Windows Data Types reference page, you would have known that.
Oh wow, that's great that you study microsoft's datatype refrence pages. What about the people who don't?

Quote from: MyndFyre[vL] on August 06, 2007, 10:05 PM
As I stated, all of that information is available on the Windows Data Types reference page.  That makes "anyone uninformed" rather "ignorant," wouldn't you say?
Not really

Quote from: MyndFyre[vL] on August 06, 2007, 10:05 PM
The idea behind the _PTR-nomenclature names is to provide you with data types of size relative to the machine word size.
That idea is such a good idea. Much like most of microsoft's other good ideas (.NET, Windows Me, Vista, XP SP2, help and support center, VC++ 6's IDE, etc.)

Stop typing as if you're a know-it-all, then.  First, you try to correct someone who is obviously more experienced and knows what he's talking about.  Then you try to brush it off and say that it's not your fault that you don't read the datatype references page as much as he does.

Seems to me like you're trying to find any excuse possible to save face just because you overlook small, but imperative details.

Like I told you before: read, read, read, then write.
Title: Re: Function pointers
Post by: Warrior on August 07, 2007, 02:26 PM
Whoa, here I thought brew was finally starting to come around and make something useful of himself.

Silly me.
Title: Re: Function pointers
Post by: brew on August 07, 2007, 07:29 PM
So what, am I supposed to study over MSDN like myndfyre over here?
I don't get what these 3 negative posts in a row are really about...
Title: Re: Function pointers
Post by: l2k-Shadow on August 07, 2007, 08:35 PM
they are over the fact that you try to find faults in everything else but yourself.
Title: Re: Function pointers
Post by: MyndFyre on August 07, 2007, 09:51 PM
Quote from: brew on August 07, 2007, 07:29 PM
So what, am I supposed to study over MSDN like myndfyre over here?
Guess that's why I'm a senior developer with a degree not even a year old that's not in my field making almost double the average salary for someone my age (23), just a year out of school.

But hey, you can continue to make underhanded jabs at me and look like an idiot while you do it.
Title: Re: Function pointers
Post by: Warrior on August 08, 2007, 12:58 AM
Myndy is only second to me on the awesome meters.
Title: Re: Function pointers
Post by: rabbit on August 08, 2007, 09:24 AM
And Warrior is only second to me.  I am the awesomest, too.  There is no one awesomer than me.  Well, okay.  Maybe Ron Jeremy.
Title: Re: Function pointers
Post by: UserLoser on August 08, 2007, 05:11 PM
Quote from: rabbit on August 08, 2007, 09:24 AM
And Warrior is only second to me.  I am the awesomest, too.  There is no one awesomer than me.  Well, okay.  Maybe Ron Jeremy.

Oh wow, Ron Jeremy
Title: Re: Function pointers
Post by: rabbit on August 08, 2007, 07:34 PM
Quote from: UserLoser on August 08, 2007, 05:11 PM
Quote from: rabbit on August 08, 2007, 09:24 AM
And Warrior is only second to me.  I am the awesomest, too.  There is no one awesomer than me.  Well, okay.  Maybe Ron Jeremy.

Oh wow, Ron Jeremy
That's what she said :P
Title: Re: Function pointers
Post by: Explicit on August 17, 2007, 03:44 PM
Quote from: brew on August 07, 2007, 07:29 PM
So what, am I supposed to study over MSDN like myndfyre over here?
I don't get what these 3 negative posts in a row are really about...

You're just being ignorant on your part if you don't read into the details... and by the way, my post wasn't negative.  If anything, I was being constructive.

Some advice: don't ask for help if you're going to dismiss input as irrelevant or incoherent, and actual constructiveness as a personal attack.
Title: Re: Function pointers
Post by: Newby on August 18, 2007, 11:22 AM
Quote from: UserLoser on August 07, 2007, 11:16 AM
brew, get a new hobby

omg I agreed with userloser for once. brew, that means you must really suck.
Title: Re: Function pointers
Post by: warz on August 19, 2007, 02:11 PM
how long have we been telling brew these things? /sigh
Title: Re: Function pointers
Post by: rabbit on August 19, 2007, 02:45 PM
I've been saying this stuff since Day 0.  Jerks.