From: David Garamond Date: 2004-01-23T00:57:57+09:00 Subject: help with Win32API I'm trying to do the equivalent of this C code: long getrand() { HCRYPTPROV hProv = 0; CryptAcquireContext(&hProv, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); long rnd; CryptGenRandom(hProv, sizeof(rnd), (BYTE*)&rnd); CryptReleaseContext(hProv, 0); return rnd; } Eexcept that I want to generate 16 bytes of random numbers. Here's my stab so far: require 'Win32API' cac = Win32API.new("advapi32", "CryptAcquireContext", ['P','L','L','I','I'], 'N') cgr = Win32API.new("advapi32", "CryptGenRandom", ['P','I','P'], 'N') hProv = " " * 16 cac.call(hProv, 0, 0, 1, 251658240) guid = " " * 16 cgr.call(hProv, 16, guid) p guid From wincrypt.h: #define PROV_RSA_FULL 1 #define CRYPT_VERIFYCONTEXT 0xF0000000 BOOL WINAPI CryptGenRandom (HCRYPTPROV hProv, DWORD dwLen, BYTE *pbBuffer); BOOL WINAPI CryptAcquireContext(HCRYPTPROV *phProv, LPCSTR pszContainer, LPCSTR pszProvider, DWORD dwProvType, DWORD dwFlags); No segfaults, but the output comes up still empty. Any pointer where I did wrong? Sigh, I'm so terrible when it comes to C. -- dave