{"id":1350,"date":"2010-11-15T11:08:16","date_gmt":"2010-11-15T11:08:16","guid":{"rendered":"http:\/\/www.mjtnet.com\/blog\/?p=1350"},"modified":"2010-11-15T11:08:16","modified_gmt":"2010-11-15T11:08:16","slug":"creating-native-function-aliases-for-win32-functions","status":"publish","type":"post","link":"https:\/\/www.mjtnet.com\/blog\/2010\/11\/15\/creating-native-function-aliases-for-win32-functions\/","title":{"rendered":"Creating Native Function Aliases for Win32 Functions"},"content":{"rendered":"<p>The other day I <a href=\"http:\/\/www.mjtnet.com\/usergroup\/viewtopic.php?t=6549#29012\">posted a response<\/a> on the forums which uses LibFunc to run the Win32 API function GetKeyState.  This prompted someone to email me the following:<\/p>\n<blockquote><p>I didn&#8217;t know the Win API call to check for a key being down. The API call works but have you considered adding a native MS command called KeyDown> or maybe CheckKeyDown><\/p><\/blockquote>\n<p>Well, it&#8217;s already possible to create native looking functions for DLL functions and therefore Win32 API functions.<\/p>\n<p>We can do this by creating an Imports file in the Imports sub folder of Macro Scheduler.   Let&#8217;s make an import file for some functions in User32.dll:<\/p>\n<p><strong>Step 1<\/strong>.  If you don&#8217;t already have an Imports subfolder inside the Macro Scheduler program folder, create one: c:\\program files\\Macro Scheduler12\\Imports<\/p>\n<p><strong>Step 2<\/strong>.  Create a symbolic link to the appropriate DLL in this folder.  Start a CMD prompt and CD to the Imports folder and for User32.dll type the following: <\/p>\n<blockquote><p>mklink user32.dll c:\\windows\\system32\\user32.dll<\/p><\/blockquote>\n<p>If on a 64 bit system replace system32 with syswow64<\/p>\n<p>This will create a link to the DLL in the Imports folder.  Next we need to make a corresponding INI file.<\/p>\n<p><strong>Step 3<\/strong>.  Create a file called User32.ini in the Imports folder.  Inside this file create entries for each function you wish to import.  E.g.:<\/p>\n<blockquote><p>[GetKeyState]<br \/>\nFunctionName=GetKeyState<br \/>\nParms=1<br \/>\nParm1=INT<\/p>\n<p>[SendMessage]<br \/>\nParms=4<br \/>\nParm1=INT<br \/>\nParm2=INT<br \/>\nParm3=INT<br \/>\nParm4=INT<\/p>\n<p>[FindWindow]<br \/>\nParms=2<br \/>\nParm1=PCHAR<br \/>\nParm2=PCHAR<\/p><\/blockquote>\n<p>Now, instead of writing:<\/p>\n<pre name=\"code\" class=\"macroscript\">Let>VK_UP=38\r\nLibFunc>user32,GetKeyState,result,VK_UP<\/pre>\n<p>You can write:<\/p>\n<pre name=\"code\" class=\"macroscript\">Let>VK_UP=38\r\nGetKeyState>VK_UP,result<\/pre>\n<p>So here&#8217;s a project for someone or a group of people:  Create a User32.ini file for a fuller list of compatible functions which we can share on the website.   Any function that accepts either integers (INT) or strings (PCHAR) and returns an integer (or nothing) can be included.  And then we want another one for Kernel32.dll &#8230; etc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The other day I posted a response on the forums which uses LibFunc to run the Win32 API function GetKeyState. This prompted someone to email me the following: I didn&#8217;t know the Win API call to check for a key being down. The API call works but have you considered adding a native MS command [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,6],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/1350"}],"collection":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/comments?post=1350"}],"version-history":[{"count":7,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/1350\/revisions"}],"predecessor-version":[{"id":1357,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/1350\/revisions\/1357"}],"wp:attachment":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/media?parent=1350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/categories?post=1350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/tags?post=1350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}