Solved

Calling ActiveX dll from c

Posted on 2000-04-24
2
168 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
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;
  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
ID: 2758271
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using unmanaged DLL from managed application 14 290
In C, why can't I shift a 64-bit integer more than 32 bits? 13 204
List out all word 7 261
Line meaning 9 82
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…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

895 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

17 Experts available now in Live!

Get 1:1 Help Now