Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to use VB dll?

How to use VB dll?

Scheduled Pinned Locked Moved C / C++ / MFC
helpcomtutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RichardWdy
    wrote on last edited by
    #1

    I have a VB dll(ActiveX dll). The project only has dll file and library file. I used it like this: typedef VOID (*VTPROC)(LPTSTR); void MyProc() { HINSTANCE hinstLib; VTPROC ProcAdd; BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; // Get a handle to the DLL module. hinstLib = LoadLibrary("VTProj"); // If the handle is valid, try to get the function address. if (hinstLib != NULL) { ProcAdd = (VTPROC)GetProcAddress(hinstLib, "Initialize"); // If the function address is valid, call the function. if (fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd) ("message via DLL function\n"); // Free the DLL module. fFreeResult = FreeLibrary(hinstLib); } // If unable to call the DLL function, use an alternative. if (! fRunTimeLinkSuccess) printf("message via alternative method\n"); } The ProcAdd was always NULL. Could anyone help me solve the problem? Thanks. No pains, no gains.

    L 1 Reply Last reply
    0
    • R RichardWdy

      I have a VB dll(ActiveX dll). The project only has dll file and library file. I used it like this: typedef VOID (*VTPROC)(LPTSTR); void MyProc() { HINSTANCE hinstLib; VTPROC ProcAdd; BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; // Get a handle to the DLL module. hinstLib = LoadLibrary("VTProj"); // If the handle is valid, try to get the function address. if (hinstLib != NULL) { ProcAdd = (VTPROC)GetProcAddress(hinstLib, "Initialize"); // If the function address is valid, call the function. if (fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd) ("message via DLL function\n"); // Free the DLL module. fFreeResult = FreeLibrary(hinstLib); } // If unable to call the DLL function, use an alternative. if (! fRunTimeLinkSuccess) printf("message via alternative method\n"); } The ProcAdd was always NULL. Could anyone help me solve the problem? Thanks. No pains, no gains.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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 .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 .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 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. // Decl

      R 1 Reply Last reply
      0
      • L Lost User

        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 .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 .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 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. // Decl

        R Offline
        R Offline
        RichardWdy
        wrote on last edited by
        #3

        Thank you very much. I am trying... No pains, no gains.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups