| View previous topic :: View next topic |
| Author |
Message |
yoavyoavyoav
Joined: 19 Sep 2009 Posts: 2
|
Posted: Sat Sep 19, 2009 3:47 pm Post subject: Problem using DllCall to msvcrt 8/9 dll |
|
|
Hi,
I came up with the need to create secure random numbers with AHK.
I tried calling RtlGenRandom(aka "SystemFunction036") with DllCall - and this worked quite well.
Then I tried to call rand_s from msvcr90.dll (I know this function actually calls RtlGenRandom - just wanted to try) - and It didn't quite work.
I couldn't understand the error so much (googling for it came with something related to AHK manifest file - but i'm unfamilier with the "manifest file" term.)
Thanks in advance ! |
|
| Back to top |
|
 |
YMP
Joined: 23 Dec 2006 Posts: 418 Location: Russia
|
Posted: Sat Sep 19, 2009 5:53 pm Post subject: |
|
|
AutoHotkey.exe contains its manifest as a resource. It's an XML file that describes the executable's dependencies. Msvcr90.dll is not mentioned among them, therefore it is not loaded when AutoHotkey.exe starts up. And loading it directly via LoadLibrary seems not allowed.
On Windows XP, you can override the built-in manifest by creating a separate file called AutoHotkey.exe.manifest and putting it beside AutoHotkey.exe. Here are its contents that worked for me on my system (XP SP2 Home):
| Code: |
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.48.03"
processorArchitecture="X86"
name="Microsoft.Windows.AutoHotkey"
type="win32"
/>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.VC90.CRT"
version="9.0.21022.8"
processorArchitecture="x86"
publicKeyToken="1fc8b3b9a1e18e3b"
/>
</dependentAssembly>
</dependency>
</assembly>
|
With the above file, this code works:
| Code: |
Err := DllCall("msvcr90\rand_s", "uint *", Rand, "Cdecl")
MsgBox, Number: %Rand%`nError: %Err%
|
For more information: Troubleshooting C/C++ Isolated Applications and Side-by-side Assemblies.
| MSDN wrote: |
On Windows XP, if an external manifest is present in the application's local folder, the operating system loader uses this manifest instead of a manifest embedded inside the binary. On Windows Server 2003 and later versions of Windows, the opposite is true—the external manifest is ignored and the embedded manifest is used when present. |
|
|
| Back to top |
|
 |
yoavyoavyoav
Joined: 19 Sep 2009 Posts: 2
|
Posted: Sun Sep 20, 2009 4:44 pm Post subject: |
|
|
Thanks for your reply and explanation - it worked
However, I read the relevant pages in MSDN and I still couldn't figure out - how not declaring the dependency to msvcr90 in the manifest disables me from calling LoadLibrary to it ?
Again - thanks. |
|
| Back to top |
|
 |
YMP
Joined: 23 Dec 2006 Posts: 418 Location: Russia
|
Posted: Mon Sep 21, 2009 4:27 am Post subject: |
|
|
| yoavyoavyoav wrote: | | However, I read the relevant pages in MSDN and I still couldn't figure out - how not declaring the dependency to msvcr90 in the manifest disables me from calling LoadLibrary to it ? |
Well, I don't know the exact answer. To me it's still one of Windows' mysteries.  |
|
| Back to top |
|
 |
|