• C

Calling ActiveX dll from c

Hi i posted a question earlier and this is basically what i need help with
I need to connect to a vb ActiveX.dll. I have 2 functions in this dll
1) Getsignature(lngAcc as long,lngAmt as long,strTrans as string)
2) FetchSignature(strAction as string,strResults as string)

I need to modify an existing c program so i can initiate a thread to activate this dll and it's first function getsignature.
now the way i understand this is that this thread will run under my C's process space therefore i do not have to worry about
marshaling the threads, is this correct ?

I do know i have to use the Iunknown interface
and the CoCreateInstance, Coinitialise and CoUnInitialise
then i need to call function 2 FetchSignatures()

does anyone have an idea on how to code this in C. My c is very rusty so as much explanation will be appreciated.
I only have the Visual C++ enviroment on the pc, but i do know that u can open a c/c++ source file and put straight c int there ??

thanx allot for your help



Who is Participating?
sharonkConnect With a Mentor Commented:
There is one thing that is not clear, you said you have to call functions from an ActiveX Dll but you didn't say from which interface? ActiveX Dll's contain classes which support interfaces. Suppose you know the Class and the interface this is what you have to do:
1)First you need a header file containing the definitions in this ActiveX and a c extension file for the declarations. If you dont have those you may be able to generate them through the following procedure: Open the dll file with OLE View (From Visual Studio Tools), Copy the IDL definitions into an IDL file, Copmile the file with midl, the files you need are the *.h and *_i.c.
2) Suppose the Interface's name if IMyInterface this code should call GetSignature (you do no refer to the IIS GetSignature???):

#include <windows.h>
#include "myfile.h"
#include "myfile_i.c"

int main(int argc, char* argv[])
  IMyInterface *mi;
  long lngAcc,lngAmt;
  BSTR strTrans;

  hr = CoCreateInstance(&CLSID_MyClass, NULL, CLSCTX_INPROC, &IID_IMyInterface, (void**)&mi);
  if (SUCCEEDED(hr))
    mi->lpVtbl->GetSignature(mi, lngAcc ,lngAmt ,strTrans);


  return 0;

3) You should of course see that you pass the right values to the parameters, and also very important pass the parameters the right way (in by value, out by reference). If you want a good book which explains all this stuff you can look at "Inside Com" or "Essential Com".
Try next:
The Ole Proxy Wizard is a tool to generate OCF/OWL based code
for handling OLE Automation servers and ActiveX Servers.
It reads a type library, and extracts all the information
it can: for example dual interfaces get C++ abstract class
definitions defined for them as well as OLE automation based
proxy classes. ProxyWizard also tries to find all types that
are marked as event sources and generates sample event
handling code for TOleWindow or TOleDialog based classes,
that you can cut and paste into your own code.
Examples of custom event handling are given in the demo

But after ProxyWiz maked code, you must change it to you needs.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.