Calling ActiveX dll from c

Posted on 2000-04-24
Medium Priority
Last Modified: 2011-04-14
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



Question by:CraigLazar

Accepted Solution

sharonk earned 2000 total points
ID: 2746434
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".
LVL 14

Expert Comment

ID: 2758271
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.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question