DLL Files does not get loaded when compiled? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Capbat
Posts: 101
Joined: 17 May 2014, 13:33
Location: Québec Canada

DLL Files does not get loaded when compiled?

07 Apr 2015, 13:45

Hi All.

My script is running ok when not compiled but I get an error when it is.
Telling me it does not link to a DLL file.
Here is part of the Code related to the DLL.

Code: Select all

MediaInfoDll = %A_ScriptDir%\MediaInfo.dll
...
...
hModule := DllCall( "LoadLibrary", Str, MediaInfoDll )
if hModule = 0
{
  Msgbox % "Error loading MediaInfo.dll`n`nWas trying to load file: " . MediaInfoDll . "`n`nError was: " . GetErrorString(A_LastError) . "`n`nDownload and install MediaInfo, then set variable 'MediaInfoDll' to point to file 'MediaInfo.dll'"
  Return
}
After this script is compile it seems that hModule is equal to 0 because I get the message in the MsgBox.
I have compiled it with latest version of AHK2EXE Also using latest version of AHK.
Created a Shortcut on the Desktop that points to the compiled script with the proper 'Start In:" information.
The script works up until I push on a button that make access to the MediaInfoDLL file.
Again this scripts works perfectly when Not Compiled.
Any Suggestions.

Thanks, All.
Last edited by Capbat on 09 Apr 2015, 09:47, edited 1 time in total.
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: DLL Files does not get loaded when script is compiled?

07 Apr 2015, 14:38

In your MsgBox code you get the error string and display it. Would you post what it was?
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
User avatar
Capbat
Posts: 101
Joined: 17 May 2014, 13:33
Location: Québec Canada

Re: DLL Files does not get loaded when script is compiled?

07 Apr 2015, 14:55

Thanks for your answer MilesAhead.
Unfortunately the "GetErrorString(A_LastError)" is empty.
The message reads "Error was:" then nothing.
See Image below:

Image

Bat
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: DLL Files does not get loaded when script is compiled?

07 Apr 2015, 16:32

Just for chuckles try copying the exe and dll to a folder that has no space in the file path. See if it finds it then. It shouldn't matter inside an API call. But you never know. Only takes a few seconds for the experiment.
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
User avatar
Capbat
Posts: 101
Joined: 17 May 2014, 13:33
Location: Québec Canada

Re: DLL Files does not get loaded when script is compiled?

07 Apr 2015, 18:25

Thank again MA
Tried it in C:\Users\MyName\Documents\DocRec\
with the same problem.

The strange thing is that it works as an AHK file and not as EXE???

Any other thoughts?
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: DLL Files does not get loaded when script is compiled?

08 Apr 2015, 07:59

I don't know. I can't get it to work at all.

Code: Select all

MediaInfoDll := A_ScriptDir "\MediaInfo.dll"
hModule := DllCall("LoadLibrary", "Str", MediaInfoDll)
If (! hModule)
  MsgBox  Load of %MediaInfoDll%  failed!
I'm on a 64 bit system. I don't know if that matters.
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: DLL Files does not get loaded when script is compiled?

08 Apr 2015, 08:03

You could try posting a question on DonationCoder.com Attn skwire.

He is one of the mods. He wrote a program called PlayTime that uses MediaInfo.dll to get run times
of media files and other info, in AHK. He must know how to get you started. Perhaps the subforum
General Software Discussion.

Just say MilesAhead said skwire would know the answer. Maybe he'll help you out. :)

Edit: The PlayTime program he wrote is the one shown at the bottom on this page:
https://mediaarea.net/en/MediaInfo
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
User avatar
Capbat
Posts: 101
Joined: 17 May 2014, 13:33
Location: Québec Canada

Re: DLL Files does not get loaded when script is compiled?

08 Apr 2015, 08:59

Thanks MA I'll do that. For myself the script version works perfectly with mediainfo.dll and I use it to get all sorts of information on my database of video files. And it works very good. So I will inquire at the subforum General Software Discussion.

Thanks.

Bat
just me
Posts: 9451
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DLL Files does not get loaded when script is compiled?

08 Apr 2015, 09:46

No problems here:

Code: Select all

