using activex dll in vc++ win32 project

3.5k views Asked by At

i have got a ScreenCameraSDK and it comes with a 11kb dll file, it has a documentation too which lists the functions which can be used. It says

ScreenCamera SDK ActiveX Reference Documentation
ActiveX Reference

The ActiveX ID on the system is: ScreenCameraSDK.RemoteControl
Every method on the interface returns FAIL or SUCCESS. (0 or 1).
Create an instance of the ActiveX on your application, and then call InitializeScreenCameraRemoteControl. If the return value is SUCCESS then ScreenCamera is properly installed and you can then call any other method on the ActiveX's interface. If not ScreenCamera could not be found and you should contact support.**

Now my question is, i have the dll and no other files. How can i use the functions inside it in a VC++ Project with Visual Studio 2008. Thanks

I TRIED THE FOLLOWING CODE BUT GOT COMPILATION ERROR OF UNDEFINED IDENTIFIER

  #include <stdio.h>

      // This is the path for your DLL.
      // Make sure that you specify the exact path.

      #import "e:\ScreenCameraSDK.dll"  no_namespace

      void main()
      {
       BSTR bstrDesc;

      try
      {
      CoInitialize(NULL);
      short st = 2;
       short st1;
      // Declare the Interface Pointer for your Visual Basic object. Here,
      // _Class1Ptr is the Smart pointer wrapper class representing the
      // default interface of the Visual Basic object.

      _Class1Ptr ptr;
      // Create an instance of your Visual Basic object, here
      // __uuidof(Class1) gets the CLSID of your Visual Basic object.

       ptr.CreateInstance(__uuidof(Class1));
       st1 = ptr->MyVBFunction(&st);
      }
      catch(_com_error &e)
      {
       bstrDesc = e.Description();

      }
      CoUninitialize();
      }

it says _Class1Ptr is unknown!

2

There are 2 answers

1
KV Prajapati On

First of all you have to do this is #import the dll, and the compiler will automatically generate all required definitions from it. Then create objects from the library by using either smart pointers, or CreateInstance().

#import "C:\files\test.dll"    no_namespace rename("EOF", "EOFile")

...
int main() {
   if (FAILED(::CoInitialize(NULL)))
      return 0;
    ........
   ::CoUninitialize();
   return 0;
}
1
purvin On
BSTR bstrDesc;

try
{
    HRESULT hr= CoInitialize(NULL);
    CLSID clsid;
    hr = CLSIDFromProgID(OLESTR("<complete class name as see in registry>"),&clsid);
    short st = 2;
    short st1;

//nameOfClassInOCX  is placeholder for explanation. If you OCX com class name is blabla
    //use _blabla and so on. 

    _nameOfClassInOCX * ptr;

    hr = CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_nameOfClassInOCX ),(LPVOID*)&ptr);  

    cout << ptr->GetFees("hi") <<endl;
    ptr->Release();
}
catch(_com_error &e)
{
         bstrDesc = e.Description();
}

CoUninitialize();