|
-
September 20th, 1999, 11:54 AM
#1
Pointer to function ....HELP!!!!
Hi:
I would like to load into a structure element a function pointer (callback function). I´m tring it with AddressOf operator but don´t work fine ... What matter?
How can I make it?
Thank for your help.... Bye
-
September 20th, 1999, 11:49 PM
#2
Re: Pointer to function ....HELP!!!!
Addressof works mainly with APIs only. No VB-VB calls, (atleast in VB 5. In 6.0 IDK) . So, how exaclty you are using? provide more info.
RK
-
September 21st, 1999, 01:38 AM
#3
Re: Pointer to function ....HELP!!!!
what do you mean "Addressof doesn't work". It sure does.
Better post your code and error message.
You can use Addressof only for functions that reside in a standard module AFAIK.
-
September 21st, 1999, 03:11 AM
#4
Re: Pointer to function ....HELP!!!!
Hi:
Following is the code which I am tring to load the address function into my structure element (ncb_post).
The error is: Compile error Syntax error.
What is the meaning of standard module AFAIK?
Declare Function Netbios Lib "netapi32.dll" (pncb as NCB) as Byte
public Const NCBNAMSZ = 16 ' absolute length of a net name
public Const NCBDGRECV = &H21 ' NCB RECEIVE DATAGRAM
Type NCB
ncb_command as Integer
ncb_retcode as Integer
ncb_lsn as Integer
ncb_num as Integer
ncb_buffer as string
ncb_length as Integer
ncb_callname as string * NCBNAMSZ
ncb_name as string * NCBNAMSZ
ncb_rto as Integer
ncb_sto as Integer
ncb_post as Long 'address of the routine to call
ncb_lana_num as Integer
ncb_cmd_cplt as Integer
ncb_reserve(10) as Byte ' Reserved, must be 0
ncb_event as Long
End Type
Sub Main()
Dim Est as NCB
Est.ncb_command = NCBDGRECV
Est.ncb_post = AddressOf Respuesta
Ret = Netbios(Est)
End Sub
Function Respuesta(pncb as NCB)
'Here I will write my code
End Function
If I can use only AddressOf into a VB-API, How can I get the address of a function into a VB-VB and after to load it in the structure element?
Thanks for your help
Bye
-
September 21st, 1999, 03:31 AM
#5
Re: Pointer to function ....HELP!!!!
Hi:
Following is the code which I am tring to load the address function into my structure element (ncb_post).
The error is: Compile error Syntax error.
Declare Function Netbios Lib "netapi32.dll" (pncb as NCB) as Byte
public Const NCBDGRECV = &H21 ' NCB RECEIVE DATAGRAM
public Const NCBNAMSZ = 16 ' absolute length of a net name
Type NCB
ncb_command as Integer
ncb_retcode as Integer
ncb_lsn as Integer
ncb_num as Integer
ncb_buffer as string
ncb_length as Integer
ncb_callname as string * NCBNAMSZ
ncb_name as string * NCBNAMSZ
ncb_rto as Integer
ncb_sto as Integer
ncb_post as Long 'Address of the routine to call
ncb_lana_num as Integer
ncb_cmd_cplt as Integer
ncb_reserve(10) as Byte ' Reserved, must be 0
ncb_event as Long
End Type
Sub Main()
Dim Est as NCB
Est.ncb_command = NCBDGRECV
Est.ncb_post = AddressOf Respuesta
Ret = Netbios(Est)
End Sub
Function Respuesta(pncb as NCB)
'I will write my code here
End Function
If I can use only AddressOf into a VB-API, How can I get the address of a function into a VB-VB?
Thanks for your help
Bye
-
September 21st, 1999, 03:39 AM
#6
Re: Pointer to function ....HELP!!!!
this is what the docs say about addressof:
"AddressOf can only be used immediately preceding an argument in an argument list; "
AFAIK = as far as I know
Obviously, I was wrong and Ravi was right.
-
September 21st, 1999, 03:41 AM
#7
Re: Pointer to function ....HELP!!!!
To pass the address of a function to a structure, use a function like this:
Function Get_AddressOf_Function(pfFunction as Long) as Long
Get_AddressOf_Function = pfFunction
End Function
You only need to figure if it has to be ByRef or ByVal, I forgot...
Hope this helps
Crazy D @ Work :-)
-
September 21st, 1999, 03:42 AM
#8
Re: Pointer to function ....HELP!!!!
I'm an idiot! :-)
I wasn't wrong:
Check MSDN - search for AddressOf.
You can assign a function pointer to a variable.
from the docs:
"Function FnPtrToLong (ByVal lngFnPtr As Long) As Long
FnPtrToLong = lngFnPtr
End Function
To use the function, you first declare the type, then call FnPtrToLong. You pass AddressOf plus your callback function name for the second argument.
Dim mt as MyType
mt.MyPtr = FnPtrToLong(AddressOf MyCallBackFunction)
"
-
September 21st, 1999, 04:37 AM
#9
Re: Pointer to function ....HELP!!!!
I think the problem is just plain simple:
Change this line
Est.ncb_post = AddressOf Respuesta
to
Est.ncb_post = AddressOf(Respuesta)
It is the trouble with the function call being called with = and no brackets.
RK
-
September 21st, 1999, 08:30 AM
#10
Re: Pointer to function ....HELP!!!!
Hi Ravi:
I had tried this solution but I received the follow error:
Compile error. Expected expression.
Have you got another idea?
Thanks for your help. Bye...
-
September 21st, 1999, 08:40 AM
#11
Re: Pointer to function ....HELP!!!!
Try what i said in my other post... AddressOf ONLY works when you call a function. It won't work outside the () of calling a function... (oh I still don't know if that function is ByRef or byVal, but the idea of passing the adres of a function to another function, which returns it, i remember that i read that in MSDN a long time ago...)
Crazy D @ Work :-)
-
September 21st, 1999, 08:53 AM
#12
Re: Pointer to function ....HELP!!!!
Hi:
Sorry I don´t understand very well your message.
Where Do I get the pointer to my function into your Get_AddressOf_Function?
I cann´t see clearly your idea.
Thanks for your help. Bye....
-
September 21st, 1999, 09:13 AM
#13
Re: Pointer to function ....HELP!!!!
Call it like this:
Get_Adressof(Adress Of The_Function)
the return value contains the pointer to the function you have to put in the structure you were talking about.
Play with it, it's either ByRef or ByVal (in the function declaration)
I've used it for the callback of the browseforfolders dialog, and it works fine (but I dont have that code here...)
Crazy D @ Work :-)
-
September 21st, 1999, 10:13 AM
#14
Re: Pointer to function ....HELP!!!!
Hi:
I have just tested your solution a work fine.
I find your solution very ingenious. Congratulation for your idea.
Thank for your help. Bye...
-
September 22nd, 1999, 05:41 AM
#15
Re: Ethernet Sniffer Analyzer....HELP!!!!
Hi:
I would not like to disturb with my E-Mail.
I send you this message because I don´t know how can I begin my development and perhaps you know any thing about this subject.
In advance thank for your help and patience.
I would like to develop an Ethernet Sniffer Analyzer and I need fundamentally the information after TCP/IP protocol.
1º) I think that I must to configure my Ethernet card in promiscuous mode. How can I make it?
2º) After configure Ethernet card I must to get the data across the net. How can I make it?
Which are the API functions that I must to use?
3º) For an easiest work, can I use WinSock.ocx for this purpose?
I believe that I can not work with Winsock.ock for this purpose because I need a previous connection but I am not sure....
Thank you very much for your help. Bye...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|