Solved

External call to VB ActiveX exe function

Posted on 2004-04-14
4
782 Views
Last Modified: 2012-08-13
I have a VB ActiveX exe that is composed of one Class module and two functions. The Class  calls the two functions. It is to be called from some C language code and receive a string parameter.

When I run the C Language code, it is able to call a Standard exe, receiving the parameter and displaying the value in a messagebox. When I call the ActiveX exe, a DOS window appears briefly and disappears with no error visible. The class appears to run but doesn't display the window it is supposed to display.

The VB code is from a software vendor, so I am reluctant to change this. I would like to call this directly from the C code. I am thinking that the ActiveX exe doesn't know what code to run first.

The C code is:

    strcpy(s_cmd, "Project1.exe ");
    strcat(s_cmd, lpDS->szDOCNAME);

    nResult = system(s_cmd);

I'm not really an expert in VB. Does it make sense to create a Standard exe to call the ActiveX exe. Any newbie links I can use to help me do this?
0
Comment
Question by:BPBEE
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
JMoon5FTM earned 125 total points
ID: 10823926
I'm not really an expert in C, but it looks like you're trying to invoke the ActiveX EXE like a normal program, using CreateProcess, ShellExecute, or the equivalent.  This doesn't work.  In order to call the ActiveX EXE from your C program, you need to first find and define the CLSID of the VB class you're accessing.  Then, you need to initialize COM using a function called CoInitialize, create an instance of the class using CoCreateInstance, and then finally terminate COM using CoTerminate.

It's really a lot easier to call it from VB, as VB does all this nonsense for you.  So if you're satisified with your Standard EXE, there's no reason you can't keep using it.  If you're serious about invoking the ActiveX EXE directly from C, let me know and I'll go into some more detail.
0
 

Author Comment

by:BPBEE
ID: 10824600
I actually have no choice in language preference. The app that is calling this VB ActiveX exe is a J.D.Edwards screen written by them (software vendor) and the only language it will use for interfacing is C. C++ is also not available and I cannot call the VB ActiveX exe directly. I must use a small C language program to call it.

I have seen some code that looks like what you're talking about but this is new to me. Would appreciate some details. Thanks for pointing me in the right direction.

Jim
0
 

Author Comment

by:BPBEE
ID: 10826067
I have some code that looks like this, but doesn't compile:

#include "C:\WINDOWS\JDE2CM.exe"
...
   CoInitialize(NULL);
   _CMClassPtr ptr;
   
   ptr.CreateInstance(__uuidof(CMClass));
   ptr->CallCM(lpDS->szDOCNAME);

   CoUninitialize();
0
 
LVL 5

Expert Comment

by:JMoon5FTM
ID: 10851455
From what I know of C/C++, I believe the #include line is trying to load the type library for the ActiveX EXE.  Does C support type libraries?  If the #include line is what's giving you trouble, I may be able to help you with this problem.

The CoInitialize and CoUninitialize look fine.

The rest of the code uses a class I'm not familiar with, so I can't tell you how well that's written.  :(
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

810 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