[原创]简单代码生成GUID字符串 By 旖旎(于2009-1-21发表)

;--------------------------------------------------------------------------------
;程序设计:中国·旖旎
;版权所有:旖旎 2003-2009
;禁止任何修改与盗版
;请访问旖旎汇编开发站 Http://Www.X64Asm.Com
;电子邮件 Admin@X64Asm.Com Tel:139******** QQ:6405035 6405038
;--------------------------------------------------------------------------------
;程序环境设置
.386
.model flat,stdcall
option casemap:none
;--------------------------------------------------------------------------------
;头文件与库文件导入
include windows.inc
include kernel32.inc
include user32.inc
include advapi32.inc
include shell32.inc
include ws2_32.inc
include    masm32.inc
include gdi32.inc
include comctl32.inc
include ole32.inc

includelib kernel32.lib
includelib user32.lib
includelib advapi32.lib
includelib shell32.lib
includelib WS2_32.Lib
includelib masm32.lib
includelib gdi32.lib
includelib comctl32.lib
includelib ole32.lib

;--------------------------------------------------------------------------------
;函数定义


;--------------------------------------------------------------------------------
;等值替换定义
IDD_DLG                equ 1000
IDC_GRP                equ 1001
IDC_EDT                equ 1002
IDC_CREATE            equ 1003

ICON_LOGO            equ 1000

;--------------------------------------------------------------------------------
;字符串宏定义
CTXT MACRO text        
    local lbl
    .const
        lbl db text,0
    .code
    exitm   <offset lbl>
ENDM
;--------------------------------------------------------------------------------
;包含文件

;--------------------------------------------------------------------------------
;已初始化数据段
.data

;--------------------------------------------------------------------------------
;未初始化数据段
.data?
hInstance            DWORD        ?

;--------------------------------------------------------------------------------
;常量段
.const
szErrorGuidConvertToString    BYTE        "错误:GUID转化为字符串出错,请稍后再试.",0
szErrorCreateGuid        BYTE        "错误:创建GUID出错,请稍后再试.",0    
;--------------------------------------------------------------------------------
;代码段
.code
;--------------------------------------------------------------------------------
;对话框回调函数
DlgProc proc @hWin:DWORD,@uMsg:DWORD,@wParam:DWORD,@lParam:DWORD
    LOCAL    @stGuid:GUID
    LOCAL    @hIcon:DWORD
    LOCAL    @wszGuidString[MAX_PATH]:BYTE
    LOCAL    @szGuidString[MAX_PATH]:BYTE
    mov        eax,@uMsg
    .if eax==WM_INITDIALOG
        ;初始化COM
        invoke    CoInitialize,NULL
        ;设置标题栏图标
        invoke LoadIcon,hInstance,ICON_LOGO
        mov  @hIcon,eax
        invoke SendMessage,@hWin,WM_SETICON,ICON_SMALL,@hIcon
        invoke DeleteObject,@hIcon
    .elseif eax==WM_COMMAND
        .if    @wParam==IDC_CREATE
            ;创建GUID
            invoke    CoCreateGuid,addr @stGuid
            .if    eax==S_OK
                ;转化GUID到字符串
                invoke    StringFromGUID2,addr @stGuid,addr @wszGuidString,sizeof @wszGuidString
                .if    eax
                    ;UNICODE转化为ANSI
                    invoke WideCharToMultiByte,CP_ACP,0,\
                    addr @wszGuidString,-1,addr @szGuidString,sizeof @szGuidString,NULL,NULL
                    ;输出
                    invoke    SetDlgItemText,@hWin,IDC_EDT,addr @szGuidString
                .elseif
                    invoke    SetDlgItemText,@hWin,IDC_EDT,addr szErrorGuidConvertToString
                
                .endif
            .elseif
                invoke    SetDlgItemText,@hWin,IDC_EDT,addr szErrorCreateGuid
            
            .endif
        .endif
    .elseif eax==WM_CLOSE
        ;卸载COM
        invoke    CoUninitialize
        invoke     EndDialog,@hWin,0
    .else
        mov        eax,FALSE
        ret
    .endif
    mov        eax,TRUE
    ret

DlgProc endp
;--------------------------------------------------------------------------------
start:

    invoke GetModuleHandle,NULL
    mov        hInstance,eax
        invoke InitCommonControls
    invoke DialogBoxParam,hInstance,IDD_DLG,NULL,addr DlgProc,NULL
    invoke ExitProcess,NULL

;--------------------------------------------------------------------------------
;程序入口点设定
end start

下载...

并不是所有的贴子都是原创,此时作者均指发表的人而不是文章的作者,作者会说明是否是转贴