Calling VB DLLs from VC/C++ 
Author Message
 Calling VB DLLs from VC/C++

Hello all,
I am looking for a sample code (or directions to related articles) on how
can I call a VB DLL
from a C/C++ program. If you have also any comments on how this VB DLL can
be called from other MS languages like fortran don't hesitate to send them
too.
Thanks in advance

Iakovos Karakas




Sun, 09 Jan 2000 03:00:00 GMT  
 Calling VB DLLs from VC/C++

VB Dll's are nothing more than OCXs. You would call the
OCXs in C/C++ like any other OCX. Remember that this is an
inprocess component.

Refer to your language manuals on how to call OCXs, if I
remember correctly, this is covered in the Books Online for
VC++
--
---------------------------------------------------------------

www.dunnsys.com
VBScript Help: www.concentric.net/~neurowiz



Quote:
> Hello all,
> I am looking for a sample code (or directions to related articles) on how
> can I call a VB DLL
> from a C/C++ program. If you have also any comments on how this VB DLL
can
> be called from other MS languages like FORTRAN don't hesitate to send
them
> too.
> Thanks in advance

> Iakovos Karakas





Sun, 09 Jan 2000 03:00:00 GMT  
 Calling VB DLLs from VC/C++

Quote:

> Hello all,
> I am looking for a sample code (or directions to related articles) on how
> can I call a VB DLL
> from a C/C++ program. If you have also any comments on how this VB DLL can
> be called from other MS languages like FORTRAN don't hesitate to send them
> too.
> Thanks in advance

> Iakovos Karakas



What do you mean a "VB DLL" VBRUN300.DLL?

Carlos
http://www.simple-sw.com



Mon, 10 Jan 2000 03:00:00 GMT  
 Calling VB DLLs from VC/C++



Quote:
> VB Dll's are nothing more than OCXs. You would call the
> OCXs in C/C++ like any other OCX. Remember that this is an
> inprocess component.

Actually, VB Dll's are much *less* than OCXs (although an OCX is a dll).  A
VB ActiveX dll is the same as a C++ ActiveX dll.  You can call into the VB
dll from C++ the same way you would call into another C++ dll.  The only
caveat is that unless you specify some level of project compatibilty when
you build the VB dll, VB will generate new CLSIDs, IIDs and dispids every
time you rebuild the project.  This means that if you use VC5's #import,
for example, if you rebuild your VB dll, your C++ code will no longer work.

There are a couple of options:

1) Use late binding from C++.  You can create the VB server by progid (via
CLSIDFromProgID, and then CoCreateInstance), and then make all of your
method calls via IDispatch::Invoke.  This can be quite a bit of work.  You
can simplify the task a bit if you are using MFC by wrapping the type
library via ClassWizard, and then by hand replacing all of the hard-coded
dispids with proper calls to IDispatch::GetIDsOfNames.  This is also a
pain.

2) If you are using VB5, you can define your interfaces in an external type
library (via idl and midl or odl and mktyplib), and then use "Implements"
to force your VB server to use specific IIDs and vtable layout.  Then you
can use #import (or your favorite method of calling dual interfaces in
C++), and be assured that as long as the interface defintions remain the
same, your C++ and VB projects will be compatible.  The only detail left is
that for maximum flexibility, you should still create your VB server by
progid instead of by CLSID.

Hope this helps.

Quote:
> ---------------------------------------------------------------

> www.dunnsys.com
> VBScript Help: www.concentric.net/~neurowiz



> > Hello all,
> > I am looking for a sample code (or directions to related articles) on
how
> > can I call a VB DLL
> > from a C/C++ program. If you have also any comments on how this VB DLL
> can
> > be called from other MS languages like FORTRAN don't hesitate to send
> them
> > too.
> > Thanks in advance

> > Iakovos Karakas





Mon, 10 Jan 2000 03:00:00 GMT  
 Calling VB DLLs from VC/C++

Does he mean an ActiveX DLL??

l.ntua.gr>...

Quote:
>Hello all,
>I am looking for a sample code (or directions to related articles) on how
>can I call a VB DLL
>from a C/C++ program. If you have also any comments on how this VB DLL
can
>be called from other MS languages like FORTRAN don't hesitate to send
them
>too.
>Thanks in advance

>Iakovos Karakas





Tue, 11 Jan 2000 03:00:00 GMT  
 Calling VB DLLs from VC/C++

Yes I believe he does.



Quote:
> Does he mean an ActiveX DLL??
>  Iakovos Karakas wrote in article


Quote:
> l.ntua.gr>...
> >Hello all,
> >I am looking for a sample code (or directions to related articles) on
how
> >can I call a VB DLL
> >from a C/C++ program.

[...]


Tue, 11 Jan 2000 03:00:00 GMT  
 Calling VB DLLs from VC/C++



Quote:
> Yes I believe he does.

Well, you just write a VB ActiveX dll, and use the new VC 5 #import to
access it:

