In VB CDK, LibInit Does Not Allow Local Memory Allocation

ID Number: Q77836

1.00

WINDOWS

Summary:

LIBINIT.ASM provided with the Microsoft Visual Basic Custom Control

Development Kit does not provide support for local memory allocation.

This is because LIBINIT.ASM does not perform a LocalInit Windows API

call to initialize the local heap.

LibInit is an example of the simplest Windows entry routine for use

with custom controls. You can either add the LocalInit Windows API

call to LIBINIT.ASM or use LIBENTRY.ASM provided with the Windows SDK

package instead. Either of these methods will allow a custom control

to perform local memory allocation. The changes to perform either of

these methods is described below.

This information applies to Visual Basic version 1.0 Custom Control

Development Kit (CDK) and to Windows versions 3.0 and 3.0a. The Visual

Basic CDK is now shipped as part of Microsoft Professional Toolkit for

Microsoft Visual Basic version 1.0 for Windows.

More Information:

To use LIBENTRY.ASM instead of LIBINIT.ASM with Visual Basic, you must

modify the LibMain Declare statement provided in CCInit.C routine:

The provided LibMain Declare statement only has three parameters. A

fourth parameter for lpszCmdLine must be added:

BOOL FAR PASCAL LibMain

(

HANDLE hmod,

HANDLE segDS,

USHORT cbHeapSize,

)

must be changed to:

BOOL FAR PASCAL LibMain

(

HANDLE hmod,

HANDLE segDS,

USHORT cbHeapSize,

LPSTR lpszCmdLine

)

If the LibMain Declare statement is not changed and LibEntry is used

with a Visual Basic custom control, it will result in an Unrecoverable

Application Error (UAE) or other unpredictable results.

To modify LIBINIT.ASM to create local heap space, add the following

lines of code to LIBINIT.ASM. Insert the lines after "push cx" and

before "call LibMain":

push cx

; Add the following lines taken from LIBENTRY.ASM

; from Windows 3.0 SDK.

; if we have some heap then initialize it

jcxz callc ; jump if no heap specified

; call the Windows function LocalInit() to set up the heap

; LocalInit((LPSTR)start, WORD cbHeap);

xor ax,ax

cCall LocalInit <ds, ax, cx>

or ax,ax ; did it do it ok ?

jz error ; quit if it failed

; invoke the C routine to do any special initialization

callc:

; End of added code.

call LibMain

After making the changes, LibInit needs to be reassembled with the

Microsoft Macro Assembler.

Additional reference words: 1.00 3.00 3.00a