MediaInfoDll := "D:\Downloads\MediaInfo\x64\MediaInfo.dll"
hModule := DllCall("LoadLibrary", "Str", MediaInfoDll)
If (! hModule)
   MsgBox, Load of %MediaInfoDll%  failed!
Else
   MsgBox, Loaded %MediaInfoDll%!
Are you sure that you stored the right version of the DLL (x86/x64) in the right folder before running the compiled script?
User avatar
Capbat
Posts: 101
Joined: 17 May 2014, 13:33
Location: Québec Canada

Re: DLL Files does not get loaded when script is compiled?

08 Apr 2015, 14:58

Thanks for joining this Thread 'Just Me'.
In your example above did you tried it when your script was compiled?
I have slightly modified the code as far as assigning the MediaInfo.dll position.
Instead of:MediaInfoDll := A_ScriptDir "\MediaInfo.dll"
I changed it to a direct location as:
MediaInfoDll := "C:\Program Files\MediaInfo\MediaInfo.dll"
This is the placement of the MediaInfo.exe Software From MediaArea.Net SARL Version 0.7.72
Again this works ok with the uncompiled Script. But not with the compiled one.
Now I am not to sure about your last comment.
just me wrote:Are you sure that you stored the right version of the DLL (x86/x64) in the right folder before running the compiled script?
Originally, the AHK and the EXE and the DLL files where all in the same Folder and Running the AHK was ok but not running the EXE.
The only thing I know about the DLL file is the version 0.7.72 I don't know if it is X86 or X64. I am using it on windows 7 (64) Machine.
Would, this make a difference only when the script is compiled, like I say it is working perfectly when Not Compiled, would it have to do with AHK?.
How can I find out if the DLL is X86 or X64?

Thanks again for Popping In just me.

Bat
just me
Posts: 9451
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DLL Files does not get loaded when script is compiled?

08 Apr 2015, 15:12

Capbat wrote:This is the placement of the MediaInfo.exe Software From MediaArea.Net SARL Version 0.7.72
I suppose that exe is just a typo.

Yes, I tried with a compiled script. And, the size of the 32-bit DLL is 3.819 KB and the size of the 64-bit DLL is 4.294 KB here.
User avatar
Capbat
Posts: 101
Joined: 17 May 2014, 13:33
Location: Québec Canada

Re: DLL Files does not get loaded when script is compiled?

08 Apr 2015, 16:26

No EXE is not a typo.
The only way I found how to get the MediaInfo.DLL file was to download MediaInfo See Here https://mediaarea.net/en/MediaInfo.
Then I extracted and installed the program and then in the program folder I found the MediaInfo.DLL file I needed. And it worked ok (except when compiled). Where did you get your DLL file? Let me know how to get a copy of the file you are using, if possible.
The file I have is 4,294KB. There was another file in that directory that 3,819KB it is named MediaInfo_i386.dll may I should try this one and change it's name to MediaInfo.dll???
Thanks Bat

Edit: MAJOR Development: I used the I386 DLL file the 3,819KB one and NOW the AHK scripts gives me an error but the EXE file works OK. I was compiling and still am at this time in Unicode 32 bit. But I am not sure what I am using as far as AutoHotKey.exe if it's 64 or 32 this is getting me all confuse. :) but I am moving ahead.... :D
just me
Posts: 9451
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DLL Files does not get loaded when script is compiled?

09 Apr 2015, 04:56

I've got the DLL files from https://mediaarea.net/en/MediaInfo/Download/Windows. You have to use the DLL of the same bitness as your AHK.exe.
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: DLL Files does not get loaded when script is compiled?

09 Apr 2015, 05:44

just me wrote:I've got the DLL files from https://mediaarea.net/en/MediaInfo/Download/Windows. You have to use the DLL of the same bitness as your AHK.exe.
I got the Dll there and "installed" the 64 bit one. It won't load using Scite4AutoIt3 ( Edit: I mean Scite4AHK .. I have both installed ) or compiled. If I try to install the 32 bit it says to use the 64 bit. Skwire's PlayTime is all one exe. He must embed the Dll as a resource is all I can figure.
Last edited by MilesAhead on 09 Apr 2015, 09:22, edited 1 time in total.
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: DLL Files does not get loaded when script is compiled?

