Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??


#! perl -w package Win32::API::Guid; require 5.005_62; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); # Items to export into callers namespace by default. Note: do not expo +rt # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. # This allows declaration use Win32::API::Guid ':all'; # If you do not need this, moving things directly into @EXPORT or @EXP +ORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( generate ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( ); our $VERSION = '0.02'; use Win32::API; my $CoCreateGuid = new Win32::API( "ole32.dll", "CoCreateGuid", [ 'P' +], 'N' ); sub generate { my ($n) = @_; $n = 1 if (!defined($n) || $n < 1); my $guid = ' ' x 16; my $hr = $CoCreateGuid->Call( $guid ); my ($guidData1, $guidData2, $guidData3, @guidData4) = unpack("LS2C +8", $guid); my @guids; for (my $i = 0; $i < $n; ++$i) { my $guidstr = sprintf( "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", $guidData1, $guidData2, $guidData3, $guidData4[0], $guidData4[1], $guidData4[2], $guidData +4[3], $guidData4[4], $guidData4[5], $guidData4[6], $guidData +4[7]); push @guids, $guidstr; ++$guidData1; } return wantarray? @guids : $guids[0]; } 1; __END__ Win32::Guid - Perl extension to generate a GUID (or UUID) for use in COM or RPC =head1 SYNOPSIS use Win32::Guid 'generate'; my @guids = generate(3); my $guid = generate; =head1 DESCRIPTION This module provides a simple Win32::API wrapper for the COM function, CoCreateGuid(). The module contains one function, generate(), which returns 36-character long strings containing GUIDs. These look something like: b09e53f4-60e9-41a6-8b30-526b69c28b5d The parameter indicates the number of GUIDs to generate (the default i +s 1). In scalar context, returns a single guid, while in array context it returns the specified number guids in an array. } These can be used in a MIDL file for class, interface, or library declarations, or in various other places related to COM. =head1 INSTALL Prerequisite: module Win32-API. Simply copy this file to C:\Perl\site\lib\Win32\API\ =head1 AUTHOR Rudi Farkas, =head1 SEE ALSO CoCreateGuid() in Win32 API documentation. Win32::Guid module by Ken Bandes, "Imitation is the sincerest form of flattery" This module is functionally equivalent to Ken's, only using the Win32::API rather than an xs-generated dll. =head1 COPYRIGHT (c) 2001 Rudi Farkas. This file is Free Software; you can redistribute it and/or modify it under the same terms as Perl +itself. =cut


#! perl -w ######################### We start with some black magic to print on f +ailure. BEGIN { $| = 1; print "1..3\n"; } END {print "not ok 1\n" unless $loaded;} use Win32::API::Guid 'generate'; $loaded = 1; print "ok 1\n"; ######################### End of black magic. { local $" = "\n"; @a = generate(); print "@a\n"; print scalar(@a) == 1 ? "ok" : "not ok", " 2\n"; @a = generate(5); print "@a\n"; print scalar(@a) == 5 ? "ok" : "not ok", " 3\n"; }

In reply to Win32-API-Guid by Rudif

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (6)
    As of 2018-02-22 10:02 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (289 votes). Check out past polls.