.NET

Reply
*pkirill
Message 11 of 19 (168 Views)

Re: Call vb.net dll from VBA?

05-19-2006 07:00 AM in reply to: *pkirill
To all - thanks for your help with this. I really appreciate the lessons!
I'm still stuck, though...

Okay, so after researching it, I *think* I added a COM Class - or rather
converted my existing class to a COM Class. Like this:

clsLoadDwgList.EventsId)> _
Public Class clsLoadDwgList
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "E7606F7A-8B38-4C5B-8115-B1B608EE9346"
Public Const InterfaceId As String = "BBBF7781-2CC6-457B-B069-47650FC39225"
Public Const EventsId As String = "1DB37C24-9477-48E3-873D-9CEA3737510B"
#End Region

Public Sub New()
MyBase.New()
End Sub

Public Shared blnDullesSpecial As Boolean = False 'Is this a Dulles Project
File
Public Shared blnDullesSpecialAutoCreate As Boolean = False
Public Shared strDrawingName...

Public Sub LoadIni()
intNumber = InStrLast(strDwgListini, "\") 'looks at path to _dwglist.ini and
finds last "\"
strFilePath =.......

And now, I can see clsLoadDwgList as an object(?) in VBA (Dim loadini as New
... gives me a option to select clsLoadDwgList.) But I guess I thought I'd
see another option in the Add References Dialog. Am I still doing something
wrong?

I also found some good information here:
http://msdn2.microsoft.com/en-us/library/57kx88c8.aspx



wrote in message news:5179931@discussion.autodesk.com...
apart from checking 'register for COM interop' you probably need to make
sure that you're using a COM Class, as opposed to just a class... if you add
a new COM Class to your project vs.net will automatically create GUID's
which provide a COM identity.
this should then allow you to add it as a reference in VBA. From my
experience, this works fine on the machine that you're compiling the DLL
from, however, if you are using the dll on other computers you'll need to
Strong Name your app and also load it into the GAC... the easiest way i've
found to do this is to add a new setup/deployment project to your current
project. the setup/deployment msi then does all the strong naming and
loading / registrying your app (DLL file)
Distinguished Contributor
jbooth
Posts: 223
Registered: ‎02-17-2006
Message 12 of 19 (168 Views)

Re: Call vb.net dll from VBA?

05-19-2006 07:16 AM in reply to: *pkirill
What version of Autocad are you trying to use? Are you using the .NET ObjectArx object library?

Autocad 2006 can use the ObjectArx wrappers to declare commands that are defined in a seperate .NET library (like something you write on your own). Older versions require you to write a VBA macro that communicates to your dll via COM interop.

To expose something to com:
- The "Register for COM Interop" checkbox must be enabled
- You must have at least one ComClass with at least one public method that is not a constructor (this can be done by adding a ComClass to your project).

To call it from AutoCad all you should need to do is reference the project and use the following code:

Dim myObject as new MyComClass()
call myObject.RunMyComClassMethod()

There are no special options required when adding your dll as a reference.


I hope this helps, but if not it may be more helpful to us to know exactly what errors you are getting while trying to run the COM class.

Regards,
JB
*pkirill
Message 13 of 19 (168 Views)

Re: Call vb.net dll from VBA?

05-19-2006 08:09 AM in reply to: *pkirill
Well, I think that did it. I have some more work to do in getting things to
clear out once I'm done - like now if I run the app, it load the drawings
into a list, then if I run it again, it loads the list again without
clearing out the first. (Restarting AutoCAD, of course, clears it out. ) But
at least I know it's seeing whole thing...

And I get an unhandled exception: "Cannot access a disposed object. Object
name: 'frmArchive'" This is a form that is called if more than 3 drawings
are selected asking you if you want to archive this set... Do I need to make
a VBA reference to all my forms?


wrote in message news:5180314@discussion.autodesk.com...
What version of Autocad are you trying to use? Are you using the .NET
ObjectArx object library?

Autocad 2006 can use the ObjectArx wrappers to declare commands that are
defined in a seperate .NET library (like something you write on your own).
Older versions require you to write a VBA macro that communicates to your
dll via COM interop.

To expose something to com:
- The "Register for COM Interop" checkbox must be enabled
- You must have at least one ComClass with at least one public method that
is not a constructor (this can be done by adding a ComClass to your
project).

To call it from AutoCad all you should need to do is reference the project
and use the following code:

Dim myObject as new MyComClass()
call myObject.RunMyComClassMethod()

There are no special options required when adding your dll as a reference.


I hope this helps, but if not it may be more helpful to us to know exactly
what errors you are getting while trying to run the COM class.

Regards,
JB
Distinguished Contributor
jbooth
Posts: 223
Registered: ‎02-17-2006
Message 14 of 19 (168 Views)

Re: Call vb.net dll from VBA?

05-19-2006 02:46 PM in reply to: *pkirill
You are trying to call a method on your frmArchive object after it was disposed. Try creating a new one instead, or try not closing it until you know you won't need it any more.

Are you specifically calling the Dispose method in your code somewhere? .The NET framework doesn't really dispose of any objects you create unless there are no references to it. The only way I know of to get this kind of error is to call dispose manually, which usually isn't done unless it's a database connection or file stream.
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 15 of 19 (168 Views)

Re: Call vb.net dll from VBA?

05-20-2006 11:21 AM in reply to: *pkirill
pkirill,

What is it that you are trying to accomplish?
What Version of AutoCAD are you using?
What Version of Visual Studio are you using?
If this is Acad 2005/06/07 why are you not using some managed solution (this may negate the need to set up a com component)?
Why use VBA at all?
Will you post some example code or a sample project?

You are asking very specific questions that are dependant on what versions of AutoCAD/VisualStudio you are using. Unfortunately I don't believe that anyone can help you more than they have if you can't give us some direction.

My point is that we want to help, but it is up to you to accurately describe your problems/questions so we have enough to go on, not just guess.

Regards,
C
*pkirill
Message 16 of 19 (168 Views)

Re: Call vb.net dll from VBA?

05-22-2006 02:01 PM in reply to: *pkirill
Much thanks for your input. Responses to your questions are below.

>What is it that you are trying to accomplish?
I'm trying to run an external vb.net app inside AutoCAD in order to keep it
"in-process" and prevent AutoCAD from bogging down when processing more than
20 or so drawings. This app essentially opens AutoCAD, opens a drawing from
list, and performs one or more actions on that drawing, closes it and then
moves on to the next drawing in the list.

>What Version of AutoCAD are you using?
AutoCAD 2005

>What Version of Visual Studio are you using?
VS 2003

>If this is Acad 2005/06/07 why are you not using some managed solution
>(this may negate the need to set up a com component)?
I'm a .NET newbie and hack and don't know what a "managed solution" means.
And the VB.net app I have already built "works" outside of AutoCAD, but just
bogs down (meaning it goes from taking 10-15 seconds per drawing to 2-3
minutes per drawing) after about 20 drawings.

>Why use VBA at all?
Because otherwise, the app runs "out of process" and starts to bog down. I'm
not 100% sure the "in-process/out-of-process" is the real issue, but it
seems to be the most likely candidate.

>Will you post some example code or a sample project?
It's a big project with several forms, modules, etc. But I'm happy to email
it to anyone who wants to take a real look at it... I'd love for someone to
take a look at it just to tell me how screwed up component organization is!

>You are asking very specific questions that are dependant on what versions
>of AutoCAD/VisualStudio you are using. >Unfortunately I don't believe that
>anyone can help you more than they have if you can't give us some
>direction.

>My point is that we want to help, but it is up to you to accurately
>describe your problems/questions so we have enough to go >on, not just
>guess.

>Regards,
>C
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 17 of 19 (168 Views)

Re: Call vb.net dll from VBA?

05-22-2006 02:31 PM in reply to: *pkirill
pkirill,

I am willing to take a look at your project. Please email it to CougerAC(at)hotmail.com. Replace (at) with the @ symbol. Also, send revelant drawings and some info on what your programs does to them. Hopefully I'll be able to advise on your issue(s).

C
*pkirill
Message 18 of 19 (168 Views)

Re: Call vb.net dll from VBA?

05-23-2006 07:01 AM in reply to: *pkirill
Thanks for your assist - your previous post was the bomb. I reverted back to
a non-hacked up version of the app, added the com class and used your
suggestion int he vba app and - bingo - it worked. Still have a small issue
of the data not clearing after the first use, but I'm working that out...


wrote in message news:5181177@discussion.autodesk.com...
You are trying to call a method on your frmArchive object after it was
disposed. Try creating a new one instead, or try not closing it until you
know you won't need it any more.

Are you specifically calling the Dispose method in your code somewhere? .The
NET framework doesn't really dispose of any objects you create unless there
are no references to it. The only way I know of to get this kind of error is
to call dispose manually, which usually isn't done unless it's a database
connection or file stream.
*pkirill
Message 19 of 19 (168 Views)

Re: Call vb.net dll from VBA?

05-23-2006 07:31 AM in reply to: *pkirill
Thanks for your assist - your previous post was the bomb. I reverted back to
a non-hacked up version of the app, added the com class and used your
suggestion int he vba app and - bingo - it worked. Still have a small issue
of the data not clearing after the first use, but I'm working that out...


wrote in message news:5181177@discussion.autodesk.com...
You are trying to call a method on your frmArchive object after it was
disposed. Try creating a new one instead, or try not closing it until you
know you won't need it any more.

Are you specifically calling the Dispose method in your code somewhere? .The
NET framework doesn't really dispose of any objects you create unless there
are no references to it. The only way I know of to get this kind of error is
to call dispose manually, which usually isn't done unless it's a database
connection or file stream.



--
----------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 95 spam emails to date.
Paying users do not have this message in their emails.
Get the free SPAMfighter here: http://www.spamfighter.com/len
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.