Re: make general windows module

From: Ralph (nt_consulting32_at_hotmail.com)
Date: 03/11/04


Date: Wed, 10 Mar 2004 20:21:59 -0600


"Eitan" <nobody@nospam_please.com> wrote in message
news:OuOE9atBEHA.2628@TK2MSFTNGP11.phx.gbl...
> Specifically I want a solution for how can I do "windows.h" in VB ?
>
> Thanks :)
>

Eitan,

You got your solution - twice.

Perhaps you are unaware of what the Windows.h file is? It is a header file
(actually multiple header files since it includes other headers) that
contains declarations of API calls, typedefs, structs, enums, etc. These
declarations are used by the C/C++ compiler to resolve references during the
compile and link to the correct libraries.

The VB version of these declarations is the "Declare Statement".
Unfortunately, while the C/C++ compiler only uses the header to resolve
references during the compile/link and the finished product does not include
the entire Windows.h declarations (only the items used), in VB every Declare
Statement remains in the executable/DLL. Each Declare statement takes at
least 16 bytes of memory whether used or not. A complete duplication of
Windows.h would be huge and an unnecessary burden on your application. That
is the primary reason Window API Declare statements are usually a cut 'n
paste operation.

There are also several "API Viewers" available - a simple program or addin
that allows you to look up the Windows API call (C signature) and then
provides a Declare statement to include in your code.

Mr. Bob Butler suggested that you can create a .bas file with Declare
statements. In fact VB use to ship with a text file that included quite a
few Window APIs.
The other alternative is to use a typelib. I provided an example of one of
them and where you could get it. A type library would come the closest to
mimicing the behavior of a "windows.h" header file for VB.

Note: not all Windows API calls can be called from VB as some use reference
pointers, data types, or structures not available to VB, so a complete
duplication of Windows.h is not possible. Also many single signature API
calls, e.g. those that take void*, can have several different VB Declare
statements in order to support different VB data types.

So there are your choices.

-ralph



Relevant Pages

  • Re: Exported function mangaled name
    ... that header file; it must be declared as __declspec ... You have to declare the function the same way in your .cpp file as in ... #define LIBSPEC __declspec ... See my essay on The Ultimate DLL Header File on my MVP Tips site. ...
    (microsoft.public.vc.mfc)
  • Re: confused about extern use
    ... going to achieve by declaring it as extern in the header file a.h. ... composed on one or more compilation units. ... Essentially you *declare* the type wherever it is ...
    (comp.lang.c)
  • Re: Trouble with FILE
    ... reasons I had to split up this program in several modules. ... I can declare, ... extern FILE *fp1; ... included in the header file, so that the FILE type is defined. ...
    (comp.lang.c)
  • Re-forward declaration of types which were already forward declared
    ... Is it a good style to re-forward declare the types, ... forward declared in base header file, in derived class header file? ...
    (comp.lang.cpp)
  • Re: Variable path to library?
    ... Specifically this Declare statement calls the Calc_Lat_Long function ... PFPS root folder path. ... programs directory entry in the registry and I can pull that value, ...
    (microsoft.public.office.developer.vba)