Ahankhah Posted January 30, 2012 Posted January 30, 2012 Hi everybody, should anyone help me converting this vb code to vlisp? Public Declare Function LoadKeyboardLayout Lib "user32" Alias "LoadKeyboardLayoutA" (ByVal pwszKLID As String, ByVal Flags As Long) As Long LoadKeyboardLayout "00000409", 1 End Function any help is greatly appreciated Quote
BlackBox Posted January 30, 2012 Posted January 30, 2012 This appears to set a specific keyboard layout current, perhaps for use of specifying a language (Arabic?). From MSDN: Loads a new input locale identifier (formerly called the keyboard layout) into the system. Several input locale identifiers can be loaded at a time, but only one per process is active at a time. Loading multiple input locale identifiers makes it possible to rapidly switch between them. ... Source: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646305%28v=vs.85%29.aspx HTH Quote
Ahankhah Posted January 31, 2012 Author Posted January 31, 2012 (edited) Thank you RenderMan for your offer, but I want to invoke this VB command inside my Visual Lisp code and don't know which external object should be invoked:cry: Edited January 31, 2012 by Ahankhah Quote
Ahankhah Posted February 2, 2012 Author Posted February 2, 2012 Finally, I find out the syntax : (vl-load-com) (defun C:English () (vlax-invoke (vlax-create-object "WScript.Shell") "run" "rundll32.exe user32.dll,LoadKeyboardLayout 00000409 1" ) ) (defun C:Persian () (vlax-invoke (vlax-create-object "WScript.Shell") "run" "rundll32.exe user32.dll,LoadKeyboardLayout 00000429 1" ) ) But, althogh there is no error messages , windows does nothing. Who knows why? Quote
BlackBox Posted February 2, 2012 Posted February 2, 2012 Ahankhah - One must vlax-release-object when accessing external objects in order to prevent catastrophic, sometimes even fatal, errors. Perhaps this is just my preference, but I also choose to use vlax-get-or-create-object instead, so as to obtain the existing object (if one exists) rather than always creating a new instance of said object. Should there be a space after "user32.dll,"...? Quote
Ahankhah Posted February 2, 2012 Author Posted February 2, 2012 (edited) Ahankhah - One must vlax-release-object when accessing external objects in order to prevent catastrophic, sometimes even fatal, errors. Perhaps this is just my preference, but I also choose to use vlax-get-or-create-object instead, so as to obtain the existing object (if one exists) rather than always creating a new instance of said object. RenderMan, you are right and I thank you for your hint . So the code should be replaced by this one: (vl-load-com) (defun ChangeLanguage (lang / shell) (setq shell (vlax-get-or-create-object "WScript.Shell")) (vlax-invoke shell "run" (strcat "rundll32.exe user32.dll, LoadKeyboardLayout " lang " 1") ) (vlax-release-object shell) ) (defun C:Persian () (ChangeLanguage "00000429") ) (defun C:English () (ChangeLanguage "00000409") ) Should there be a space after "user32.dll,"...? Unfortunately not any result yet . Edited February 4, 2012 by Ahankhah Edited code according to Renderman's error trapping Quote
BlackBox Posted February 2, 2012 Posted February 2, 2012 The shell string runs for me (without the space)... but it causes an error in the "Multi-user USER DLL ..." which cannot be good. Quote
Ahankhah Posted February 4, 2012 Author Posted February 4, 2012 Renderman, 1- I edited the code to cover your correction. 2- I ran it in AutoCAD and get the error message showing: An exception occured while trying to run "rundll32.exe user32.dll, LoadKeyboardLayout 00000429 1" while when issuing the following in the Window's Run edit box (Start->Run...) this way: rundll32.exe user32.dll LoadKeyboardLayout "00000409" 1 there is no error message, and also not any desired result... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.