Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 801
  • Last Modified:

External call to VB ActiveX exe function

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
BPBEE
Asked:
BPBEE
  • 2
  • 2
1 Solution
 
JMoon5FTMCommented:
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
 
BPBEEAuthor Commented:
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
 
BPBEEAuthor Commented:
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
 
JMoon5FTMCommented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now