|
-
April 6th, 1999, 04:30 PM
#1
How to create a VB app as an OLE server ?
Urgent.
Please show me how to create a VB application as an OLE server since I need to expose some methods/properties to other applications using OLE automation.
Please help. Thanks.
David.
David
-
April 6th, 1999, 04:49 PM
#2
Re: How to create a VB app as an OLE server ?
Hi
1. When you start VB5/6, choose New->ActiveX EXE
2. This will then create a project with a class module - rename this to MyClass
3. Add the following code to MyClass
Public Sub DoSomeThing()
MsgBox "Doing Something..."
End Sub
4. Now go to Project->Properties
5. In the 'Project Name' textbox, change the name to MyProject
6. Now save the whole project somewhere
7. Now go to File->Make MyProject.Exe
Now you need to create a Client Application
1. Start a New Instance of VB5/6
2. Choose Standard EXE
3. Goto Project->References
4. Scroll down until you see MyProject.Exe (or just browse till you find the EXE file)
5. Now, add a Button to Form1 called Command1
6. In the Command1_Click event :
Dim oObject As MyClass
Set oObject = New MyClass
oObject.DoSomeThing
Set oObject = Nothing
That's all there is to it (well, nearly all.....)
Regards
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb
-
April 7th, 1999, 11:08 AM
#3
Re: How to create a VB app as an OLE server ?
Great! Your help is clear and easy to do.
I did and it worked.
Another question related to this is:
I had a standard EXE (VB app), and I'd like to make it an OLE server, I changed its properties to ActiveX.EXE and Startup Object to be Sub Main. Inside Sub Main, I add the code to load the my frmMain and show it, so when the app starts it will show the frmMain, but it did not.
Can you show me how to do it ?
Generally, I like to have a VB application with forms and OLE automation enable and when I run the app, it will bring up the frmMain.
(If it can not be done, I guess I have to expose a method that will load and show the form)
Again, thank you very much.
David.
David
-
April 7th, 1999, 03:19 PM
#4
Re: How to create a VB app as an OLE server ?
Hi
>Another question related to this is:
>I had a standard EXE (VB app), and I'd like to make it
>an OLE server, I changed its properties to ActiveX.EXE and
>Startup Object to be Sub Main. Inside Sub Main, I add the code to
>load the my frmMain and show it, so when the app starts it will
>show the frmMain, but it did not.
>Can you show me how to do it ?
Now this all depends on how the ActiveX EXE is started. Basically, you
can start an ActiveX EXE in two ways -
- By double clicking on the Icon (usual method)
- By using the Object Model (ie. CreateObject etc)
You can determine which method was used to start your application using
the App.StartMode property -
-vbSModeStandalone (0)
-VbSModeAutomation (1)
Don't forget, that if you turn an application into an ActiveX EXE and try debugging
it from within VB, absolutely nothing will happen ! - VB expects it to act as an
Automation (ie. OLE/ACTIVEX) server component, so unless a client is using any of the
objects (ie. another instance of VB), then you won't see anything.
>Generally, I like to have a VB application with forms and OLE automation
>enable and when I run the app, it will bring up the frmMain.
>(If it can not be done, I guess I have to expose a method that will load and show the form)
You'll definately have to code two different ways of starting your app - in fact,
it's a bit more in-depth than that. You'll have to design a good object model which
will allow developers access to relevant objects/methods that your app exposes (and
no access to the dangerous ones, eg. a 'DeleteAllEmployees' method).
Take a look at other programs (eg. Excel and Word), and study their object models,
you can learn a lot by the methods they provide and how you could design your
app to interact in a similar way.
A good object model is essential if you are designing an ActiveX Component - it's
something that can be very tricky to wrap around an existing application, but it
is possible with enough thought and effort.
>Again, thank you very much.
No problem
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb
-
April 7th, 1999, 04:02 PM
#5
Re: How to create a VB app as an OLE server ?
Thanks a bunch :-)
I got everything working.
David.
David
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|