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. the way to use a DLL in Visual C++.

the way to use a DLL in Visual C++.

Scheduled Pinned Locked Moved C / C++ / MFC
c++comhelpquestion
3 Posts 3 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.
  • L Offline
    L Offline
    lsh486love
    wrote on last edited by
    #1

    I want to use a dll in Visual C++ (Active X control), and for that i did the following: ClassWizard->Add class->From a type library Now i have the files that I need (.cpp and .h), but when I invoke a method, I get this message in my output: "Warning: attempt to call Invoke with NULL m_lpDispatch!" And the method does nothing. I think I have to create a LPDISPATCH object, but i don't know how. Any help??? My dll file name is "HanBarcord.dll". and class name in the dll file is "Cbarcord". I think I have to create the pointer to the real COM's IDispatch. So, I'm trying to use the object's CreateDispatch function member. But I don't know what I should put into parameter of "barcordreader.CreateDispatch" exactly. COleException *e = new COleException; Cbarcord barcordreader; barcordreader.CreateDispatch(" ????????????? ", e); Thank you in advance .

    CPalliniC S 2 Replies Last reply
    0
    • L lsh486love

      I want to use a dll in Visual C++ (Active X control), and for that i did the following: ClassWizard->Add class->From a type library Now i have the files that I need (.cpp and .h), but when I invoke a method, I get this message in my output: "Warning: attempt to call Invoke with NULL m_lpDispatch!" And the method does nothing. I think I have to create a LPDISPATCH object, but i don't know how. Any help??? My dll file name is "HanBarcord.dll". and class name in the dll file is "Cbarcord". I think I have to create the pointer to the real COM's IDispatch. So, I'm trying to use the object's CreateDispatch function member. But I don't know what I should put into parameter of "barcordreader.CreateDispatch" exactly. COleException *e = new COleException; Cbarcord barcordreader; barcordreader.CreateDispatch(" ????????????? ", e); Thank you in advance .

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      You should pass the CLSID or the ProgID of the automation object, see [^]. You may also get better help posting at the COM forum [^]. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • L lsh486love

        I want to use a dll in Visual C++ (Active X control), and for that i did the following: ClassWizard->Add class->From a type library Now i have the files that I need (.cpp and .h), but when I invoke a method, I get this message in my output: "Warning: attempt to call Invoke with NULL m_lpDispatch!" And the method does nothing. I think I have to create a LPDISPATCH object, but i don't know how. Any help??? My dll file name is "HanBarcord.dll". and class name in the dll file is "Cbarcord". I think I have to create the pointer to the real COM's IDispatch. So, I'm trying to use the object's CreateDispatch function member. But I don't know what I should put into parameter of "barcordreader.CreateDispatch" exactly. COleException *e = new COleException; Cbarcord barcordreader; barcordreader.CreateDispatch(" ????????????? ", e); Thank you in advance .

        S Offline
        S Offline
        Stuart Dootson
        wrote on last edited by
        #3

        The CLSID, which should be recorded in the typelib somewhere. I prefer using #import, which exposes the whole of a type-lib, including the CLSIDs. Here's an example - I'm using Excel's _Application class (it's a COM class - you could use it via MFC's 'Add Class' route:

        // Do the import - need to rename some things to avoid name collisions
        #import "libid:00020813-0000-0000-C000-000000000046" version("1.6") auto_search no_dual_interfaces rename("DialogBox", "excelDialogBox") rename("RGB", "excelRGB") rename("DocumentProperties", "excelDocumentProperties") rename("SearchPath", "excelSearchPath") rename("CopyFile", "excelCopyFile") rename("ReplaceText", "excelReplaceText")

        int main(int, char**)
        {
        CoInitializeEx(0, COINIT_APARTMENTTHREADED);
        {
        // Create the Excel object (or get the active instance) - note
        // that the CLSID of the Excel application class is linked to
        // the structure (Excel::Application) generated for that class
        // and can be accessed using __uuidof.
        Excel::_ApplicationPtr xl;
        if (SUCCEEDED(xl.GetActiveObject(__uuidof(Excel::Application))))
        {
        std::cout << "Getting name\n";
        // We're using several auto-generated classes here (Excel
        // application, Excel workbook) - you'd have to import each
        // one separately with MFC!
        std::cout << xl->ActiveWorkbook->FullName << std::endl;
        }
        }
        CoUninitialize();
        }

        If you're using VC6 (which I'm guessing you are?), I'm not sure how well #import will work for you, though :-(

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        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