AutoHotkey Community

It is currently May 26th, 2012, 9:41 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: September 19th, 2009, 4:47 pm 
Offline

Joined: September 19th, 2009, 4:37 pm
Posts: 2
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.)

Image


Thanks in advance !


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 19th, 2009, 6:53 pm 
Offline

Joined: December 23rd, 2006, 6:02 pm
Posts: 424
Location: Russia
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 20th, 2009, 5:44 pm 
Offline

Joined: September 19th, 2009, 4:37 pm
Posts: 2
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2009, 5:27 am 
Offline

Joined: December 23rd, 2006, 6:02 pm
Posts: 424
Location: Russia
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. :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, JSLover, patgenn123, rbrtryn, virpara and 59 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group