This is an old revision of the document!
Demo Script: DevCon 2024
Create repo: M:\Repos\NLS\DevCon2024\.hg\
Open twinBASIC > Sample 4
Save as: M:\Repos\NLS\DevCon2024\DevCon2024.twinproj
(in repository folder)
Ignore *.twinproj
files in repository:
- .hgignore
syntax: glob *.twinproj
Set Export Path for Version Control
- Ensure a clean repository with initial commit of .hgignore
- Project > Project Settings…
- Search for "export"
- Check box next to "☑ Project: Export Path"
- Enter text:
${SourcePath}\Source
- This will save the twinBASIC source files to a subfolder named "Source" in the same folder as the .twinproj file itself
- Check box next to "☑ Project: Export After Save" and set value in dropdown to Yes
- Click [Save Changes]
- File > Export Project… to force an initial export
- In TortoiseHg, commit with the following message:
initial export from twinBASIC IDE
- The commit will include over 1,000 files; this is expected
- Most of the committed files come from referenced packages; that's ok
- Remember, "Anything that can lead to a bug in our software belongs in version control."
Test Build From Source in Empty Folder
- Create a new folder:
%tmp%\DevConClone\
- Clone the repository into this folder:
hg clone --verbose ssh://opal//home/gb/repos/devcon2024/ "C:\Users\Mike\AppData\Local\Temp\DevConClone"
- Open a new instance of twinBASIC
- In the _| New |_ tab, click [Import from folder…] then [Open]
- Enter folder name:
%tmp%\DevConClone\Source
then [OK] - File > Save Project As… >
%tmp%\DevConClone\DevCon2024.twinproj
> [Save] - Make any small change to a project file
- Save the project
- Commit the change and push to Opalstack
Test Build From Source for an Existing Project
The twinBASIC IDE appears to currently lack a "Build from Source" method that will overwrite the current .twinproj file with the contents of the "Project: Export Path" setting. As a result, we must use this multi-step workaround:
- In the original repository (
M:\Repos\NLS\DevCon2024
), pull changes from Opalstack - Open a new twinBASIC instance OR go to File > New Project…
- In the _| New |_ tab, click [Import from folder…] then [Open]
- For folder, enter
M:\Repos\NLS\DevCon2024\Source
then click [OK] - Go to File > Save As…
- Save project as
M:\Repos\NLS\DevCon2024\DevCon2024.twinproj
- Click [Yes] when asked to replace the existing file
- Confirm that the project successfully built from source:
- Go to File > Export Project… to force a full export of the source files
- Verify that new "Last Modified" dates have been created in
M:\Repos\NLS\DevCon2024\Source\
- Verify that there are no pending changes in the repository
Create the Tool Window Controls
- Open myToolWindow.tbcontrol
- Select all controls and delete them
- Select form and set the following properties:
- Height: 1700
- Width: 2550
- Create a text box and set the following properties:
- Name:
tbObjName
- Anchors > Right: ☑ True
- Height: 300
- Left: 150
- Text: {blank}
- TextHint:
Object Class Name
- Top: 150
- Width: 2250
- Create a text box and set the following properties:
- Name:
tbCollName
- Anchors > Right: ☑ True
- Height: 300
- Left: 150
- Text: {blank}
- TextHint:
Collection Class Name
- Top: 600
- Width: 2250
- Create a button and set the following properties:
- Name:
btnCreateClass
- Anchors > Right: ☑ True
- Caption:
Create Collection Class
- Height: 450
- Left: 150
- Top: 1050
- Width: 2250
Edit the Code in myToolWindow.twin
- Delete the
Timer1_Timer()
andHelloWorld_Click()
subroutines - Add a Click event handler for btnCreateClass using the code below
Private Sub btnCreateClass_Click() MsgBox "Object class name: " & Me.tbObjName.Text & vbNewLine & _ "Collection class name: " & Me.tbCollName.Text, vbInformation, "Create Class" End Sub
Build and Test the Addin on Same Machine
The following instructions assume a machine with 32-bit Office (e.g., mjw20):
- Ensure "win32" is selected in dropdown
- File > Build
- Creates and registers this file:
M:\Repos\NLS\DevCon2024\Build\DevCon2024_win32.dll
- As part of registration, the following registry key and values are created:
HKEY_CURRENT_USER\SOFTWARE\Microsoft\VBA\VBE\6.0\Addins\DevCon2024.myAddIn\
- Description: "DevCon2024"
- FriendlyName: "DevCon2024"
- LoadBehavior: 3 (3 => Loaded/Load at startup)
HKEY_CLASSES_ROOT\DevCon2024.myAddIn\CLSID
HKEY_CLASSES_ROOT\DevCon2024.myToolWindow\CLSID
HKEY_CLASSES_ROOT\CLSID\{9B80DA6E-8B20-4D53-AE54-430ACFAE987B}
- (Default):
myAddIn
\InProcServer32
- (Default):
M:\Repos\NLS\DevCon2024\Build\DevCon2024_win64.dll
(NOTE: The presence of win64.dll here is likely a result of running the win64 build as shown in the next section) - ThreadingModel: Both
\ProgID
- DEBUG CONSOLE should show this:
- [LINKER] SUCCESS created output file 'M:\Repos\NLS\DevCon2024\Build\DevCon2024_win32.dll'
- [LINKER] → Open Folder (NOTE: this is a clickable link)
- [REGISTER] type-library registration completed. DllRegisterServer() returned OK
- Open Excel or Access
- Press [Alt] + [F11] to go to VBA IDE
Build and Test the Addin on a Different Machine and Bitness
The following instructions assume you are building on a machine with 32-bit Office (mjw20), but installing on a machine with 64-bit Office (e.g., gbm18):
- Ensure "win64" is selected in dropdown
- File > Build
- I copied
M:\Repos\NLS\DevCon2024\Build\DevCon2024_win64.dll
to%fb%\12114\DevCon2024_win64.dll
(I will test registering it tomorrow on gbm18) - Open a non-admin cmd prompt
- Run:
regsvr32 DevCon2024_win64.dll
- Receive message: "DllRegisterServer in DevCon2024_win64.dll succeeded."
- Open Word (or Excel) - The add-in appears.
Copy and Paste Working VBA Code into twinBASIC
- Add a standard code module named "MyModule":
- Right-click Sources > Add > Add Module (.TWIN supporting Unicode)
-
- Copy and paste the GetGuidBasedTempPath code
- Copy and paste the FileWrite code
- Handle "Unrecognized datatype symbol 'Scripting'" error in DIAGNOSTICS pane:
- Go to Project > References
- Switch to "Available COM References" tab
- Search for "script" and then click the "Microsoft Scripting Runtime" reference
- Click [Save Changes]
Add fafalone's WinDevLib Package for API Calls
- Project > References…
- Switch to "Available Packages" tab
- Search for "windows"
- Check box next to "☑ Windows Development Library for twinBASIC vX.Y.ZZZ"
- The package will immediately begin downloading in the background
- When the download finishes, the name will change to "☑ [IMPORTED] Windows Development Library for twinBASIC vX.Y.ZZZ"
- NOTE: "WinDevLib for Implements" is a different package
- Click [Save Changes]
- Comment out (or delete) API `Declare` lines throughout the project
- Be aware that if you used non-standard `Alias` names, you may need to adjust your API calls to match the standard versions used in WinDevLib
- myAddIn.twin:
- Delete
Private Type RECT
structure - Delete
GetClientRect()
function declare
- InterProcess.twin:
- Delete
GetCurrentProcessId()
function declare line… - …through
Type UUID
structure
- MyModule.twin:
- Delete
Sleep
sub declare - Comment out
CoCreateGuid
function declare and highlight the failure to compile due to the stricter typing ofid As UUID
in WinDevLib versusid As Any
in my code - Uncomment the
CoCreateGuid
function to show that explicit API declares override the WinDevLib versions
- Pass Unicode strings directly to API declare functions
- Most string-related API functions have ANSI and Unicode versions ("A" and "W" for "ANSI" and "Wide", respectively)
- Lots of legacy VB6/VBA code use the ANSI version of API functions
- WinDevLib encourages the use of Unicode versions by default
- This means that code that passes input strings to API functions may require wrapping the string in `StrPtr()` (or removing `StrPtr()`) from your existing code
- ☐ Remove
StrPtr()
from calls toFindWindowEx()
in InterProcess.callerApplicationObject - ☐ Convert final argument from
0&
tovbNullString
for calls toFindWindowEx()
in InterProcess.callerApplicationObject