标签:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
Option Explicit Private Type GUID Data1 As Long Data2 As Integer Data3 As Integer Data4(8) As Byte End Type Private Declare Function CoCreateGuid Lib "ole32.dll" (pguid As GUID) As Long Private Declare Function StringFromGUID2 Lib "ole32.dll" (rguid As Any, ByVal lpstrClsId As Long , ByVal cbMax As Long ) As Long Private Function GUIDGen() As String ‘生成GUID Dim uGUID As GUID Dim sGUID As String Dim bGUID() As Byte Dim lLen As Long Dim RetVal As Long lLen = 40 bGUID = String (lLen, 0) CoCreateGuid uGUID ‘把结构转换为一个可显示的字符串 RetVal = StringFromGUID2(uGUID, VarPtr(bGUID(0)), lLen) sGUID = bGUID If (Asc(Mid$(sGUID, RetVal, 1)) = 0) Then RetVal = RetVal - 1 GUIDGen = Left$(sGUID, RetVal) End Function |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include <objbase.h> #include <stdio.h> //--生成GUID const char * newGUID() { static char buf[64] = {0}; GUID guid; if (S_OK == ::CoCreateGuid(&guid)) { _snprintf(buf, sizeof (buf) , "{%08X-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X}" , guid.Data1 , guid.Data2 , guid.Data3 , guid.Data4[0], guid.Data4[1] , guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5] , guid.Data4[6], guid.Data4[7] ); } return ( const char *)buf; } int main( int argc, char * argv[]) { //--COM CoInitialize(NULL); printf (newGUID()); printf ( "\n" ); //--COM CoUninitialize(); return 0; } |
1
2
3
4
5
6
7
8
|
uses ActiveX; function ctGUID: string ; var id:TGUID; begin CoCreateGuid(id); Result:=GUIDToString(id); end ; |
1
2
3
4
5
6
7
8
9
10
11
12
13
|
using System; namespace GUID测试 { class Program { static void Main( string [] args) { //产生一个新的GUID并输出 Console.WriteLine(System.Guid.NewGuid()); Console.ReadKey(); } } } |
1
2
3
4
5
6
7
8
9
10
11
|
import java.util.UUID; public class guid { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub UUID uuid = UUID.randomUUID(); System.out.println( ".{" +uuid.toString()+ "}" ); } } |
1
2
3
4
5
6
7
8
9
10
11
12
|
Function Guid_Gen: ansistring ; Var s: string ; i: longint ; Begin s:= ‘0123456789abcdef‘ ; //8-4-4-4-12 Guid_Gen:= ‘xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx‘ ; for i:= 1 to length(Guid_Gen) do begin if Guid_Gen[i]= ‘x‘ then Guid_Gen[i]:=s[Random( 16 )+ 1 ]; end ; End ; |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
.版本 2 .DLL命令 CoCreateGuid, , "ole32" , "CoCreateGuid" .参数 guid, 字节集 .版本 2 .子程序 生成新的GUID, 文本型 .局部变量 guid, 字节集 .局部变量 a, 长整数型 .局部变量 b, 整数型 .局部变量 c, 整数型 .局部变量 s, 文本型 .局部变量 i, 整数型 guid = 取空白字节集 (16) CoCreateGuid (guid) a = 取字节集数据 (取字节集左边 (guid, 4), #长整数型, ) b = 取字节集数据 (取字节集中间 (guid, 5, 2), #整数型, ) c = 取字节集数据 (取字节集中间 (guid, 7, 2), #整数型, ) s = “” s = s + 取文本右边 (“00000000” + 取十六进制文本 (a), 8) + “-” s = s + 取文本右边 (“0000” + 取十六进制文本 (b), 4) + “-” s = s + 到小写 (取文本右边 (“0000” + 取十六进制文本 (c), 4)) + “-” ‘ 第三部分中的字母为小写字母 .计次循环首 (8, i) s = s + 取文本右边 (“00” + 取十六进制文本 (guid [i + 8]), 2) .如果真 (i = 2) s = s + “-” .如果真结束 .计次循环尾 () 返回 (“{” + s + “}”) |
1
|
public function create_guid(){ $charid = strtoupper (md5(uniqid(mt_rand(), true))); $hyphen = chr (45); // "-" $uuid = substr($charid, 6, 2).substr($charid, 4, 2).substr($charid, 2, 2).substr($charid, 0, 2).$hyphen .substr($charid, 10, 2).substr($charid, 8, 2).$hyphen .substr($charid,14, 2).substr($charid,12, 2).$hyphen .substr($charid,16, 4).$hyphen .substr($charid,20,12); return $uuid; } |
1
2
3
|
Function GetGuidToString() As String GetGuidToString = LCase(Mid$(CreateObject( "Scriptlet.TypeLib" ).GUID, 2, 36)) End Function |
标签:
原文地址:http://www.cnblogs.com/yg6405816/p/5570642.html