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

Post by 1100++ » 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: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: DllCall Produces Strange Error Code

Post by tank » 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;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter

1100++
Posts: 78
Joined: 10 Feb 2018, 19:05

Re: DllCall Produces Strange Error Code

Post by 1100++ » 02 Jan 2020, 09:11

Yes.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: DllCall Produces Strange Error Code

Post by swagfag » 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

Post by 1100++ » 02 Jan 2020, 09:45

Could it be DllMain()? I just used the default version provided with the Visual Studio template.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: DllCall Produces Strange Error Code

Post by swagfag » 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

Post by 1100++ » 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

Post by 1100++ » 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.

Post Reply

Return to “C/C++”