The PBWin Help file has more than a few illustrations showing typical coding of CLASSes. What the following code will try to illustrate is the typical skeleton for a COM DLL that can be published and registered. The link in the foregoing post shows working code for a publishable and registrable COM DLL. Some things to be aware of are the few datatypes compliant COM classes do not support. Again see the link in the last post for more notes on that subject.
Code:
'start with standard PBWin template for DLL's #COMPILE DLL #DIM ALL %USEMACROS = 1 #INCLUDE "Win32API.inc" GLOBAL ghInstance AS DWORD 'GUID equates, if you want them fixed values, must be outside of a function or class 'You can get a unique "GUID(number)" inserted from the right click menu (PB IDE's) $MyClassGUID = GUID$("{BF1FD6B3-6151-45BC-9173-CDD0BA08C305}") $MyFirstInterface = GUID$("{F235C6C8-7CD4-420F-8C0D-BDD5841E70BD}") '------------------------------------------------------------------------------- ' Main DLL entry point called by Windows... ' FUNCTION LIBMAIN (BYVAL hInstance AS LONG, _ BYVAL fwdReason AS LONG, _ BYVAL lpvReserved AS LONG) AS LONG SELECT CASE fwdReason CASE %DLL_PROCESS_ATTACH 'Indicates that the DLL is being loaded by another process (a DLL 'or EXE is loading the DLL). DLLs can use this opportunity to 'initialize any instance or global data, such as arrays. ghInstance = hInstance FUNCTION = 1 'success! 'FUNCTION = 0 'failure! This will prevent the EXE from running. CASE %DLL_PROCESS_DETACH 'Indicates that the DLL is being unloaded or detached from the 'calling application. DLLs can take this opportunity to clean 'up all resources for all threads attached and known to the DLL. FUNCTION = 1 'success! 'FUNCTION = 0 'failure! CASE %DLL_THREAD_ATTACH 'Indicates that the DLL is being loaded by a new thread in the 'calling application. DLLs can use this opportunity to 'initialize any thread local storage (TLS). FUNCTION = 1 'success! 'FUNCTION = 0 'failure! CASE %DLL_THREAD_DETACH 'Indicates that the thread is exiting cleanly. If the DLL has 'allocated any thread local storage, it should be released. FUNCTION = 1 'success! 'FUNCTION = 0 'failure! END SELECT END FUNCTION ' '**** BUILD YOUR CLASS HERE **** 'CLASS name [$GUID] [AS COM | AS EVENT] CLASS MyClass $MyClassGUID AS COM ' 'NOTE: Any Instance Variable declares need to be first, not per 9.0 help file. ' example: INSTANCE ClassName AS STRING INSTANCE Something AS LONG ' ... additional INSTANCE declarations if any ' ' Any Class Method code blocks follow the instance variable section, if any. ' example: CLASS METHOD Initialize ClassName = "MyFirstClass" Something = 0 END METHOD ' ... additional CLASS METHOD blocks added in succession ' ' Then the interface blocks follow ' INTERFACE name $GUID [AS EVENT] ' INHERIT IUNKNOWN 'see help for options ' Method and Property code blocks follow the INHERIT statement... ' END INTERFACE ' example: INTERFACE MyFirstInterface $MyFirstInterface INHERIT IUNKNOWN METHOD Startup() ME.Initialize END METHOD ' ... additional METHOD blocks PROPERTY GET SomeValue() AS LONG PROPERTY = Something END PROPERTY ' if a corresponding PROPERTY SET is required, then it MUST immediately ' follow the corresponding PROPERTY GET block PROPERTY SET SomeValue(BYVAL x AS LONG) Somthing = x END PROPERTY ' ... addtional PROPERTY blocks 'add any EVENT SOURCE declaration if you have also coded any corresponding EVENT class(es) 'see the EVENT statement page in the PB Help File for an example of an Event class and the 'EVENT SOURCE statement in a basic class such as this. That help also illustrates how to 'instatiate the events and terminate them with EVENTS FROM and EVENTS END statements. ' EVENT SOURCE interface-name END INTERFACE ' ' ... Additional INTERFACE blocks, if any END CLASS ' ' ... Additional CLASS blocks if any.
Leave a comment: