Function to create GUID

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
I can (and often do) generate a GUID and get it into a variable this way:

set xyzzy=%@execstr[uuidgen.exe]

Or, as often as not, like this:

set xyzzy=%@upper[%@replace[-,,%@execstr[uuidgen.exe]]]

But of course that calls for always having UUIDGEN on tap. If there's some other tool for this other than ActiveState's Perl, with its Win32 extensions, I haven't run across it.

Any chance of ever having a variable function such as %@guid[], which would immediately generate it? The frosting on the cake would be switches for returning the GUID in upper- or lower-case, and with or without hyphens separating the number groups.
 
#2
If there's some other tool for this other than ActiveState's Perl, with its Win32 extensions, I haven't run across it.
Every Windows system, from XP forward, comes with VBC.EXE, which is the Visual Basic Compiler for .NET. I have mine aliased as follows;

Code:
which vbc
vbc is an alias : c:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe
You can create your own GUID generator with the following VB.NET code;

Code:
Imports System

Class Sample
  Public Shared Sub Main()
  Dim g As Guid
  g = Guid.NewGuid()
  Console.WriteLine(g)
  End Sub 'Main
End Class 'Sample
Save the code as guid.bas, and execute the following;

Code:
vbc guid.bas
This will create the file guid.exe, which you can use to create your own unique guid.

Joe
 
#3
Joe:
Could someone more familiar with VBC etc. than I am use your code above as the framework for a plugin, instead of creating an external executable? Of course, while we do not usually think of them that way, plugins are actually also externals, so the function would still use an external, just a different type (and the load time delay, if any, would occur at a different time).
 
#6
Thanks! But a simple request - TCC's defaults to slash "/", just like CMD's, as the option prefix, not the POSIX-style hyphen. My own few utilities accept both (they predate TCC). Most plugins which process commands with options expect the slash...
 
#8
Thanks. Talk about instant gratification. : ) ... a few minutes later ... not having used 4NT or TCC plugins before, I guess I need to do some catching-up. I made a PLUGINS subdirectory of the install directory for TCC, added the new DLL to it, and closed and launched TCC.

c:\takecommand> echo %@guid[]

produced an error message about an incorrect function. Ok, let's load the DLL manually.

plugin /L plugins\jlcGuid.dll

Result: TCC: (Sys) plugins\jlcGuid.dll is not a valid Win32 application.

or in case TCC assumes you've used a PLUGINS subdirectory:

plugin /L jlcGuid.dll (same result)

...and echo %@guid[] had the same result as earlier

So -- there must be some simple step I'm omitting here...
 
Last edited:

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,429
40
Albuquerque, NM
prospero.unm.edu
#9
Thanks. Talk about instant gratification. : ) ... a few minutes later ... not having used 4NT or TCC plugins before, I guess I need to do some catching-up. I made a PLUGINS subdirectory of the install directory for TCC, added the new DLL to it, and closed and launched TCC.

c:\takecommand> echo %@guid[]

produced an error message about an incorrect function. Ok, let's load the DLL manually.

plugin /L plugins\jlcGuid.dll

Result: TCC: (Sys) plugins\jlcGuid.dll is not a valid Win32 application.
Works here. Are you by any chance using a 64-bit build of TCC?
 
#13
Interesting decision on their part, given that 64-bit devices seem to be taking over. I appreciate the offer. I think I'm good with what I have, because I also have 4NT on a creaky old WinXP box, and I would think the DLL will work with that version.
 
#14
Interesting decision on their part, given that 64-bit devices seem to be taking over.
Since Bob Zale passed away, I'm not sure what direction PowerBASIC is taking. There have been assurances from his wife, Vivian Zale, that they are "preparing to launch new and innovative products", but I remember a year ago Bob saying that, since PowerBASIC is written in assembler, it is quite the task to create "new development syntax for hundreds of thousands of lines of assembler code. New generated machine code. New calling conventions. New optimization techniques. New register preservation."

Bob Zale was PowerBASIC, and I will just have to wait and see what happens.

Joe