Search the Community
Showing results for tags 'srand msvcrt'.
-
I'm trying to call the srand function in the msvcrt.dll. It is defined as void srand( unsigned int seed ); My sample code is: Local $aResult Local $h_DLL = DllOpen("msvcrt.dll") If $h_DLL <> -1 Then Local $uint = DllStructCreate("uint") DllStructSetData($uint, 1, 54321) ConsoleWrite('@@' & @ScriptLineNumber & ' uint[' & DllStructGetSize($uint) & ']:' & DllStructGetData($uint, 1) & @CRLF) $aResult = DllCall($h_DLL, "none", "srand", "int", $uint) ConsoleWrite('@@' & @ScriptLineNumber & ' srand done' & @CRLF) If @error Then ConsoleWrite('@@' & @ScriptLineNumber & ' srand Error:' & @error & @CRLF) EndIf Else ConsoleWrite('@@' & @ScriptLineNumber & ' srand DLL Error' & @CRLF) EndIf When I run it I get: >Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\AutoIt3\PasswordTool\Tweaks\srand.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop @@7 uint[4]:54321 !>15:15:08 AutoIt3.exe ended.rc:-1073741819 +>15:15:08 AutoIt3Wrapper Finished. >Exit code: 3221225477 Time: 0.6205 Which indicates an Access violation. Using windbg, I can see in the assembly that it is trying to do a PTR on a 0x00 value. Searching the web, I found a reference to what the srand routine is trying to do: void __cdecl srand (unsigned int seed) { _getptd()->_holdrand = (unsigned long)seed; } int __cdecl rand (void) { _ptiddata ptd = _getptd(); return ( ((ptd->_holdrand = ptd->_holdrand * 214013L + 2531011L) >> 16) & 0x7fff ); } Do I need to do something to the msvcrt.dll library before it can reference any global pointers. I'm assuming that _getptd() must reference some global pointer?