the way to use a DLL in Visual C++.
-
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 .
-
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 .
You should pass the
CLSID
or theProgID
of the automation object, see [^]. You may also get better help posting at theCOM
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] -
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 .
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