Click here to Skip to main content
15,893,381 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How should i do that? Pin
Christian Graus19-Jul-02 11:38
protectorChristian Graus19-Jul-02 11:38 
GeneralCreating threads Pin
Member 44967518-Jul-02 21:13
Member 44967518-Jul-02 21:13 
GeneralRe: Creating threads Pin
Mandalay18-Jul-02 21:25
Mandalay18-Jul-02 21:25 
GeneralRe: Creating threads Pin
Member 44967518-Jul-02 21:36
Member 44967518-Jul-02 21:36 
GeneralActiveX assert Pin
Jose Vicente18-Jul-02 21:09
Jose Vicente18-Jul-02 21:09 
GeneralRe: ActiveX assert Pin
includeh1018-Jul-02 23:06
includeh1018-Jul-02 23:06 
QuestionHow to use VB dll? Pin
RichardWdy18-Jul-02 21:07
RichardWdy18-Jul-02 21:07 
AnswerRe: How to use VB dll? Pin
18-Jul-02 23:36
suss18-Jul-02 23:36 
hi i coppied this from msdn please go through....

Method 1 - CreateDispatch:
1.Start Visual C++ and select New on the File menu. Choose MFC AppWizard (Exe) and a project name, and Click OK. When the MFC AppWizard dialog box appears, click Finish. Click OK on the next dialog box.
2.Select ClassWizard on the View menu, pick Ctst1App in the Class Name box, and double-click InitInstance in the Messages box. Click Edit Code to bring up the code for BOOL CTst1App::InitInstance(), find the line AfxEnableControlContainer();, and add the following line before it:
3.
AfxOleInit();

4.Select ClassWizard from the View menu and click the Automation tab. Click AddClass and select "from a TypeLibrary". Specify Project1.dll, the Visual Basic DLL which was created in step 3. When the Confirm Classes dialog box appears, click OK. Click OK again to close the MFC ClassWizard dialog box.
5.Open your <app name="">.cpp file and add the line #include "Project1.h". You need to include Project1.h wherever you have code that accesses project1.dll.
6.Open the ClassWizard again. On the Message Maps tab, select CAboutDlg in the Class Name box and IDOK in the Object IDs box, and then double-click BN_CLICKED. Click OK in response to the dialog box and OK again to close the ClassWizard.
7.Open <app name="">.cpp, scroll to the bottom to theCAboutDlg::OnOK(), and replace it with the following code:
8.
9. void CAboutDlg::OnOK()
10. {
11.
12. short st = 2;
13. short st1;
14. _Class1 p;
15. p.CreateDispatch("Project1.Class1");
16. st1 = p.MyVBFunction(&st);
17. CDialog::OnOK();
}

18.Compile your .exe file (F7).
19.Run the .exe file and select About on the Help menu. Click OK on the About box and the message box that was specified in project1.dll appears. Click the Close button to dismiss the dialog box.
Method 2 - #IMPORT:
1.Start Visual C++ 6.0 and create a Win32 Console Application. Select "An Empty Project" and click Finish.
2.Point to Add to Project on the Project menu and click New to add a new C++ source file to the project. Paste the following code in the new source file and save it:
3.
4. #include <stdio.h>
5.
6. // This is the path for your DLL.
7. // Make sure that you specify the exact path.
8.
9. #import "c:\project1.dll" no_namespace
10.
11. void main()
12. {
13. BSTR bstrDesc;
14.
15. try
16. {
17. CoInitialize(NULL);
18. short st = 2;
19. short st1;
20. // Declare the Interface Pointer for your Visual Basic object. Here,
21. // _Class1Ptr is the Smart pointer wrapper class representing the
22. // default interface of the Visual Basic object.
23.
24. _Class1Ptr ptr;
25. // Create an instance of your Visual Basic object, here
26. // __uuidof(Class1) gets the CLSID of your Visual Basic object.
27.
28. ptr.CreateInstance(__uuidof(Class1));
29. st1 = ptr->MyVBFunction(&st);
30. }
31. catch(_com_error &e)
32. {
33. bstrDesc = e.Description();
34.
35. }
36. CoUninitialize();
}

37.Compile and run your project. The message box from Project1.DLL should appear.
The #import method can be used in a Win32 Application, a Console Application, or in MFC as well.

