Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to call VB activex DLL in MFC

Posted on 2002-04-28
2
Medium Priority
?
305 Views
Last Modified: 2013-11-20
Hi all
  i am Vb programmer and i wanted to know how to call vb dll in vc++ as my collegue is working as vc++ programmeer and he wants to integrate my dll with his program in his project .

can any body give me a good example for that

thanks

asps
0
Comment
Question by:asps
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 1100 total points
ID: 6974791
Hi

i got this information from one site and the author for this is Milind S Deobhankar

May this article helps you



How to call VB dll from VC++
In this article I'll present a way of calling a VB ActiveX DLL from a MFC client application. There are other ways to do so but I find this by far the easiest. Any information presented here is only for learning purposes.
I shall briefly point out the steps you need to follow-
·     Create an ActiveX server component with VB. This is the ActiveX DLL you need to create with VB.
·     Create an dialog based MFC application using the MFC Appwizard.
·     Import the server's (DLL) type library into the MFC client app.
·     Initialize the COM library
·     Retrieve the CLSID of the server component.
·     Create an instance of the COM server component.
·     Use the COM object
·     Uninitialize the COM library
First create a new ActiveX DLL project using VB 6.0. Name the project prjdll and the class clsdll. Add a new function fnCallDll to the class. My function just displays a messagebox and looks like
Public Function fnCallDll()
     MsgBox "VB ActiveX DLL"
End Function
Save and compile this project to create prjdll.dll. This is our server component.
Now we are going to develop the client. Create a new dialog based application in VC++ using MFC Appwizard and save the project.
We are going to import the server component's type library using the #import statement. Copy the prjdll.dll file to the directory where you have saved your MFC Appwizard project. Click the FileView tab of the Project Workspace window, expand the Header Files folder, open the file stdafx.h and add the following code (appears greyed)
# import "prjdll.dll"
using namespace prjdll;
You must add the above code after
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately  
and before
#endif
in the stdafx.h file.Importing the prjdll.dll file helps the compiler to link to the dll's type library at runtime. The #import tells the compiler to generate the wrapper class, which will encapsulate the functionalities of the server component. If the server component is created using VB we need the import the associated .dll file and if the component is created using VC++, we need to import the .tlb file.The name of the wrapper class will be same as the server component name, by default.
Compile the stdafx.cpp file. The compiler generates a .tlh and a .tli file in your projects Debug or Release directory (depending on your configuration). These are the type library header and implementation files. Open the .tlh file by double-clicking it and find out word immediately after the word namespace. This is usually the name of the project that we earlier created using VB.Look at the code we inserted earlier to the stdafx.h file.The using namespace is required so that we can access the server's methods.
Place a codebutton control (IDC_BUTTON1) on the dialog. Double-click the control to add a command handler OnButton1() for the button. Now add the following code in the handler-
HRESULT hresult;
CLSID clsid;

CoInitialize(NULL);     //initialize COM library
hresult=CLSIDFromProgID(OLESTR("prjdll.clsdll"), &clsid);    //retrieve CLSID of component
         
_clsdll *t;
hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_clsdll),(LPVOID *) &t);
if(FAILED(hresult))
{
     AfxMessageBox("Creation Failed");
     return;
}

t->fnCallDll ();  //call method
t->Release();   //call method
CoUninitialize();  //Unintialize the COM library        
The name of the CoClass is _clsdll. The CoCreateInstance function returns the address of the interface pointer requested. Now the pointer t can happily be used to access the functionality of the server component.
That's it. On clicking the button a Messagebox should pop up.




Cheers
Koundinya
0
 

Author Comment

by:asps
ID: 6980777
as there are no comments or answers from others and i am accepting his answer as his idea is working fine.

Thanks
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question