Author |
Message |
Frank Ad #1 / 25
|
 Function pointers ?
Hi guys, Is there a trick or workaround to assigning a function pointer to a long ? Regards, Frank.
|
Sat, 31 Jan 2004 12:50:15 GMT |
|
 |
Jakob Bielin #2 / 25
|
 Function pointers ?
Quote: > Is there a trick or workaround to assigning a function pointer to a > long ?
cast it void f(void) { Quote: }
.. long lpF = (long) f ; regards, jb
|
Sat, 31 Jan 2004 15:35:53 GMT |
|
 |
Yaniv Sapi #3 / 25
|
 Function pointers ?
Quote:
> > Is there a trick or workaround to assigning a function pointer to a > > long ? > cast it > void f(void) > { > } > .. > long lpF = (long) f ; > regards, > jb
??? VB, to remind you...
|
Sat, 31 Jan 2004 16:27:56 GMT |
|
 |
Frank Ad #4 / 25
|
 Function pointers ?
On Tue, 14 Aug 2001 09:35:53 +0200, "Jakob Bieling"
Thanks for the reply.. I tried, but it keeps saying Syntax Error. So i've followed on with your advice and poured plaster in the keyboard, the box and now on the screen, i'm typing blind actually as we speak.. But i can still hear the messagebox sounding as it says Syntax Error... please tell me what am i doing wrong ? Do i have to wait for the plaster to set properly ? Is there an OCX or API call that can dry it more efficiently ? Actually i'm not sure if it is properly registered yet, i'll dab on it a bit more..where do i find plstsrv32.exe ? I need a drink.. :) Quote: >> Is there a trick or workaround to assigning a function pointer to a >> long ? >cast it >void f(void) >{ >} >.. >long lpF = (long) f ; >regards, >jb
Regards, Frank.
|
Sat, 31 Jan 2004 16:52:36 GMT |
|
 |
Jakob Bielin #5 / 25
|
 Function pointers ?
Quote: > ??? > VB, to remind you...
oh, oops, sorry, um... bye :) jb
|
Sat, 31 Jan 2004 17:04:20 GMT |
|
 |
Dag Sund #6 / 25
|
 Function pointers ?
AddressOf(), but that only work for global Subs/functions residing in a .BAS module. Dag.
Quote: > On Tue, 14 Aug 2001 09:35:53 +0200, "Jakob Bieling"
> Thanks for the reply.. > I tried, but it keeps saying Syntax Error. So i've followed on with > your advice and poured plaster in the keyboard, the box and now on the > screen, i'm typing blind actually as we speak.. > But i can still hear the messagebox sounding as it says Syntax > Error... please tell me what am i doing wrong ? > Do i have to wait for the plaster to set properly ? > Is there an OCX or API call that can dry it more efficiently ? > Actually i'm not sure if it is properly registered yet, i'll dab on it > a bit more..where do i find plstsrv32.exe ? > I need a drink.. :) > >> Is there a trick or workaround to assigning a function pointer to a > >> long ? > >cast it > >void f(void) > >{ > >} > >.. > >long lpF = (long) f ; > >regards, > >jb > Regards, Frank.
|
Sat, 31 Jan 2004 17:16:22 GMT |
|
 |
Jakob Bielin #7 / 25
|
 Function pointers ?
Quote: > Thanks for the reply.. > I tried, but it keeps saying Syntax Error. So i've followed on with > your advice and poured plaster in the keyboard, the box and now on the > screen, i'm typing blind actually as we speak.. > But i can still hear the messagebox sounding as it says Syntax > Error... please tell me what am i doing wrong ? > Do i have to wait for the plaster to set properly ? > Is there an OCX or API call that can dry it more efficiently ? > Actually i'm not sure if it is properly registered yet, i'll dab on it > a bit more..where do i find plstsrv32.exe ? > I need a drink.. :)
hehe, now that i am aware of the fact that i am posting to a VB newsgroup, here my second try: to pass the pointer of a function to, for example, a Win32 API function, you do: Call SomeWin32APIFunc (param1, param2, AddressOf Func, param4, param5) unfortunately, there is no way in VB to store a function pointer, since you cannot assign "AddressOf Func" to a variable. but in VB, it is of no use anyway, because you can not call a VB function by its pointer. mh, sorry for the first "unclear" post :) bye jb
|
Sat, 31 Jan 2004 17:15:35 GMT |
|
 |
Jakob Bielin #8 / 25
|
 Function pointers ?
Quote: > Is there an OCX or API call that can dry it more efficiently ?
oh, i just thought of another solution: write a dll in C or C++ that contains one function. this function will accept a pointer to a function and return a long. all it does it return the function pointer converted to a long. so you call the func with the function as argument you want to pointer to and it will return the long value of that pointer. not sure if you want to do this, tho :) regards, jb
|
Sat, 31 Jan 2004 17:20:53 GMT |
|
 |
Frank Ad #9 / 25
|
 Function pointers ?