Method 3 - Pure COM Interface
1.Start Visual C++ and select New from the File menu. Choose MFC AppWizard (Exe), name the project tst1, and click OK. When the MFC Appwizard dialog box appears, select Dialog Based and click Finish. Click OK when the next dialog box appears.
2.The Resource Editor is started by default. Delete all the controls on the dialog box and add a Command button on it, retaining the default caption "Button1".
3.Double-click Button1 to display the Add Member Function dialog box. Click OK to accept the name OnButton1.
4.Click OLE/COM Object Viewer on the Tools menu. Select View Typelib from the File menu and choose the Project1.dll you created earlier. Click Open to display the ITypeLib Viewer, which contains the .idl file for your DLL.
5.Copy the contents of your .idl file (contents of the right pane) to the Clipboard. Hold the SHIFT key down while paging or scrolling from the first character to the end of the text in the pane. Press Ctrl+C to copy the marked text to the Clipboard.
6.Click New on Visual C++ File menu. Select Text File on the New dialog box, name the file test1.idl, and click OK.
7.A blank text file appears. Paste the data from the Clipboard into it and save the file.
8.Select Settings from the Project menu, expand the tst1 and Source Files nodes of the tree view, and select test1.idl. Click the MIDL tab, enter test1.h in the "Output header file name" box, and click OK.
9.Open tst1Dlg.cpp and add the following files to the includes section:
10.
11. #include <initguid.h>
#include "test1.h"

12.Click the ClassWizard on the View menu, select Ctst1App in the Class Name box, and double-click InitInstance in the Messages box. Click Edit Code to bring up the code for:
13.
BOOL CTst1App::InitInstance()
Find the line:

AfxEnableControlContainer();
Add the following line before it:

AfxOleInit();

14.Open the ClassWizard again. On the Message Maps tab select CTst1Dlg in the Class Name box and IDC_BUTTON1 in the Object IDs box. Double-click BN_CLICKED in the Messages box, and click Edit Code to bring up the code for void CTst1Dlg::OnButton1(). Replace the OnButton1() function with the following code:
15.
16. void CTst1Dlg::OnButton1()
17. {
18. // TODO: Add your control notification handler code here.
19.
20. _Class1 *pClass = NULL;
21. IUnknown *pUnk = NULL;
22.
23. // HRESULT hr = CoCreateInstance(CLSID_Class1,NULL,
24. // CLSCTX_INPROC_SERVER,IID__Class1,(void **)&pClass);
25. // You can directly get the Interface ID as in the previous line or
26. // you can do a QueryInterface on IUnknown to get the IID
27. // as in the following three lines:
28.
29. HRESULT hr = CoCreateInstance(CLSID_Class1,NULL,CLSCTX_INPROC_SERVER,
30. IID_IUnknown,(void **)&pUnk);
31. hr = pUnk->QueryInterface(IID__Class1,(void **)&pClass);
32. pUnk->Release();
33.
34. // Once you have the IID, you can make use of the interface pointer
35. // to access our Visual Basic DLL.
36.
37. short st = 2;
38. short st1;
39. hr = pClass->MyVBFunction(&st,&st1);
40. pClass->Release();
41.
}
GeneralRe: How to use VB dll? Pin
RichardWdy19-Jul-02 0:25
RichardWdy19-Jul-02 0:25 
Generalmulti-select in CTreeCtrl Pin
Roman Nurik18-Jul-02 20:35
Roman Nurik18-Jul-02 20:35 
GeneralRe: multi-select in CTreeCtrl Pin
Mike Upton18-Jul-02 22:18
Mike Upton18-Jul-02 22:18 
GeneralRe: multi-select in CTreeCtrl Pin
Xiao-heihei18-Jul-02 22:47
sussXiao-heihei18-Jul-02 22:47 
GeneralRe: multi-select in CTreeCtrl Pin
Xiao-heihei18-Jul-02 22:50
sussXiao-heihei18-Jul-02 22:50 
GeneralRe: multi-select in CTreeCtrl Pin
Xiao-heihei18-Jul-02 22:50
sussXiao-heihei18-Jul-02 22:50 
GeneralRe: multi-select in CTreeCtrl Pin
Tibor Blazko18-Jul-02 23:02
Tibor Blazko18-Jul-02 23:02 
GeneralDownloading file Pin
Anonymous18-Jul-02 19:54
Anonymous18-Jul-02 19:54 
GeneralRe: Downloading file Pin
Roman Nurik18-Jul-02 20:33
Roman Nurik18-Jul-02 20:33 
GeneralRe: Downloading file Pin
Anonymous18-Jul-02 21:13
Anonymous18-Jul-02 21:13 
GeneralRe: Downloading file Pin
Scott H. Settlemier19-Jul-02 7:23
Scott H. Settlemier19-Jul-02 7:23 
GeneralRe: Downloading file Pin
Michael Dunn19-Jul-02 16:54
sitebuilderMichael Dunn19-Jul-02 16:54 
GeneralSHFileOperation failed, why. Pin
ttzzgg_8071318-Jul-02 19:47
ttzzgg_8071318-Jul-02 19:47 
GeneralRe: SHFileOperation failed, why. Pin
Mike Upton18-Jul-02 22:40
Mike Upton18-Jul-02 22:40 
GeneralRe: SHFileOperation failed, why. Pin
ttzzgg_8071319-Jul-02 1:51
ttzzgg_8071319-Jul-02 1:51 
Generalwave file editing please help me Pin
anju18-Jul-02 18:10
anju18-Jul-02 18:10 
GeneralEvents in edit control Pin
harish kota18-Jul-02 17:52
harish kota18-Jul-02 17:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.