Solved

External call to VB ActiveX exe function

Posted on 2004-04-14
4
778 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

743 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

15 Experts available now in Live!

Get 1:1 Help Now