09 Apr 2015, 08:53

By the way, it used to be simple. If the complete path to Dll was not specified there was a search order starting with the folder of the program that called LoadLibrary. Now when I look up LoadLibrary on MSDN it has all this jazz about if "safe loading" is enabled it will or won't search the current directory first and it will or won't show an error with GetLastError. It was working so why did they fix it? :)
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
User avatar
Capbat
Posts: 101
Joined: 17 May 2014, 13:33
Location: Québec Canada

Re: DLL Files does not get loaded when script is compiled?  Topic is solved

09 Apr 2015, 09:38

I think I have found the solution and thanks to you 'just me' for leading me in the proper direction.
I have find out that I am using AutoHotkey.exe 64bit. and originally I was using the 64bit DLL.
So 64Bit AHK.EXE and 64Bit DLL should work, the thing is I was compiling in 32bit.
That is why with that configuration the script worked but not the EXE.
Then I changed to 64B AHK.EXE and 32Bit DLL.
Then the Script wouldn't work but the EXE compiled in 32bit Did.
Today I use the initial configuration 64EXE 64DLL and compiled in 64Bit and the problem is gone.

Thanks Again 'just me'

Bat.
User avatar
Capbat
Posts: 101
Joined: 17 May 2014, 13:33
Location: Québec Canada

Re: DLL Files does not get loaded when script is compiled?

09 Apr 2015, 09:45

MilesAhead wrote:He must embed the Dll as a resource is all I can figure.
As explained above I eventually found the solution with the help of 'just me' and yours. But I will get back to Skwire to find out how he embedded it in exe of included it in. By the way this http://www.donationcoder.com/ is very interesting for small developer like me. I didn't knew it existed, thanks for pointing it out to me.

Thanks.
Bat
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: DLL Files does not get loaded when script is compiled?

09 Apr 2015, 11:05

Capbat wrote:
MilesAhead wrote:He must embed the Dll as a resource is all I can figure.
As explained above I eventually found the solution with the help of 'just me' and yours. But I will get back to Skwire to find out how he embedded it in exe of included it in. By the way this http://www.donationcoder.com/ is very interesting for small developer like me. I didn't knew it existed, thanks for pointing it out to me.

Thanks.
Bat
You are welcome. I've been on there for years. The whole idea is to boost the small developer. If you publish freeware be sure to let Mouser know. He gives a special welcome to those who share their programs. :)
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
Tuellerey
Posts: 9
Joined: 25 Feb 2021, 15:24

Re: [SOLVED] DLL Files does not get loaded when compiled?

17 Apr 2021, 04:14

I solved my problem with this post




Hello there!

I have a similar problem described at the wrong place in this forum. I guess it's more of a general issue. I tried to compile it differently, I changed to ANSI and Unicode in my AutoHotkey Compiler, I also changed the gerenal configuration of AutoHotkey for any of these three.

Still, I cannot run the compiled script at the very same folder, it will not find the dll file obviously.

Sorry for the chaos. I appreciate any help!

Thanks a lot.
Tuellerey


Tuellerey wrote:
16 Apr 2021, 02:40
Hello there.

It's a fabulous wrapper :clap:

Still, I have an issue. The scripts run well being *.ahk. Once I compile them, executing the *.exe will cause an error:

image.png

I don't know, why. I cannot unblock as described, did this in the beginning.

The correspondend lines of code would be:

Code: Select all

class AutoHotStreamDeck {
	__New(){
		dllName := "AutoHotStreamDeck.dll"
		dllFile := A_LineFile "\..\" dllName
		hintMessage := "Try right-clicking lib\" dllName ", select Properties, and if there is an 'Unblock' checkbox, tick it`nAlternatively, running Unblocker.ps1 in the lib folder (ideally as admin) can do this for you."
		if (!FileExist(dllFile)){
			MsgBox % "Unable to find lib\" dllName ", exiting..."
			ExitApp
		}
I appreciate any help.

Cheers,
Tuellerey

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Google [Bot], mikeyww, Nerafius, scriptor2016 and 82 guests