.DLL loading on startup

so my company is wanting to try Bricscad the first step is porting our tools from autocad to bricscad. I made several tools using VB.Net in autocad and in autocad to get them loaded on startup I needed to register the .dll in the registry. I made a piece of code for that (pasted the autodesk version below). now the first problem I run into is that I cannot find the registrykey and registry class Imports (Bold parts) for bricscad. can someone point out where I can find those or if there is another method used with bricscad?
_
Imports RegistryKey = Autodesk.AutoCAD.Runtime.RegistryKey
Imports Registry = Autodesk.AutoCAD.Runtime.Registry

<CommandMethod("RegisterUPACadApps")>
Public Sub RegisterMyApp()
'' Get the AutoCAD Applications key
Dim sProdKey As String = HostApplicationServices.Current.MachineRegistryProductRootKey
Dim sAppName As String = "UPACadApps"

    Dim regAcadProdKey As RegistryKey = Registry.CurrentUser.OpenSubKey(sProdKey)
    Dim regAcadAppKey As RegistryKey = regAcadProdKey.OpenSubKey("Applications", True)

    '' Check to see if the "MyApp" key exists
    Dim subKeys() As String = regAcadAppKey.GetSubKeyNames()
    For Each sSubKey As String In subKeys
        '' If the application is already registered, exit
        If (sSubKey.Equals(sAppName)) Then
            regAcadAppKey.Close()

            Exit Sub
        End If
    Next

    '' Get the location of this module
    Dim sAssemblyPath As String = Assembly.GetExecutingAssembly().Location

    '' Register the application
    Dim regAppAddInKey As RegistryKey = regAcadAppKey.CreateSubKey(sAppName)
    regAppAddInKey.SetValue("DESCRIPTION", sAppName, RegistryValueKind.String)
    regAppAddInKey.SetValue("LOADCTRLS", 14, RegistryValueKind.DWord)
    regAppAddInKey.SetValue("LOADER", sAssemblyPath, RegistryValueKind.String)
    regAppAddInKey.SetValue("MANAGED", 1, RegistryValueKind.DWord)

    regAcadAppKey.Close()
End Sub

_

