Author Topic: Lauching Autocad from a VB exe? No luck...  (Read 19893 times)

0 Members and 1 Guest are viewing this topic.

Dnereb

  • Guest
Re: Lauching Autocad from a VB exe? No luck...
« Reply #15 on: April 26, 2006, 05:28:03 PM »
Havano,

You and I are on diffrent wave lengths on some things (I'm referring to what I wrote in my post and what you red in my post no more)
the $$$$ signs mend you could make a friendly way to persuade your customer to upgrade the software you are writing instead of locking or flunking. No more. I wasn't fishing for any deal.

perhaps the "it would help"should be: it would help to make that friendly error message and keeping control over what happens on your customers machine.... like a hyperlink to a mail to you so your customer could contact you easy and fast...etc etc.

I can however provide both exe's and the more efficient way... a dll's compiled in VB6.0 sp6

But I'm sure many members can. My suggestion to you is to really think through what you need, ask some questions on the difference between VB 6.0. and Acad vba because there are some. and carefully writ out the demands, needs options and so one you want... And post a assignment so everyone intrested can bid on it.




havano

  • Guest
Re: Lauching Autocad from a VB exe? No luck...
« Reply #16 on: April 27, 2006, 01:40:26 AM »
Thanks Keith and Dnereb for your reaction.
Sorry for removing my most recent posting, to which you reacted. When I woke op just now, I read it back and wasn't very proud of it. It was written in a "sinking state of mind". Please don't remove your reactions, they have been -and are- very helpful.

You are right Dnereb, I have had trouble understanding what you mean. It may have to do with me being a novice at VB(A) programming and with English not being my native language.

The bulk of the program I'm writing has little to do with Autocad anyway. The user must input some preferences and parameter values, VB(A) will do some sheet material cost-optimization and parametric drawing. It's hardly rocket science... There may be some other issues I would like to have your advice on. They will be posted as separate topics when they come up.

I wonder, has this binding issue already been discussed recently elsewhere on this forum? I did't find any, but maybe I wasn't looking in the right places. Or is the subject so trivial that no-one thinks it's worth mentioning?

Again Keith, Dnereb and Bryco, thanks for your highly appreciated help!
« Last Edit: April 27, 2006, 02:44:23 AM by havano »

Dnereb

  • Guest
Re: Lauching Autocad from a VB exe? No luck...
« Reply #17 on: April 27, 2006, 02:46:54 AM »
Don't worry I'm no native American/English speaker as well. so you can put some of the misunderstandingd at my account as well.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Lauching Autocad from a VB exe? No luck...
« Reply #18 on: April 27, 2006, 08:21:17 AM »
To my knowledge, late binding has not been discussed at any length here.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Draftek

  • Guest
Re: Lauching Autocad from a VB exe? No luck...
« Reply #19 on: April 27, 2006, 09:48:03 AM »
You will be better off forgetting the late binding and simply re-compiling your code every 3 years for a new compilation of the autocad type library.

In other words - an app that uses autocad.16 is good for 2004, 2005 and 2006.

By the time you need to recompile your probably not going to be using vb6 anyway.

Dnereb

  • Guest
Re: Lauching Autocad from a VB exe? No luck...
« Reply #20 on: April 27, 2006, 10:23:04 AM »
Can you tell me why?
-you shouldn't use a dlll with late binding.
-why recompiling is better as writing code that wil run always no matter what version.
-You have to rewrite an app in VB 6.0 or in this case VBA into VB.net.

I will dig in .net this year but I can imagine myself maintaining apps written in VB6 in VB6 to avoid re writing for several weeks to add a little option button.

Draftek

  • Guest
Re: Lauching Autocad from a VB exe? No luck...
« Reply #21 on: April 27, 2006, 10:34:21 AM »
I'm a little confused over all your questions but to answer the main one:

Two words: Maintenance Nightmare.

Unless your project is tiny, the idea of replacing all autocad object references to object and then working on said project at a later date would be confusing or require having two projects synced. Either way I don't think it's a good idea.

Personally, I have built quite a large autocad dll utility app that I drop into my programs for use. I cannot imagine having to maintain all generic objects in it and totally wiping out my intellisense.

Not to mention there are features added in new compiles that will not work with older versions so knowing the version can be important.

I currently have two dll's one pre 2004 and one 2004 to 2006. I will drop the old one this year and add a new managed one for C#. I have about 1,000 apps deployed and have had no problems with having two versions of the programs provided on the cd's.

havano

  • Guest
Re: Lauching Autocad from a VB exe? No luck...
« Reply #22 on: April 27, 2006, 10:37:28 AM »
Hi Draftek,

If early binding is not the cause my VB test program returns errors when run by the customer, then wat is? Both he and I are using Autocad 2006, so the type libraries should be the same. The only problem I can see, is that his system also contains Autocad 2006 LT and Autocad R14.

And so we return to my original question!
« Last Edit: April 27, 2006, 04:43:25 PM by havano »

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Lauching Autocad from a VB exe? No luck...
« Reply #23 on: April 27, 2006, 10:55:19 AM »
Unless your project is tiny, the idea of replacing all autocad object references to object and then working on said project at a later date would be confusing or require having two projects synced. Either way I don't think it's a good idea.
I am working on a project that contains collectively 16000 lines of code and over 200 individual files. I always utilize late binding because it makes my program work on multiple versions ... This application is deployed over all versions from R2000 to R2007 without any issues ...

Personally, I have built quite a large autocad dll utility app that I drop into my programs for use. I cannot imagine having to maintain all generic objects in it and totally wiping out my intellisense.

IF you are familiar enough with the object model, you will find that you don't need the intellisense


Not to mention there are features added in new compiles that will not work with older versions so knowing the version can be important.

Indeed, which is why late binding is so great. If you cannot accurately predict what the client is going to do, then you MUST know your job and you MUST know the differences, otherwise you run the risk of appearing as a novice to your client.

I currently have two dll's one pre 2004 and one 2004 to 2006. I will drop the old one this year and add a new managed one for C#. I have about 1,000 apps deployed and have had no problems with having two versions of the programs provided on the cd's.
I currently have one single application that works on multiple versions and I only have a single version to maintain.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Draftek

  • Guest
Re: Lauching Autocad from a VB exe? No luck...
« Reply #24 on: April 27, 2006, 11:12:00 AM »
havano: I'm not sure what your problem is because I'm not sure how your project is set up, but the 429 error can be deceiving the dll not loading may not be yours. Did you register your dll on the users's machine?

I have some startup code I have used for years without fail but I don't feel comfortable posting it because I did not write all of it.

You might try writing your app as a dll and passing the autocad application to it from a vba macro. That's the way I do 90% of my stuff.

Keith: I think it's better if I don't address your post...

LE

  • Guest
Re: Lauching Autocad from a VB exe? No luck...
« Reply #25 on: April 27, 2006, 11:28:29 AM »
Here is what I neophyte in VB used some time ago...

Code: [Select]
Option Explicit
Option Compare Text
Declare Function RegQueryValueEx& Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey&, ByVal lpszValueName$, ByVal lpdwRes&, lpdwType&, ByVal lpDataBuff$, nSize&)
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
      "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
      String, ByVal lpszFile As String, ByVal lpszParams As String, _
      ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
      Private Declare Function GetDesktopWindow Lib "user32" () As Long



Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_CLASSES_ROOT = &H80000000
Const KEY_QUERY_VALUE = &H1&
Const KEY_ENUMERATE_SUB_KEYS = &H8&
Const KEY_NOTIFY = &H10&
Const READ_CONTROL = &H20000
Const STANDARD_RIGHTS_READ = READ_CONTROL
Const KEY_READ = STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY
Const SW_SHOWNORMAL = 1
Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&

