Solved

External call to VB ActiveX exe function

Posted on 2004-04-14
4
781 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

929 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

18 Experts available now in Live!

Get 1:1 Help Now