Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. I set a global hook,But can use SAPI to speak the word typed!

I set a global hook,But can use SAPI to speak the word typed!

Scheduled Pinned Locked Moved C / C++ / MFC
helpcomperformancequestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    white jungle
    wrote on last edited by
    #1

    I want to get the word user typed and read it with SAPI. The code as follow: #pragma data_seg("shared") HHOOK m_hHook=NULL; ISpVoice * pVoice = NULL; HRESULT hr =NULL; #pragma data_seg() #pragma comment(linker,"/section:shared,rws") //defien some var for shared HINSTANCE glhInstance=NULL; //define the global var and the glhInstance will init the //function InitInstance() ................. BOOL CHookKBDApp::InitInstance() { glhInstance=::AfxGetInstanceHandle(); if (FAILED(CoInitialize(NULL))) { AfxMessageBox("Error to intiliaze COM"); return FALSE; } return CWinApp::InitInstance(); } //////////////////// .............. StartHook() { ... m_hHook=::SetWindowsHookEx(WH_CALLWNDPROC,CallWndProc,glhInstance,0); ...... //I set a global hook to get the message WM_IME_COMPOSITION //because I won't read the english ,just chinese //in the CallWndProc function there are some problem! LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam ) { //When Message WM_IME_COMPOSITION occured //I use following code to read the string if( SUCCEEDED( hr ) ) { hr = pVoice->Speak(test.AllocSysString(),SPF_DEFAULT,NULL); } //test is the string I got //and each time I typed some chinese in other program //the function pVoice->Speak(test.AllocSysString(),SPF_DEFAULT,NULL); //will throw out a error //just as "the memory address 0x00000 can be read" //but why?the string test is right! } I don'y know where the bug is ,please someone tell me it! thanks a lot! Don't look at me in that way!

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups