Solved

External call to VB ActiveX exe function

Posted on 2004-04-14
4
792 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
[X]
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
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

696 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