AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem using DllCall to msvcrt 8/9 dll

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
yoavyoavyoav



Joined: 19 Sep 2009
Posts: 2

PostPosted: Sat Sep 19, 2009 3:47 pm    Post subject: Problem using DllCall to msvcrt 8/9 dll Reply with quote

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
View user's profile Send private message
YMP



Joined: 23 Dec 2006
Posts: 418
Location: Russia

PostPosted: Sat Sep 19, 2009 5:53 pm    Post subject: Reply with quote

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
View user's profile Send private message
yoavyoavyoav



Joined: 19 Sep 2009
Posts: 2

PostPosted: Sun Sep 20, 2009 4:44 pm    Post subject: Reply with quote

Thanks for your reply and explanation - it worked Smile

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
View user's profile Send private message
YMP



Joined: 23 Dec 2006
Posts: 418
Location: Russia

PostPosted: Mon Sep 21, 2009 4:27 am    Post subject: Reply with quote

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. Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group