DllCall Produces Strange Error Code

Talk about things C/C++, some related to AutoHotkey
1100++
Posts: 78
Joined: 10 Feb 2018, 19:05

DllCall Produces Strange Error Code

02 Jan 2020, 06:46

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?
User avatar
tank
Posts: 2830
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Irving TX
Contact:

Re: DllCall Produces Strange Error Code

02 Jan 2020, 07:14

Are you loadlibrary firs?
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank :thumbup:
swagfag
Posts: 3881
Joined: 11 Jan 2017, 17:59

Re: DllCall Produces Strange Error Code

02 Jan 2020, 09:14

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
1100++
Posts: 78
Joined: 10 Feb 2018, 19:05

Re: DllCall Produces Strange Error Code

02 Jan 2020, 09:45

Could it be DllMain()? I just used the default version provided with the Visual Studio template.
swagfag
Posts: 3881
Joined: 11 Jan 2017, 17:59

Re: DllCall Produces Strange Error Code

02 Jan 2020, 23:18

probably not. u can try calling SetLastError urself with some bogus value beforehand and check whether it remains the same throughout.
1100++
Posts: 78
Joined: 10 Feb 2018, 19:05

Re: DllCall Produces Strange Error Code

03 Jan 2020, 00:24

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.
1100++
Posts: 78
Joined: 10 Feb 2018, 19:05

Re: DllCall Produces Strange Error Code

03 Jan 2020, 00:51

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.

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 3 guests