Comments

  • James Maeding
    edited April 2020

    Interesting, you prefer to load via registry as opposed to On_doc_load.lsp or On_start.lsp?
    Is that because its all you are familiar with, or you don't use those lisps, or want it hidden to users that know lisp?
    I much prefer those lisps for doing things at startup, as I can troubleshoot things by simply renaming them or editing them to get rid of whatever.
    You use (command "netload" dllname...)
    With reg stuff, it loads in all profiles so not much control, which may be exactly what you want...
    anyway, some useful threads I looked up on this are:
    theswamp.org/index.php?topic=31173.msg367509#msg367509
    That uses lisp to make the key (strcat "HKEY_CURRENT_USER\" (vlax-product-key) "\Applications\"...)

    I don't think your question is really something limited by the bricscad .net API though. If you know where you want to do reg stuff, you can do it with regular .net tools. I prefer that anyway for exactly this situation. Keepit generic instead of cad platform specific.
    Code like:
    Microsoft.Win32.RegistryKey Key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(prefix + "\" + appname, true);
    will let you do what you need.
    You may have to do a couple statements assembling the actual reg path, but that should be easy.
    Also, you may consider switching to C# as the majority of experienced .net people use it. I switched just to get better support, and its more compact IMO.

  • James Maeding
    edited April 2020

    @Fyer BTW, My favorite thing is helping people trying to transition to bcad. I have tons of in-house lisp and .net code that I dd this for, and the end result is super easy to maintain. I'm a c# guy, so one cool thing you can do is put runtime var if statements at the top, for your imports (C# is using...):
    so for the cad related references, like:
    (ignore the ' characters, had to use that to get formatting to behave..)
    '#if ACAD
    using Autodesk.AutoCAD.Runtime;
    using Autodesk.AutoCAD.ApplicationServices;
    using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;
    using Autodesk.AutoCAD.EditorInput;
    using AcEd = Autodesk.AutoCAD.EditorInput;
    using Autodesk.AutoCAD.DatabaseServices;
    using AcDb = Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.Geometry;
    using AcGe = Autodesk.AutoCAD.Geometry;
    using AcCo = Autodesk.AutoCAD.Colors;
    using Autodesk.AutoCAD.Windows;
    using Autodesk.AutoCAD.GraphicsInterface;
    '#endif
    '#if BCAD
    using Teigha.DatabaseServices;
    using AcDb = Teigha.DatabaseServices;
    using Bricscad.EditorInput;
    using AcEd = Bricscad.EditorInput;
    using Teigha.Geometry;
    using AcGe = Teigha.Geometry;
    using AcCo = Teigha.Colors;
    using Teigha.Runtime;
    using Teigha.GraphicsInterface;
    using Bricscad.Runtime;
    using Bricscad.ApplicationServices;
    using AcAp = Bricscad.ApplicationServices.Application;
    using Bricscad.Windows;
    '#endif'

    So by doing that, AcGe and other aliaseseses can be used for both platforms.
    those ACAD and BCAD variables are set at the project level. So I have a different project for acad and bcad, but they all use the same code files.
    You can use those #if statements within your code too, to essentially switch out code that is specific to acad or bcad.

    I'd love to see you get things working as life is better with an acad alternative, cost aside. I regularly open dwg's in bcad just to see if they behave better than acad when troubleshooting. Bcad typically wins, and its audit fixes stuff acad misses.

  • In BricsCAD you can use ARXLOAD to load BRX or TX or NET.

    Another alternative is to create a autoload.rx file and put it on your support file search path. This is a simple text file containing the path and file name of the application you want to load. e.g.
    ; Autoload.rx ; Myapplication V20 C:\Program Files\MyprogramFolder\Myapplication.dll

    The advantage to using a bit of LISP is that you can use it to determine which file to load for the particular CAD platform & version. Here is an example based around loading DOSLIB.

    ; DOSLIBLOADER ; Function to load DOSLib. ; DOSLib extends AutoLISP, providing a large number of additional functions ; Source: ; https://wiki.mcneel.com/doslib/home ; (defun DOSLibLoader (/ prog acad ext proc fname) ; Retrieve CAD platform details (setq prog (getvar "Program")) ; Determine the version of the CAD Application ; and the arx file type to use (cond ; BricsCAD ((= prog "BRICSCAD") (setq acad (substr (getvar "_VERNUM") 1 2)) (setq ext ".brx") ) ; AutoCAD ((= prog "acad") (setq acad (substr (getvar "ACADVER") 1 2)) (setq ext ".arx") ) ) ; Determine the system's processor architecture (setq proc (= "AMD64" (getenv "PROCESSOR_ARCHITECTURE"))) ; Build a file name string (if proc (setq fname (strcat "DOSLib" acad "x64" ext)) (setq fname (strcat "DOSLib" acad ext)) ) ; If found on the search path, load it (if (findfile fname) (arxload fname nil) (prompt (strcat "\n" fname " not found.")) ; Otherwise prompt that it's missing ) (princ) )

    Regards,
    Jason Bourhill
    BricsCAD V20 Ultimate
    CAD Concepts

  • @Jason Bourhill said:
    In BricsCAD you can use ARXLOAD to load BRX or TX or NET.

    Another alternative is to create a autoload.rx file and put it on your support file search path. This is a simple text file containing the path and file name of the application you want to load. e.g.
    ; Autoload.rx ; Myapplication V20 C:\Program Files\MyprogramFolder\Myapplication.dll

    I made the Autoload.RX file in a folder as you suggested and put it in my support file search path. but I cannot figure out how to make Bricscad load this file so it will load the .dll mentioned in it.

    As a side note: ARXLOAD is not working for me, I am using Bricscad Pro, according to our reseller it should contain ARX-loading. but I am getting this message: "Unable to recognize command "ARXLOAD". This error can occur when the command is not supported for the active license."

  • @James Maeding said:
    @Fyer BTW, My favorite thing is helping people trying to transition to bcad. I have tons of in-house lisp and .net code that I dd this for, and the end result is super easy to maintain. I'm a c# guy, so one cool thing you can do is put runtime var if statements at the top, for your imports (C# is using...):
    so for the cad related references, like:
    (ignore the ' characters, had to use that to get formatting to behave..)
    '#if ACAD
    using Autodesk.AutoCAD.Runtime;
    using Autodesk.AutoCAD.ApplicationServices;
    using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;
    using Autodesk.AutoCAD.EditorInput;
    using AcEd = Autodesk.AutoCAD.EditorInput;
    using Autodesk.AutoCAD.DatabaseServices;
    using AcDb = Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.Geometry;
    using AcGe = Autodesk.AutoCAD.Geometry;
    using AcCo = Autodesk.AutoCAD.Colors;
    using Autodesk.AutoCAD.Windows;
    using Autodesk.AutoCAD.GraphicsInterface;
    '#endif
    '#if BCAD
    using Teigha.DatabaseServices;
    using AcDb = Teigha.DatabaseServices;
    using Bricscad.EditorInput;
    using AcEd = Bricscad.EditorInput;
    using Teigha.Geometry;
    using AcGe = Teigha.Geometry;
    using AcCo = Teigha.Colors;
    using Teigha.Runtime;
    using Teigha.GraphicsInterface;
    using Bricscad.Runtime;
    using Bricscad.ApplicationServices;
    using AcAp = Bricscad.ApplicationServices.Application;
    using Bricscad.Windows;
    '#endif'

    So by doing that, AcGe and other aliaseseses can be used for both platforms.
    those ACAD and BCAD variables are set at the project level. So I have a different project for acad and bcad, but they all use the same code files.
    You can use those #if statements within your code too, to essentially switch out code that is specific to acad or bcad.

    I'd love to see you get things working as life is better with an acad alternative, cost aside. I regularly open dwg's in bcad just to see if they behave better than acad when troubleshooting. Bcad typically wins, and its audit fixes stuff acad misses.

    Thanks James,

    I tried using this in my program but it ended up producing a lot of errors and double namespaces. the main problem I am having is with the first lines in every Sub I am using.
    Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
    Dim acCurDb As Database = acDoc.Database
    Dim acEd As Editor = acDoc.Editor

    I cant seem to rewrite the subs using the declerations you mentioned above.

    As for the C# I see a lot of people doing code in C#, as I am more of an engineer and learned myself programming I found using vb.net easier (the first programming job I did was converting a VBA program to VB.NET). still figuring out what good practices are and what makes it easy to maintain programs. also not sure if putting all my tools in one big file is the smartest thing to do.

  • @James Maeding said:
    Interesting, you prefer to load via registry as opposed to On_doc_load.lsp or On_start.lsp?
    Is that because its all you are familiar with, or you don't use those lisps, or want it hidden to users that know lisp?
    I much prefer those lisps for doing things at startup, as I can troubleshoot things by simply renaming them or editing them to get rid of whatever.
    You use (command "netload" dllname...)
    With reg stuff, it loads in all profiles so not much control, which may be exactly what you want...
    anyway, some useful threads I looked up on this are:
    theswamp.org/index.php?topic=31173.msg367509#msg367509
    That uses lisp to make the key (strcat "HKEY_CURRENT_USER\" (vlax-product-key) "\Applications\"...)

    I don't think your question is really something limited by the bricscad .net API though. If you know where you want to do reg stuff, you can do it with regular .net tools. I prefer that anyway for exactly this situation. Keepit generic instead of cad platform specific.
    Code like:
    Microsoft.Win32.RegistryKey Key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(prefix + "\" + appname, true);
    will let you do what you need.
    You may have to do a couple statements assembling the actual reg path, but that should be easy.
    Also, you may consider switching to C# as the majority of experienced .net people use it. I switched just to get better support, and its more compact IMO.

    I completely missed this message. Think this might help me. for autocad you could actually enter the register pretty easy with the above code, but if I am able to rewrite it using only regular .net tools it should be easy to make it work for both files.

    the reason I registerd the DLL was so that when I update the tools (removing bugs adding new things ect.) I could just replace the current DLL on our network drive and have everyone in the company automatically get the new version. Getting 20 draftsman to all unload their current stuff and reload the new is a nightmare.

    As to why I am using vb.net see my last post.

  • James Maeding
    edited April 2020

    @Fyer
    I'm also an engineer that learned programming because it was useful, though I did grow up doing hobby level programming on apple II+, 286, 386...
    What I found though, is the good programmers in the cad arena consider VB.net ugly to look at. I started in vb.net, wrote quite a bit, then switched.
    I still have a fair amount of vb.net code but VS likes one flavor within an assembly so there is that.
    You may think the code I posted about using statements is a level of complexity that causes headaches, but you will find you have stumbled onto a gold nugget. I'm thinking almost for sure you did not set the "preprocessor directive" variable BCAD in your project. Google that to see how to do it, will take 1 minute.
    Maintaining minimal code sets is critical, and so slick once you get it going. I also use them for acad/bcad version issues, where in one version a method exists, and not in another. You cannot just use normal if...as the compiler says the missing method is, missing.
    So keep on the .net learning curve, it will get simpler fairly soon it seems to me based on your progress.
    Now, on the part about maintaining your tools on the network, I would not do that.
    It is exactly the first idea most cad managers have, and works well for what I call "libraries of data", but you are putting yourself in a corner for a set of tools. Instead, make a master folder of tools on the network. Then set up a batch file to robocopy that to the users' C drive.
    Set your support paths to the C drive folders, not network.
    Have the batch file run on login, before they cad start up cad.
    If you do that, you will find you can fix and update your tools on the server at any time. Without that, those dll's loaded from server are locked. You have to wait til everyone is out to update them - a horrible thing in a pinch when you discover some bug before lunch.
    Also, the user can hack their system to pieces, and just close acad, run batch, and start again and all is healed.
    Works on laptops without internet/VPN, and so on. Its another gold nugget I've seen many people reject, but gold is gold.