Question
Do ActiveX DLLs made in VB still need the VB runtimes on
the
machine?
________________________________________
Answer
In a word, Yes.
Visual Basic does not support what is known as "Static
Linking". What that means is that all componets, controls,
and applications developed with Visual Basic, also requier
the Visual Basic Runtime libraries.
Question
What is a circular reference? Why is it bad?
________________________________________
Answer
Consider two objects, A and B. A holds a reference to B,
and B holds a reference to A. A only releases its
reference to B when A terminates. B only releases its
reference to A when B terminates. Since neither A nor B
will terminate until all active references to them are
released, A and B are now immortal (which might sound cool,
but is really a 'bad thing').
Circular references should be avoided whenever possible,
but in some designs they can be unavoidable. For those
cases, there are various methods for "breaking" circular
references. One technique is to require the client to
manually clear them (eg. Set A.BReference = Nothing or call
a method which releases the reference). Another technique
is to use unsupported functions (ObjPtr, etc.) to get a non-
binding reference to the object. Yet another method is to
use a proxy object to dynamically obtain a reference which
is held only for the duration of the call
Question
What is meant by "Early Binding" and "Late Binding"? Which
is better?
________________________________________
Answer
Early binding and late binding refer to the method used to
bind an interface's properties and methods to an object
reference (variable). Early binding uses type library
information at design time to reference procedures, while
late binding handles this at run time. Late binding
handles this by interrogating the reference before each
call to insure that it supports a particular method. Since
every call to a late bound object actually requires two
calls ("Do you do this?" followed by "Okay, do it then"),
late binding is much less efficient than early binding.
Except where early binding is not supported (ASP,
scripting, etc.), late binding should only be used in very
special cases.
It is a common misconception that any code using the
CreateObject function instead of Set = New is using late
binding. This is not the case. The type declaration of
the object variable determines whether it is late or early
bound, as in the following:
Dim A As Foo
Dim B As Foo
Dim C As Object
Dim D As Object
Set A = New Foo 'Early Bound
Set B = CreateObject("FooLib.Foo") 'Early Bound
Set C = CreateObject("FooLib.Foo") 'Late Bound
Set D = New Foo 'Late Bound
Question
I have been reading on the topic callin win32 APIs, but as
I think its a very complex topic I hope anyone can help me
sort it out a little more when answering my question:
In what kind of circumstances do you actually have
use accessing WIN32 API?
________________________________________
Answer
There are approximately 15,000 functions included in the
WIN32 API. It's a 'collection' of functions that make up
the 'guts' of how Windows works.
Every application uses these functions to 'be' a Windows
application. In VB we are just shielded from most of it
because they wrote a bunch of 'wrapper' functions over the
API's for us.
Sometimes however they didn't give us all the functionality
we need and we will have to use a specific API function
ourselves to overcome this limitation. There are a number
of areas where we can do this. Actually just about
anything and anywhere.
However below you will find some quick examples of 'why' we
would use the API directly. As far as the AddressOf
operator, this is because some API functions require
a 'callback' function. This is a routine that the API will
call when it has finished it's processing and wants to let
you know it's 'your turn' again.
Some examples...
* Putting icons in the System Tray
* Getting / Setting text to other applications (commonly
called "Screen-Scrapping")
* Creating high precision timer functions (vb's are very
limited)
* Subclassing a form or window (<--too much here to
explain shortly)
* Making a specific window always being on top of other
windows
Question
Why do so many example programs not use the DLL name
directly without an alias? Surely the DLL names do not
commonly clash with existing names.
________________________________________
Answer
There are a lot of reasons to use aliases. For instance, the
SendMessage API. You need to change the data types you are
sending to the API, so you need to have multiple
declarations of the same API.
There are many structures (UDTs) which are bigger or smaller
in NT than they are in Win9x. So, again, you need to change
what UDT you are pointing at depending on the OS. Since you
can''t do this on the fly, you need to write to different
declares.
Also, there are a lot of APIs that need to differentiate
between whether you are sending it a unicode or an ansi
string.
Question
What is a hWnd and what can it be used for?
Code examples for different kinds of usage are welcome.
________________________________________
Answer
An hWnd is a Handle to a Window if you will. A handle is a
long integer generated by the operating system so it can
keep track of the all the objects (a form, a command button
etc.)
You can't set a hwnd at design or runtime, and the value of
the handle changes each time the form is opened. Handles
are used when you make calls to API functions, the function
needs to know the handle of the window, plus other
arguements depending on the what
the API does.
The GetWindowsText API frx:
Declare Function GetWindowText Lib "user32" alias _
"GetWindowTextA" (byval Hwnd as long, byval lpstring as _
string, byval cch as long) as Long
Assuming the object in question is a form, passing the hwnd
of the form to the api will cause a search to performed in
windows internal data structures looking for that handle,
and then return what text is in the forms title bar
or caption.
Question
Is there an event that fires when an application loses the
focus (Deactivate fires when a form loses focus to another
form in the same app, but not when I bring another
application to the front).
________________________________________
Answer
No event fires ... but the active window receives the
WM_ACTIVATEAPP message.
Question
How can I close another program?
________________________________________
Answer
You have to use the API - here's a code example, you'll
need to create a CommandButton called "Command1" on a form
and paste this code in. You'll need to modify the function
call under the Command1_Click event to reflect the Window
Caption \ Class you are trying to close.