Page 1 of 1

DllCall Produces Strange Error Code

Posted: 02 Jan 2020, 06:46
by 1100++
In order to use C++ code within AutoHotkey, I've been writing the code into functions that I compile into DLLs with Visual Studio and call with DllCall(). However, while most of the functions work as expected and set ErrorLevel to 0 after being called, they always set A_LastError to 126—"The specified module could not be found." Is this something that I should be concerned about?

Re: DllCall Produces Strange Error Code

Posted: 02 Jan 2020, 07:14
by tank
Are you loadlibrary firs?

Re: DllCall Produces Strange Error Code

Posted: 02 Jan 2020, 09:11
by 1100++
Yes.

Re: DllCall Produces Strange Error Code

Posted: 02 Jan 2020, 09:14
by swagfag
not necessarily, if ur functions dont call SetLastError what u are observing might be the remnants of previous winapi calls
or there might be something wrong with ur code, who knows

Re: DllCall Produces Strange Error Code

Posted: 02 Jan 2020, 09:45
by 1100++
Could it be DllMain()? I just used the default version provided with the Visual Studio template.

Re: DllCall Produces Strange Error Code

Posted: 02 Jan 2020, 23:18
by swagfag
probably not. u can try calling SetLastError urself with some bogus value beforehand and check whether it remains the same throughout.

Re: DllCall Produces Strange Error Code

Posted: 03 Jan 2020, 00:24
by 1100++
Using SetLastError(0); inside one of the functions resulted in an A_LastError value of zero.
If I call SetLastError(n) before calling one of my functions, the value n is preserved through the function call.

Re: DllCall Produces Strange Error Code

Posted: 03 Jan 2020, 00:51
by 1100++
I think I've determined that the error code comes from the call to LoadLibrary() that I perform before calling the function; apparently, my call to GetProcAddress() afterward has no effect on the value.