Microsoft KB Archive/69675

{|
 * width="100%"|

Must Specify as Integer When Calling External DLL

 * }

Q69675

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows 95, versions 7.0, 7.0a
 * Microsoft Word 97 for Windows

-

SUMMARY
When declaring an external function that takes an integer as one of its parameters in a Word for Windows version 1.1 macro, &quot;As Integer&quot; must be used specifically in the parameter declaration or an Unrecoverable Application Error (UAE) will occur.

If the Declare statement made a call to IsAppLoaded using &quot;(name$)&quot; instead of &quot;(name$) As Integer,&quot; a UAE will occur in Word for Windows when the macro is run.

Word 7.0, 97
In word for windows version 7.0 most function calls now return a 32 bit result refered to as a long. In function declarations As Long must be inserted in place of As Integer or a worbasic error 100 (Syntax error ) will result.

Word 2.0, 6.0
This procedure is different in Word for Windows version 2.0. If &quot;As Integer&quot; is not specified, you will receive a WordBASIC error 100, &quot;Syntax Error&quot;.

MORE INFORMATION
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code &quot;as is&quot; without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Windows Dynamic Link Libraries (DLL) can be accessed using WordBasic macros in Word for Windows. In the following example, an external function is declared for use within Word for Windows using the WordBasic macro language.

For example:

Word 7.0, 97
  Declare Function GetModuleHandle Lib &quot;kernel32&quot; Alias &quot;GetModuleHandleA&quot;(lpModuleName$) As Long Sub Main lpModuleName$ = InputBox$(&quot;Enter an application name&quot;) If GetModuleHandle(lpModuleName$) > 0 Then MsgBox &quot;The application is _ loaded &quot; End Sub

Word 2.x, 6.x
  Declare Function IsAppLoaded Lib &quot;kernel&quot; (name$) As Integer Alias &quot;GetModuleHandle&quot; Sub Main AppName$ = InputBox$(&quot;Enter an application name (e.g., Excel)&quot;) If IsAppLoaded(AppName$) Then Print &quot;The application is loaded&quot; End Sub