Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Timeout API function

HI

I've created a class module which can open a connection to a FTP server.
The only problem I have is when the user set an invalid server. Sometime the function OpenConnection returns 0, so I know the server doesn't exists or an error occured and I show a message. (this works)

But, sometime the connection do NOT return anything, it hungs up and I have to restart VB. :SICK:
I read that the TIMEOUT of WinInet doesn't always work at http://support.microsoft.com/kb/176420/en-us.
So, I'm not sure that the function InternetSetOption with flag INTERNET_OPTION_CONNECT_TIMEOUT will work.

How can I stop the execution of the API function OpenConnection if it is not accomplished after some seconds (about 10s)? :confused:
If you have an others ideas to avoid this problem, let me know them.

Maybe using multithreading? But still I need the address of a function that is in a class module.

Sorry for my english, I speak Polish and French and I'm only 16 (Don't look at my age if you submit a hard code :D ).
[1098 byte] By [chrispl] at [2007-11-11 8:27:42]
# 1 Re: Timeout API function
Try this: http://support.microsoft.com/default.aspx?scid=kb;en-us;189850
Phil Weber at 2007-11-11 17:25:28 >
# 2 Re: Timeout API function
Thanks for this link. It can be very useful, but how can I get the address of a private function which is in a class module?
chrispl at 2007-11-11 17:26:28 >
# 3 Re: Timeout API function
You can use VB's AddressOf statement to get the address of a function. I'm not sure, however, if it will work with a Private function; you may have to make the callback function Public.
Phil Weber at 2007-11-11 17:27:26 >
# 4 Re: Timeout API function
The function AddressOf works only for public functions and subs decared in modules.
I need to get the address of a private function which is in a class module.
chrispl at 2007-11-11 17:28:31 >
# 5 Re: Timeout API function
AddressOf is all there is, unless you use a third-party DLL that provides different functionality. You'll likely have to work within its limitations.
Phil Weber at 2007-11-11 17:29:30 >