On Tue, 14 Aug 2001 11:20:53 +0200, "Jakob Bieling"
Having got my drink and dinner served, i'm feeling much better now. :-) Quote: >> Is there an OCX or API call that can dry it more efficiently ? >oh, i just thought of another solution: >write a dll in C or C++ that contains one function. this function will accept a pointer to >a function and return a long. all it does it return the function pointer converted to a
Yeah, i was trying to avoid doing that. I really wanted to assign it straight to a long though. For once, i actualy have come across a use for a function pointer as such in VB. Now it's niggling me, i want to use it and see if i can crash things. Thanks again. :) Regards, Frank.
|
Sat, 31 Jan 2004 17:58:14 GMT |
|
 |
Jakob Bielin #10 / 25
|
 Function pointers ?
Quote: > Yeah, i was trying to avoid doing that. I really wanted to assign it > straight to a long though. For once, i actualy have come across a use > for a function pointer as such in VB. Now it's niggling me, i want to > use it and see if i can crash things. > Thanks again. :)
np, but how and where are you going to use a function pointer? just curious :) oh, and btw, crashing things is not that hard.. just get the API declaration of CopyMemory and play with that. you'll be amazed at how easy crashing things is :)))) regards jb
|
Sat, 31 Jan 2004 18:10:32 GMT |
|
 |
Frank Ad #11 / 25
|
 Function pointers ?
On Tue, 14 Aug 2001 12:10:32 +0200, "Jakob Bieling" Quote:
>np, but how and where are you going to use a function pointer? just curious :)
Someone was talking about how the CommonDialog mixes up selected filenames and returns them in a different order. Sort of got me interested, i looked and it certainly does just that. With the API GetSaveFilename() you can set a callback function to receive mouseclicks. I've never even used it's callback method in C, so i'm trying to see what it does. The problem is that the function name is passed in via one of the OPENFILENAME structure's member. Then the whole struct is passed in the call. VB simply won't let me set that member though. And i've tried some {*filter*} ways :) Quote: >oh, and btw, crashing things is not that hard.. just get the API declaration of >CopyMemory and play with that. you'll be amazed at how easy crashing things is :))))
Hehe, i'll just boot into DOS and fire up TurboC 1.5. I used to laugh back in the Fidonet days when someone asked how to reboot the system, as i had so many wonderful routines to do just that. They were mostly called "myfirstPtr.exe, myfirstTsr.exe or something.. :-) I feel sorry for kids today. They miss out on all that fun. And then there is Larry, but shoving coal into a PC instead of plugging it in is a bit too much work, even for me. ;-) Regards, Frank.
|
Sat, 31 Jan 2004 18:52:27 GMT |
|
 |
Paul Marshal #12 / 25
|
 Function pointers ?
Hi Frank, ? The problem is that the function ? name is passed in via one of the OPENFILENAME structure's member. ? Then the whole struct is passed in the call. VB simply won't let me ? set that member though. And i've tried some {*filter*} ways :) Here's an easy way to do it. This function will accept the address of a procedure in a .bas module and return it: Public Function FuncPtr(ptr As Long) As Long FuncPtr = ptr End Function When setting up your structure do this: YourUDT.lpFunc = FuncPtr(AddressOf YourCallbackProc) -- Paul Marshall
|
Sat, 31 Jan 2004 19:52:20 GMT |
|
 |
Frank Ad #13 / 25
|
 Function pointers ?
On Tue, 14 Aug 2001 06:52:20 -0500, Paul Marshall
Doooh ! Thanks Paul. :-) Ps: You could have made it look a bit more complicated, so i wouldn't look so stupid. :-) Quote: >Here's an easy way to do it. This function will accept the address of a >procedure in a .bas module and return it: >Public Function FuncPtr(ptr As Long) As Long > FuncPtr = ptr >End Function >When setting up your structure do this: > YourUDT.lpFunc = FuncPtr(AddressOf YourCallbackProc) >-- >Paul Marshall
Regards, Frank.
|
Sat, 31 Jan 2004 20:06:06 GMT |
|
 |
tcarv #14 / 25
|
 Function pointers ?
Try this... Public Sub TargetFuncInBas() '... End Sub Public Function PtrToFunc(ByVal pFunc As Long) As Long PtrToFunc = pFunc End Function Public Sub Main() Dim pFunc As Long pFunc = PtrToFunc(AddressOf TargetFuncInBas) MsgBox "Address Is " & CStr(pFunc) End Sub HTH, Tom Quote:
> Hi guys, > Is there a trick or workaround to assigning a function pointer to a > long ? > Regards, Frank.
|
Sat, 31 Jan 2004 20:49:56 GMT |
|
 |
Jakob Bielin #15 / 25
|
 Function pointers ?
Quote:
> Hi Frank, > > The problem is that the function > > name is passed in via one of the OPENFILENAME structure's member. > > Then the whole struct is passed in the call. VB simply won't let me > > set that member though. And i've tried some {*filter*} ways :) > Here's an easy way to do it. This function will accept the address of a > procedure in a .bas module and return it: > Public Function FuncPtr(ptr As Long) As Long > FuncPtr = ptr > End Function > When setting up your structure do this: > YourUDT.lpFunc = FuncPtr(AddressOf YourCallbackProc) > -- > Paul Marshall
doh, thats makes me go "hey, why did i not think of this before?" hehe regards, jb
|
Sat, 31 Jan 2004 21:17:56 GMT |
|
|
Page 1 of 2
|
[ 25 post ] |
|
Go to page:
[1]
[2] |
|