【汇编】汇编写的SpVoice的Demo,COM类的调用例子
其实和这个帖子差不多,就是说句话而已。然而这是汇编的。这对于学习汇编的人有很大帮助哦。;导出符号
global _start
;导入API
extern __imp__CoInitialize@4
extern __imp__CoCreateInstance@20
extern __imp__MessageBoxA@16
extern __imp__ExitProcess@4
;SpVoice的虚表
struc ISpVoice_Vtbl
;IUnknown
.QueryInterface resd 1
.AddRef resd 1
.Release resd 1
;ISpNotifySource
.SetNotifySink resd 1
.SetNotifyWindowMessage resd 1
.SetNotifyCallbackFunctionresd 1
.SetNotifyCallbackInterface resd 1
.SetNotifyWin32Event resd 1
.WaitForNotifyEvent resd 1
.GetNotifyEventHandle resd 1
;ISpEventSource
.SetInterest resd 1
.GetEvents resd 1
.GetInfo resd 1
;ISpVoice
.SetOutput resd 1
.GetOutputObjectToken resd 1
.GetOutputStream resd 1
.Pause resd 1
.Resume resd 1
.SetVoice resd 1
.GetVoice resd 1
.Speak resd 1
.SpeakStream resd 1
.GetStatus resd 1
.Skip resd 1
.SetPriority resd 1
.GetPriority resd 1
.SetAlertBoundary resd 1
.GetAlertBoundary resd 1
.SetRate resd 1
.GetRate resd 1
.SetVolume resd 1
.GetVolume resd 1
.WaitUntilDone resd 1
.SetSyncSpeakTimeout resd 1
.GetSyncSpeakTimeout resd 1
.SpeakCompleteEvent resd 1
.IsUISupported resd 1
.DisplayUI resd 1
endstruc
segment .text
;==============================================================================
;函数:_start
;描述:程序入口点
;------------------------------------------------------------------------------
_start:
;//初始化COM
;if(FAILED(hr=CoInitialize(NULL)))
;{
; MessageBox(NULL,"初始化COM失败。",NULL,MB_OK);
; return 1;
;}
push 0
call
cmp eax,0
jge .initsuccess
push 0
push 0
push szInitComFailed
push 0
call
jmp .Failed
.initsuccess:
;ISpVoice*Voice;
;if(FAILED(hr=CoCreateInstance(CLSID_SpVoice,NULL,CLSCTX_INPROC_SERVER,IID_ISpVoice,(LPVOID*)&Voice)))
;{
; MessageBox(NULL,"创建ISpVoice对象失败。",NULL,MB_OK);
; return 1;
;}
push _pSpVoice
push _IID_ISpVoice
push 1 ;CLSCTX_INPROC_SERVER
push 0
push _CLSID_SpVoice
call
cmp eax,0
jge .createsuccess
push 0
push 0
push szCreateObjFailed
push 0
call
jmp .Failed
.createsuccess:
;Voice->Speak(TEXT("Hello World. 然而并没有什么卵用。"),SVSFDefault,NULL);
push 0
push SVSFDefault
push szSpeak
mov edx,
push edx
mov eax,
call
;Voice->Release();
mov edx,
push edx
mov eax,
call
xor eax,eax
push eax
call
.Failed:
mov eax,1
push eax
call
;数据段
segment .data
_pSpVoice dd 0;ISpVoice*pSpVoice=NULL;
_CLSID_SpVoice:
dd 0x96749377
dw 0x3391,0x11D2
db 0x9E,0xE3,0x00,0xC0,0x4F,0x79,0x73,0x96
_IID_ISpVoice:
dd 0x6C44DF74
dw 0x72B9,0x4992
db 0xA1,0xEC,0xEF,0x99,0x6E,0x04,0x22,0xD4
szInitComFailed db "初始化COM失败。",0
szCreateObjFailed db "创建ISpVoice对象失败。",0
szSpeak:;"Hello World. 然而并没有什么卵用。",0
db 0x48,0x00,0x65,0x00,0x6c,0x00,0x6c,0x00,0x6f,0x00,0x20,0x00,0x57,0x00,0x6f,0x00
db 0x72,0x00,0x6c,0x00,0x64,0x00,0x2e,0x00,0x20,0x00,0x36,0x71,0x0c,0x80,0x76,0x5e
db 0xa1,0x6c,0x09,0x67,0xc0,0x4e,0x48,0x4e,0x75,0x53,0x28,0x75,0x02,0x30,0x00,0x00
SPF_DEFAULT equ 0
SPF_ASYNC equ (1<<0)
SPF_PURGEBEFORESPEAK equ (1<<1)
SPF_IS_FILENAME equ (1<<2)
SPF_IS_XML equ (1<<3)
SPF_IS_NOT_XML equ (1<<4)
SPF_PERSIST_XML equ (1<<5)
SPF_NLP_SPEAK_PUNC equ (1<<6)
SPF_PARSE_SAPI equ (1<<7)
SPF_PARSE_SSML equ (1<<8)
SPF_PARSE_AUTODETECT equ 0
SPF_NLP_MASK equ SPF_NLP_SPEAK_PUNC
SPF_PARSE_MASK equ (SPF_PARSE_SAPI|SPF_PARSE_SSML)
SPF_VOICE_MASK equ (((((((SPF_ASYNC|SPF_PURGEBEFORESPEAK)|SPF_IS_FILENAME)|SPF_IS_XML)|SPF_IS_NOT_XML)|SPF_NLP_MASK)|SPF_PERSIST_XML)|SPF_PARSE_MASK)
SPF_UNUSED_FLAGS equ (~SPF_VOICE_MASK)
SVSFDefault equ SPF_DEFAULT
SVSFlagsAsync equ SPF_ASYNC
SVSFPurgeBeforeSpeak equ SPF_PURGEBEFORESPEAK
SVSFIsFilename equ SPF_IS_FILENAME
SVSFIsXML equ SPF_IS_XML
SVSFIsNotXML equ SPF_IS_NOT_XML
SVSFPersistXML equ SPF_PERSIST_XML
SVSFNLPSpeakPunc equ SPF_NLP_SPEAK_PUNC
SVSFParseSapi equ SPF_PARSE_SAPI
SVSFParseSsml equ SPF_PARSE_SSML
SVSFParseAutodetect equ SPF_PARSE_AUTODETECT
SVSFNLPMask equ SPF_NLP_MASK
SVSFParseMask equ SPF_PARSE_MASK
SVSFVoiceMask equ SPF_VOICE_MASK
SVSFUnusedFlags equ SPF_UNUSED_FLAGS
编译命令:nasm -f win32 COM_SpVoice.asm -o COM_SpVoice.obj
@pause
link /ENTRY:start /MACHINE:X86 /NOLOGO /OUT:COM_SpVoice.exe /RELEASE /SUBSYSTEM:WINDOWS /VERSION:1.0 COM_SpVoice.obj kernel32.lib user32.lib ole32.lib
@pause
BIN:
SRC: 来抢个沙发,支持楼主; LINK 感觉有点儿麻烦~
页:
[1]