Private Function GetAppPath(subkey As String, sAppEntry As String) As String
Dim s As String * 255, sAppPath As String
Dim lAppKey As Long, lType As Long, lLen As Long, lRC As Long
    lLen = Len(s)
    lRC = RegOpenKeyEx(HKEY_CLASSES_ROOT, sAppEntry, 0, KEY_READ, lAppKey)
    If lRC <> 0 Then Exit Function
    lRC = RegQueryValueEx( _
            lAppKey, _
            subkey, _
            0, _
            lType, _
            s, _
            lLen)
    's = Left$(s, lLen - 6)
    GetAppPath = Mid(s, 2, lLen - 8) 'Left$(s, lLen - 5)
End Function

 Function StartDoc(DocName As String, Param As String, Dir As String) As Long
          Dim Scr_hDC As Long
          Scr_hDC = GetDesktopWindow()
          StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
          Param, Dir, SW_SHOWNORMAL)
      End Function

Sub Main()
   
   Dim version As String
   Dim result As Boolean
   Dim sAcadEntry As String
   
   On Error Resume Next
   
   sAcadEntry = "AutoCAD.Drawing.16\shell\open\command"
   version = GetAppPath("", sAcadEntry)
   
   If StrConv(version, 1) Like "*ACAD.EXE" <> True Then
    MsgBox ("El programa AutoCAD Ver. 2004 no se encuentra instalado. \nPor favor refiérase al Manual del Usuario.")
    End
   End If
   
   'result = Shell(version & " /b draftteam.scr", 1)
   Dim r As Long, msg As String, Dir As String
          Dir = App.Path
          r = StartDoc(version, " /b draftteam.scr", Dir)
          If r <= 32 Then
              'There was an error
              Select Case r
                  Case SE_ERR_FNF
                      msg = "Archivo ejecutable de AutoCAD no encontrado."
                  Case SE_ERR_PNF
                      msg = "Ruta de AutoCADno encontrada"
                  Case SE_ERR_ACCESSDENIED
                      msg = "Acceso denegado de AutoCAD"
                  Case SE_ERR_OOM
                      msg = "Memoria insuficient"
                  Case SE_ERR_DLLNOTFOUND
                      msg = "DLL no encontrado"
                  Case SE_ERR_SHARE
                      msg = "Error de memoria"
                  Case SE_ERR_ASSOCINCOMPLETE
                      msg = "Incompleta o asociación de archivo inválida."
                  Case SE_ERR_DDETIMEOUT
                      msg = "DDE finalizó"
                  Case SE_ERR_DDEFAIL
                      msg = "Transacción DDE fallida."
                  Case SE_ERR_DDEBUSY
                      msg = "DDE ocupado"
                  Case SE_ERR_NOASSOC
                      msg = "No hay asociación para extensión de archivo."
                  Case ERROR_BAD_FORMAT
                      msg = "Ejecutable inválido."
                  Case Else
                      msg = "Error desconocido."
              End Select
              MsgBox msg
              End
          End If
   'wait 20 seconds to let AutoCAD open
   Dim TimeNow As Double
   Dim TimeEnd As Double
   TimeNow = Hour(Now()) + (Minute(Now()) / 60#) + (Second(Now()) / 3600#)
   TimeEnd = TimeNow + (20# / 3600#)
   
   
   Dim objAcad As Object
   Set objAcad = GetObject(, "AutoCAD.Application")
   
   While TimeNow < TimeEnd And (objAcad Is Nothing = True)
      Set objAcad = GetObject(, "AutoCAD.Application")
      TimeNow = Hour(Now()) + (Minute(Now()) / 60#) + (Second(Now()) / 3600#)
   Wend
 
   Dim preferences As Object
   Set preferences = objAcad.preferences
   Dim sPath As String
   sPath = preferences.Files.SupportPath
   If sPath <> "" Then
   Dim DttPath As String
   DttPath = objAcad.ActiveDocument.GetVariable("DWGPREFIX")
   Dim LDttPath As Integer
   LDttPath = Len(DttPath)
   If Right(DttPath, 1) = "\" Then
        DttPath = Left(DttPath, LDttPath - 1)
   End If
   'Add the path if does not exist
   If StrConv(sPath, 1) Like "*" & StrConv(DttPath, 1) & "*" <> True Then
        preferences.Files.SupportPath = sPath & ";" & DttPath
   End If
   End If
   Set objAcad = Nothing
   Set preferences = Nothing
   
End Sub

Then, having a filename.SCR to call a lisp file to be loaded....

HTH.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Lauching Autocad from a VB exe? No luck...
« Reply #26 on: April 27, 2006, 11:36:50 AM »
I just had a thought ... it may not be the AutoCAD object at all .. if you are referencing ANY files on your system, any type libraries that your client DOES NOT have, then it may throw the 429 error. The best way to identify if that is the problem, you should remove any unused references from your compiled executable, identify the referenced file names and versions, then request that your client identify that he has those files installed. The 13 error is a whole lot more incidious. It can be something as simple as an unexpected data type, a missing registry setting, or a missing file.

Draftek: I understand .. as is your perogative
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

havano

  • Guest
Re: Lauching Autocad from a VB exe? No luck...
« Reply #27 on: April 27, 2006, 03:02:35 PM »
Thanks LE, I will try to decipher the code you posted, maybe a little higher up on my learning curve of VB and Spanish.

You may be right there, Keith. In the references list I checked a lot of libraries that I thought might have something to do with Autocad. If I didn't actually use a reference it wouldnt hurt either, I thought. Maybe I thought wrong.

On the other hand, I tried my test programs on a PC with nothing but Windows XP Home Edition and a typical install of Autocad 2006, and they al worked fine. Would it matter if my customer used XP Professional? I use a function that calls the user32.dll in order to keep my VB-form on top even after Autocad opens:
Code: [Select]
Declare Function SetWindowPos Lib "user32" _
  (ByVal hwnd As Long, _
  ByVal hWndInsertAfter As Long, _
  ByVal x As Long, ByVal y As Long, _
  ByVal cx As Long, ByVal cy As Long, _
  ByVal wFlags As Long) As Long
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Could that cause the problem?

This answers your question as well Draftek, in my test programs (.EXE) I only call this user32.dll and the generic Autocad library/libraries. Shouldn't they all have been registered during the Windows and Autocad install?
« Last Edit: April 27, 2006, 03:10:05 PM by havano »

Dnereb

  • Guest
Re: Lauching Autocad from a VB exe? No luck...
« Reply #28 on: April 27, 2006, 03:30:19 PM »
user32.dll is on my XP pro system and shouldn't be a problem. If you doubt avalibility you could check on www.allapi.net
they have good documentation on Api's download and install the .chm and you can use it as a documentation and library on API's. It also includes info on what api is availeble on which windows platform.
I still think your line:
Public AcadObj As AcadApplication
is the killer because it's a public and evaluated before you probably realize.
(read about the scope of variables to figer out why)



havano

  • Guest
Re: Lauching Autocad from a VB exe? No luck...
« Reply #29 on: April 27, 2006, 04:05:24 PM »
Hi again Dnereb,

My test program consists essentially of the code I posted earlier (3 commandbuttons in a single form) and hereabove (one function in a single module). So I could easily declare it as private. I just did, no problem here. Would that do the trick in my customer's environment? Having (re)read the scope tutorial I still don't see why.
« Last Edit: April 27, 2006, 04:11:52 PM by havano »