CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Apr 2009
    Posts
    116

    [RESOLVED] On Screen Keyboard Error On 64 bit Windows 7

    By using visual studio 2010, I have problem calling up on screen keyboard using line below for Windows 7 64 bit.

    WinExec("OSK.EXE", SW_SHOW);

    However, it is working fine on windows XP 32 bit. Any idea how to call up on screen keyboard for 64 bit windows?

    Code:
    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
    	int nRetCode = 0;
    
    	HMODULE hModule = ::GetModuleHandle(NULL);
    
    	if (hModule != NULL)
    	{
    		// initialize MFC and print and error on failure
    		if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
    		{
    			// TODO: change error code to suit your needs
    			_tprintf(_T("Fatal Error: MFC initialization failed\n"));
    			nRetCode = 1;
    		}
    		else
    		{
    			// TODO: code your application's behavior here.
    
    			WinExec("OSK.EXE", SW_SHOW); //to call up on screen keyboard
    		}
    	}
    	else
    	{
    		// TODO: change error code to suit your needs
    		_tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
    		nRetCode = 1;
    	}
    
    	return nRetCode;
    }
    Attached Images Attached Images  

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: On Screen Keyboard Error On 64 bit Windows 7

    A 64-bit Windows system prevents 32-bit applications from accessing System32 directory. For that purpose, it redirects to SysWOW64.
    You can (temporarily) disable that redirection by calling Wow64DisableWow64FsRedirection.

    Example
    Code:
        PVOID pOldValue = NULL;
        Wow64DisableWow64FsRedirection(&pOldValue);
                
        STARTUPINFO si = {0};
        si.cb = sizeof(STARTUPINFO);
        PROCESS_INFORMATION pi = {0};
        bRet = ::CreateProcess(_T("C:\\Windows\\System32\\OSK.EXE"), 
            NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
    
        Wow64RevertWow64FsRedirection(pOldValue);
    Additional notes
    • Although it may work, WinExec is a 16-bit legacy function. You should use CreateProcess instead.
    • The above example is intentionally made as simple as possible. It doesn't handle errors, uses a hard-coded path and does not check if the system is 32 or 64-bit version. You have to complete that yourself.


    See also
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Apr 2009
    Posts
    116

    Re: On Screen Keyboard Error On 64 bit Windows 7

    Thanks ovidiucucu, I tried your code and it manage to call up the on screen keyboard.
    Also, I did try the WinExec using code below, it works as well.
    Appreciate your help on this.
    Code:
      PVOID OldValue = NULL;
    
    if( Wow64DisableWow64FsRedirection(&OldValue) ) 
     {
        WinExec("OSK.EXE", SW_SHOW);
     }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured