I'm trying to fix a serious bug in my Win32::SystemInfo module that affects Win9x. The fix involves including a DLL with the module that will determine the CPU speed. The DLL contains code released by Intel, and I have successfully used it in a Visual C++ based project at work. I can't seem to get it work with Win32::API, however.
The function I'm calling in the DLL is defined like this:
struct FREQ_INFO cpuspeed(int clocks);. FREQ_INFO is a struct that contains four unsigned longs.

My test code is this:
use strict; use Win32::API; my $FREQ_INFO = pack("L4",0,0,0,0); my $CpuSpeed ||= new Win32::API ("cpuinf32", "cpuspeed", ["I"], "P") or die "Could not load DLL\n"; $FREQ_INFO = $CpuSpeed->Call(0); my ($in_cycles, $ex_ticks, $raw_freq, $norm_freq) = unpack("L4",$FREQ_ +INFO); print "In cycles: $in_cycles\n"; print "Ex ticks: $ex_ticks\n"; print "Raw freq: $raw_freq\n"; print "Norm freq: $norm_freq\n";

Running this code generates a Privileged Instruction exception. I thought that the problem might lie in the code I'm calling, since it executes ring 0 operations on the CPU. I changed the Win32::API call to import a different function, called cpunormspeed, that takes an int and returns an unsigned long. When I make that function call, I get a generic application error.
Am I making an error in the return parameter? Should I just get the return value in an I or N and unpack it without packing first?

Guildenstern
Negaterd character class uber alles!

In reply to Difficulties with Win32::API by Guildenstern

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.