Solved

Calling ActiveX dll from c

Posted on 2000-04-24
2
165 Views
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


:)

Craig


0
Comment
Question by:CraigLazar
2 Comments
 
LVL 1

Accepted Solution

by:
sharonk earned 500 total points
Comment Utility
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;
  HRESULT hr;
  long lngAcc,lngAmt;
  BSTR strTrans;

  CoInitialize(NULL);
  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".
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
Comment Utility
Try next:
http://ourworld.compuserve.com/homepages/John_Maddock/
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
applications.

But after ProxyWiz maked code, you must change it to you needs.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now