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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 and use conditional statements in the C programming language.
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

770 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