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. Other Discussions
  3. Article Writing
  4. Call VB DLLs from C++

Call VB DLLs from C++

Scheduled Pinned Locked Moved Article Writing
c++helpquestionlearning
6 Posts 5 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.
  • K Offline
    K Offline
    Karl Fetterhoff
    wrote on last edited by
    #1

    Why is it that C++ cannot utilize a DLL authored in Visual Basic? Is there somebody out there who is mixed language savvy enough to address this issue in an article? I'd be very interested in interfacing between the two or learning how VB / C++ can exchange delimited strings via Winsock / CSocket. Any ideas?

    T S 2 Replies Last reply
    0
    • K Karl Fetterhoff

      Why is it that C++ cannot utilize a DLL authored in Visual Basic? Is there somebody out there who is mixed language savvy enough to address this issue in an article? I'd be very interested in interfacing between the two or learning how VB / C++ can exchange delimited strings via Winsock / CSocket. Any ideas?

      T Offline
      T Offline
      Tom Welch
      wrote on last edited by
      #2

      I do this all the time. #import "c:\path\to\my\vb.dll" rename_namespace("WHATEVER") Then simply use

      WHATEVER::MyObjectPtr pObj = NULL;
      try
      {
      HRESULT hr = pObj.CreateInstance( __uuidof(WHATEVER::MyObject) );
      if (FAILED(hr))
      {
      _com_issue_error(hr);
      }

      pObj->DoStuff();
      }
      catch (_com_error& e)
      {
      // please don't forget this part
      }

      You still want an article? :confused:

      A N 2 Replies Last reply
      0
      • T Tom Welch

        I do this all the time. #import "c:\path\to\my\vb.dll" rename_namespace("WHATEVER") Then simply use

        WHATEVER::MyObjectPtr pObj = NULL;
        try
        {
        HRESULT hr = pObj.CreateInstance( __uuidof(WHATEVER::MyObject) );
        if (FAILED(hr))
        {
        _com_issue_error(hr);
        }

        pObj->DoStuff();
        }
        catch (_com_error& e)
        {
        // please don't forget this part
        }

        You still want an article? :confused:

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Cool! #import looks like a powerful directive, but how can it allow me to reference the VB DLL's method? Specifically, my VB DLL has one string function, "Execute", which accepts a string as an argument. So I'm not surprised to see the compiler complain that MyObjectPtr is not a member of WHATEVER. But when I replace "MyObjectPtr" with "Execute" I still get the same complaint. I really appreciate your help Tom. Thanks in advance for any insight you might wish to share. Haha! Yeah, maybe a short article. You can bet I'm going to create a few notes of my own if I ever get this approach to work.

        T 1 Reply Last reply
        0
        • A Anonymous

          Cool! #import looks like a powerful directive, but how can it allow me to reference the VB DLL's method? Specifically, my VB DLL has one string function, "Execute", which accepts a string as an argument. So I'm not surprised to see the compiler complain that MyObjectPtr is not a member of WHATEVER. But when I replace "MyObjectPtr" with "Execute" I still get the same complaint. I really appreciate your help Tom. Thanks in advance for any insight you might wish to share. Haha! Yeah, maybe a short article. You can bet I'm going to create a few notes of my own if I ever get this approach to work.

          T Offline
          T Offline
          Tom Welch
          wrote on last edited by
          #4

          Short answer... You can use BSTR, CComBSTR, or _bstr_t datatypes to transmit strings over COM. I like _bstr_t the best because you can easily use any string and cast it to a _bstr_t without worrying about memory allocation. Confused? Don't be. A little bit of reading should clear up your questions. The long answer... I will put this in an article. I don't know when I'll get it done. But I'll shoot for this weekend.

          1 Reply Last reply
          0
          • T Tom Welch

            I do this all the time. #import "c:\path\to\my\vb.dll" rename_namespace("WHATEVER") Then simply use

            WHATEVER::MyObjectPtr pObj = NULL;
            try
            {
            HRESULT hr = pObj.CreateInstance( __uuidof(WHATEVER::MyObject) );
            if (FAILED(hr))
            {
            _com_issue_error(hr);
            }

            pObj->DoStuff();
            }
            catch (_com_error& e)
            {
            // please don't forget this part
            }

            You still want an article? :confused:

            N Offline
            N Offline
            NewportKarl
            wrote on last edited by
            #5

            I have made better progress, but I seem to be up against a wall with this particular error: warning C4042: '_IID' : has bad storage class It doesn't seem to make any difference what type I define in VB to pass/return to/from the DLL. Byte, Integer, String, Variant -- all yield the same error.

            1 Reply Last reply
            0
            • K Karl Fetterhoff

              Why is it that C++ cannot utilize a DLL authored in Visual Basic? Is there somebody out there who is mixed language savvy enough to address this issue in an article? I'd be very interested in interfacing between the two or learning how VB / C++ can exchange delimited strings via Winsock / CSocket. Any ideas?

              S Offline
              S Offline
              Shinde Vikram
              wrote on last edited by
              #6

              hello karl well the VB's DLL is a ActiveX DLL which supports the COM so the functions exported by the VB's DLL can be called through the VB program. But You can call Funtion from DLL of C++ through VB so do not worry abt calling the VB's DLL through C++ and remove it from your mind i m student of M. Sc. Computer Science from india and expert in Message Digest Security

              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