#import "C:\\sources\\w6servicescheduler\\output\\W6RPC.dll"
rename_namespace("GOLDBERG")

#include <stdio.h>
#include <tchar.h>
#include <iostream.h>

struct StartOle {
    StartOle() { CoInitialize(NULL); }
    ~StartOle() { CoUninitialize(); }

Quote:
} _inst_StartOle;

long callvb(char *strMsg)
{
        long lResult;

        using namespace GOLDBERG;

        try
        {
                _W6MessagePtr pXL("W6Rpc.W6Message"); // that's VB ActiveX DLL object
                _bstr_t bs(strMsg);
                lResult = pXL->SendMessage(bs);
                cout << lResult << endl;
    } catch (_com_error &e)
        {
        dump_com_error(e);
                return -1;
    }

        return lResult;

Quote:
}



Fri, 14 Jan 2000 03:00:00 GMT  
 Calling VB DLLs from VC/C++

First read...
 VB4DLL.TXT
 VB5DLL.TXT
Then look for all information about...
 OLEAUTO.H
There's a neat sample somewhere (on MSDN, I think), that makes a simple
HELLO app call to a OLE server.  It can be easily modified to call any VB
OLE server-app/dll.  And it's in C!!!
Or look in the VC help:
------------------------------------------
Visual Basic provides full support for OLE Automation. The following table
lists how Visual Basic statements translate into OLE APIs.
Visual Basic Statement  OLE APIs
CreateObject    CLSIDFromProgID
                CoCreateInstance
                QueryInterface to get IDispatch interface.
GetObject       CLSIDFromProgID
                CoCreateInstance
                QueryInterface for IPersistFile interface.
                Load on IPersistFile interface.
                QueryInterface to get IDispatch interface.
GetObject       CreateBindCtx creates the bind context for the subsequent
functions.
                MkParseDisplayName returns a moniker handle for BindMoniker.
                BindMoniker returns a pointer to the IDispatch interface.
                Release on moniker handle.
                Release on context.
GetObject       CLSIDFromProgID
                GetActiveObject on class ID.
                QueryInterface to get IDispatch interface.
Dim x As New interface  Find CLSID for interface.
                        CoCreateInstance
                        QueryInterface

Quote:
> >  Iakovos Karakas wrote in article

> > l.ntua.gr>...
> > >Hello all,
> > >I am looking for a sample code (or directions to related articles) on
> how
> > >can I call a VB DLL
> > >from a C/C++ program.
> [...]



Fri, 14 Jan 2000 03:00:00 GMT  
 Calling VB DLLs from VC/C++

Quote:


> > Hello all,
> > I am looking for a sample code (or directions to related articles) on how
> > can I call a VB DLL
> > from a C/C++ program. If you have also any comments on how this VB DLL can
> > be called from other MS languages like FORTRAN don't hesitate to send them
> > too.
> > Thanks in advance

> > Iakovos Karakas


> What do you mean a "VB DLL" VBRUN300.DLL?

No. With VB 4.0 and 5.0 you can make dll's . I believe he wants to know
what the callign convention is. In this case it is same convention as
VC++ as the Dlls are compiled the same way.

Dave



Wed, 19 Jan 2000 03:00:00 GMT  
 Calling VB DLLs from VC/C++

Quote:



> > > Hello all,
> > > I am looking for a sample code (or directions to related articles) on how
> > > can I call a VB DLL
> > > from a C/C++ program. If you have also any comments on how this VB DLL can
> > > be called from other MS languages like FORTRAN don't hesitate to send them
> > > too.
> > > Thanks in advance

> > What do you mean a "VB DLL" VBRUN300.DLL?
> No. With VB 4.0 and 5.0 you can make dll's . I believe he wants to know
> what the calling convention is. In this case it is same convention as
> VC++ as the Dlls are compiled the same way.

Actually, I think they use the Pascal calloing convention.
The real question is: Why????  Why would anyone want to call *slow*
Visual Basic routines for C or C++.  Now the other way would make
sense.  I use VB to produce the UI and call C routines for speed.

--
*********************************************************

* Supporter of the campaign against grumpiness on c.l.c *
*********************************************************
The habit of viewing things cheerfully,
and of thinking of life hopefully,
may be made to grow up in us like any other habit.
                                    Matthew Arnold



Wed, 19 Jan 2000 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Calling VB DLLs from VC/C++

2. VB 5.0 calling C++ 5.0 DLL that calls winsock.dll

3. Creating DLLs with VC/C++ for VB

4. vb calls vc dll and strings get chopped

5. Problems calling a VC DLL from VB

6. calling VC DLL from VB

7. Calling VC++ programs and VC created dlls from VB

8. Calling C DLLs with VB/VC 5

9. can you create a dll in VB and call in VC

10. VB Call to VC DLL

11. callbacks (VB calls a VC DLL)

12. vb calling vc dll :csaa

 

 
Powered by phpBB® Forum Software