programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: - some questions and possibly a bug

From: Rick VanNorman <rvn_at_forth.com>
Date: Sat, 23 Jan 1999 16:45:04 -0800

>Original sender: ForthCAD <pop_at_forthcad.com>
>I have some questions and possibly I have found a bug (SwiftForth 1.50.1)

>* A problem when using Dll import words:
>
> >AS MyBeep 1 IMPORT: MessageBeep \ OK

In version 1.50.1, the AS facility was not functional. It works in the
new release 1.50.3. Please contace forthsales_at_forth.com for details
on updating your software.

To achieve the same code, simply use

: MyBeep MessageBeep ;

>* How to call directly a WindowProc adress of a DLL function ?
>
> I want to do something such as...
>
> >GETWINPROC: MessageBeep VALUE BeepAddr

This is generally a bad idea, at least in an application that is
intended to be saved as a program and later executed. The problem is
that windows may not instantiate the DLL that MessageBeep is in
at the same address later. You cannot count on the address being
constant from one execution of the program to another.

If you _really_ want to do this (and I discourage it!) you could
build defining words out of these primitives to do something like:

Z" USER32.DLL" LoadLibrary ( -- hlib)
( hlib) Z" MessageBeep" GetProcAddress ( -- addr)
CONSTANT BEEPADDR

0 1 BEEPADDR PASCAL-CALL DROP

But again, I highly recommend against doing this! Code that does this
will be all but impossible to maintain.

This is why the system has the IMPORT: function, which deals with
the correct instantiation of function addresses each time the
system loads.

Rick

.
Received on Sat Jan 23 1999 - 16:45:04 PST

This archive was generated by hypermail 2.2.0 : Thu Nov 20 2008 - 03:04:27 PST