I have a (black box) DLL -- non-COM -- which I am using in a VB project. The function I'm using is declared at the top of the file it's used in similarly:
In the function which calls the DLL, the code goes like this:
Now, here's the weird thing:
If I run the function in Debug mode, even without any breakpoints, the first call succeeds. In compiled form the behavior is stranger: the first call to MyFunction fails. If I immediately call it again the second one fails as well. If I leave the Sleep 1500 in there the second call succeeds.
I'd really rather not have the Sleep statement in there, as this function may be called multiple times, and adding at least a 1.5 second delay to each call is bad form. Can anyone tell me why the first call fails, and how to fix it?
code:<HR>Code:Private Declare Function MyFunction Lib "thedll.dll" _ (ByVal lpszPath As String, ByVal lpszUsername As String, _ ByVal lpszPassword As String, ByVal lpszServer As String) As Long
In the function which calls the DLL, the code goes like this:
The lstr* variables are all local fixed-length string variables. The path to thedll.dll is correct. thedll.dll is not in the system path or the process path, but even if I add it the problem persists. MyFunction returns 0 on failure and 1 on success.code:<HR>Code:Dim curLocation As String curLocation = CurDir ChDir strPathToTheDLL DoEvents lngReturnCode = MyFunction(lstrPath, lstrUsername, lstrPassword, lstrServer) Sleep 1500 If lngReturnCode = 0 Then lngReturnCode = MyFunction(lstrPath, lstrUsername, lstrPassword, lstrServer) End If<P> DoEvents ChDir curLocation
Now, here's the weird thing:
If I run the function in Debug mode, even without any breakpoints, the first call succeeds. In compiled form the behavior is stranger: the first call to MyFunction fails. If I immediately call it again the second one fails as well. If I leave the Sleep 1500 in there the second call succeeds.
I'd really rather not have the Sleep statement in there, as this function may be called multiple times, and adding at least a 1.5 second delay to each call is bad form. Can anyone tell me why the first call fails, and how to fix it?
project\thedll.dll"); use the short 8.3 name just to be sure.