• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 531
  • Last Modified:

Invoke Visual Basic ActiveX exe with parms from C Language.

I have the current statement that works fine:

    ShellExecute ( NULL, _J("open"), _J("boldvr.exe "), lpDS->szDescriptn01, NULL, SW_HIDE );

This executes the process "boldvr.exe" and passes the "szDescriptn01" pointer to the called process when a button is clicked.

I need to change this so that when the process opens the window, the main window in the background cannot be accessed to click the button and open a 2nd window.

I am using J. D. Edwards Enterprise One editor that builds the C code. This is sometimes very particular so I try to use slightly older commands for best results. I'm pretty sure C++ commands will not work.

I have tried ShellExecuteEx and spawn. If anyone can convert my code to one os these and have the effect I am trying to accompish - that would help me greatly. Thanks.
0
BPBEE
Asked:
BPBEE
  • 9
  • 9
1 Solution
 
jkrCommented:
You could try

DWORD ExecuteAndWaitForCompletion   (   LPSTR   pszCmd)
{
   STARTUPINFO         si;
   PROCESS_INFORMATION pi;

   BOOL                bRes;

   DWORD               dwCode  =   0;

   MSG                 msg;

   ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

   si.cb           =   sizeof  (   STARTUPINFO);
   si.dwFlags      =   STARTF_USESHOWWINDOW;
   si.wShowWindow  =   SW_HIDE;

   bRes    =   CreateProcess   (   NULL,
                                   pszCmd,
                                   NULL,
                                   NULL,
                                   TRUE,
                                   NORMAL_PRIORITY_CLASS,
                                   NULL,
                                   NULL,
                                   &si,
                                   &pi
                               );

   WaitForSingleObject (   pi.hProcess, INFINITE);

   GetExitCodeProcess  (   pi.hProcess,    &dwCode);

   CloseHandle (   pi.hProcess);
   CloseHandle (   pi.hThread);

   return  (   dwCode);
}


and call it like

char acCmd[MAX_PATH];

sprintf(acCmd, "boldrvr.exe %s", lpDS->szDescriptn01);

ExecuteAndWaitForCompletion(acCmd);
0
 
BPBEEAuthor Commented:
I tried the following code and received build errors below. Very close, I think:

/************************************************************************/
    char acCmd[MAX_PATH];
    sprintf(acCmd, "boldrvr.exe %s", lpDS->szDescriptn01);
    ExecuteAndWaitForCompletion(acCmd);

return (ER_SUCCESS);
}
/************************************************************************
 *  
 ************************************************************************/

DWORD ExecuteAndWaitForCompletion ( LPSTR pszCmd)
{
   STARTUPINFO         si;
   PROCESS_INFORMATION pi;
   BOOL                bRes;
   DWORD               dwCode  =   0;
   MSG                 msg;

   ZeroMemory ( &si, sizeof ( STARTUPINFO));

   si.cb           =   sizeof ( STARTUPINFO);
   si.dwFlags      =   STARTF_USESHOWWINDOW;
   si.wShowWindow  =   SW_HIDE;

   bRes = CreateProcess ( NULL,
                          pszCmd,
                          NULL,
                          NULL,
                          TRUE,
                          NORMAL_PRIORITY_CLASS,
                          NULL,
                          NULL,
                          &si,
                          &pi
                         );

   WaitForSingleObject ( pi.hProcess, INFINITE);

   GetExitCodeProcess ( pi.hProcess,    &dwCode);

   CloseHandle ( pi.hProcess);
   CloseHandle ( pi.hThread);

   return ( dwCode);
}


Error messages, Warnings:

B550411A.c
C:\B9\DV9\source\B550411A.c(64) : error C2143: syntax error : missing ';' before 'type'
C:\B9\DV9\source\B550411A.c(65) : error C2065: 'acCmd' : undeclared identifier
C:\B9\DV9\source\B550411A.c(65) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
C:\B9\DV9\source\B550411A.c(65) : warning C4024: 'sprintf' : different types for formal and actual parameter 1
C:\B9\DV9\source\B550411A.c(66) : warning C4013: 'ExecuteAndWaitForCompletion' undefined; assuming extern returning int
C:\B9\DV9\source\B550411A.c(75) : warning C4142: benign redefinition of type
C:\B9\DV9\source\B550411A.c(89) : warning C4133: 'function' : incompatible types - from 'char *' to 'unsigned short *'
jdertdll.c


************Build Finished************

CALLBSFN.dll -   2 error(s),    5 warning(s):  Build failed.  Restored previous dll.

0
 
jkrCommented:
Jup, we're getting closer. 1st, you'll need a function prototype at the top of your .c file, e.g.

DWORD ExecuteAndWaitForCompletion ( LPSTR pszCmd); // prototype

As for

C:\B9\DV9\source\B550411A.c(64) : error C2143: syntax error : missing ';' before 'type'
C:\B9\DV9\source\B550411A.c(65) : error C2065: 'acCmd' : undeclared identifier

is there anything preceding this line?

  char acCmd[MAX_PATH];

It would seem weird to me if the compiler complains about 'char'...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BPBEEAuthor Commented:
Hi jkr,

Looks like J. D. Edwards is not accepting the acCmd field declaration:

   char acCmd[MAX_PATH];

with this statement.
0
 
jkrCommented:
What type is this compiler using for character arrays?
0
 
BPBEEAuthor Commented:
This is everything before the "char acCmd[MAX_PATH];" statement. The editor turns the word "char" blue so it does accept it. But it may not accept something else on this line. Or ?????

#include <jde.h>
#define B550411A_c

/*****************************************************************************
 *    Source File:  B5549115m
 *
 *    Description:  C Business Function - Invokes process and returns to
 *                                        current application.
 *
 *        History:
 *          Date        Programmer  SAR# - Description
 *          ----------  ----------  -------------------------------------------
 *   Author 11/22/2004  JJ          Created  
 *
 ****************************************************************************/
#include <B550411A.h>
#include <string.h>
#include <process.h>
#include <stdio.h>
#include <shellapi.h>

 /**************************************************************************
 *  Business Function:  InvokeProcessInsideCurrentApp
 *
 *        Description:  Invokes process and returns to current application.
 *
 *         Parameters:
 *           LPBHVRCOM            lpBhvrCom    Business Function Communications
 *           LPVOID               lpVoid       Void Parameter - DO NOT USE!
 *           LPDSW5542520A        lpDS         Parameter Data Structure Pointer  
 *
 *************************************************************************/
JDEBFRTN (ID) JDEBFWINAPI InvokeProcessInsideCurrentApp (LPBHVRCOM    lpBhvrCom,
                                             LPVOID       lpVoid,                                                          LPDSD5549115 lpDS)  
{
   /************************************************************************
    * Declare pointers
    ************************************************************************/
     PFNJDE2CMdll lpJDE2CM;
     HINSTANCE hLibrary;
  /************************************************************************
    * Check for NULL pointers
    ************************************************************************/
   if ((lpBhvrCom == (LPBHVRCOM) NULL) ||
       (lpVoid    == (LPVOID)    NULL) ||
       (lpDS      == (LPDSD5549115)      NULL))
   {
     jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL);
     return ER_ERROR;
   }
0
 
jkrCommented:
Ah, could it be that we need to use

/************************************************************************/
   WCHAR acCmd[MAX_PATH];
   wsprintf(acCmd, _J("boldrvr.exe %s"), lpDS->szDescriptn01);
   ExecuteAndWaitForCompletion(acCmd);

return (ER_SUCCESS);
}
/************************************************************************
*  
************************************************************************/

DWORD ExecuteAndWaitForCompletion ( LPWSTR pszCmd)
{
  STARTUPINFO         si;
  PROCESS_INFORMATION pi;
  BOOL                bRes;
  DWORD               dwCode  =   0;
  MSG                 msg;

  ZeroMemory ( &si, sizeof ( STARTUPINFO));

  si.cb           =   sizeof ( STARTUPINFO);
  si.dwFlags      =   STARTF_USESHOWWINDOW;
  si.wShowWindow  =   SW_HIDE;

  bRes = CreateProcess ( NULL,
                         pszCmd,
                         NULL,
                         NULL,
                         TRUE,
                         NORMAL_PRIORITY_CLASS,
                         NULL,
                         NULL,
                         &si,
                         &pi
                        );

  WaitForSingleObject ( pi.hProcess, INFINITE);

  GetExitCodeProcess ( pi.hProcess,    &dwCode);

  CloseHandle ( pi.hProcess);
  CloseHandle ( pi.hThread);

  return ( dwCode);
}

?
0
 
BPBEEAuthor Commented:
Let me find out about the char arrays ... should be very C like.
0
 
jkrCommented:
It seems that this thing wants UNICODE, at least

C:\B9\DV9\source\B550411A.c(89) : warning C4133: 'function' : incompatible types - from 'char *' to 'unsigned short *'

suggests that...
0
 
BPBEEAuthor Commented:
I moved the declarations for the array and function to the top of the code and now down to the following build warnings:

B550411A.c
C:\B9\DV9\source\B550411A.c(52) : warning C4210: nonstandard extension used : function given file scope
C:\B9\DV9\source\B550411A.c(91) : warning C4133: 'function' : incompatible types - from 'char *' to 'unsigned short *'
Replacing B550411A.obj
jdertdll.c
   Creating library C:\B9\DV9\lib32\CALLBSFN.lib and object C:\B9\DV9\lib32\CALLBSFN.exp


************Build Finished************

CALLBSFN.dll -   0 error(s),    2 warning(s):  Built successfully.

Still need to get the second warning about the incompatible types.
0
 
jkrCommented:
Have you changed

DWORD ExecuteAndWaitForCompletion ( LPSTR pszCmd)
{

to

DWORD ExecuteAndWaitForCompletion ( LPWSTR pszCmd)
{

also?
0
 
BPBEEAuthor Commented:
      DWORD ExecuteAndWaitForCompletion ( LPSTR pszCmd);
and
                 DWORD ExecuteAndWaitForCompletion ( LPWSTR pszCmd)

result in the same build log with the two warnings. I think that the type LPSTR needs some type of declaration possibly in the header. Is there a library that needs to be included ??
Or do I need to add some code to the .h source ??
0
 
jkrCommented:
That's pretty weird - just to make that sure, where is line 91 in the above code actually?
0
 
BPBEEAuthor Commented:
I see your logic. It is possible that the error may refer to any function in the code. I was told that the compiler is likely an strict ANSI compiler since it is a cross platform application.

Line 91 ??? is the NULL parameter hilighted below:

DWORD ExecuteAndWaitForCompletion ( LPSTR pszCmd)
{
   STARTUPINFO         si;
   PROCESS_INFORMATION pi;
   BOOL                bRes;
   DWORD               dwCode  =   0;
   MSG                 msg;

   ZeroMemory ( &si, sizeof ( STARTUPINFO));

   si.cb          = sizeof ( STARTUPINFO);
   si.dwFlags     = STARTF_USESHOWWINDOW;
   si.wShowWindow = SW_HIDE;

   bRes = CreateProcess ( NULL,
                          pszCmd,
                          NULL,
                          NULL,
                          TRUE,
                          NORMAL_PRIORITY_CLASS,
                          NULL, //<<<<<======== Line 91
                          NULL,
                          &si,
                          &pi
                         );

   WaitForSingleObject ( pi.hProcess, INFINITE);

   GetExitCodeProcess ( pi.hProcess, &dwCode);

   CloseHandle ( pi.hProcess);
   CloseHandle ( pi.hThread);

   return ( dwCode);
}
0
 
jkrCommented:
Ah, I see. Nevertheless, you still should use

DWORD ExecuteAndWaitForCompletion ( LPWSTR pszCmd)

for both the prototype and the implementation since you are passing UNICODE characters to this function. If the marked line above really is the one the compiler is complaining about, you can safely ignore the warning and run a test.
0
 
BPBEEAuthor Commented:
The code compiles with only one warning now. Code is below. Warning message follows. But I will try this out to see if it seems to work. I changed the "W" version you had suggested previously but I had missed changing some of the code to include the extra "W" or "w".

#include <jde.h>

#define B550411A_c

/*****************************************************************************
 *    Source File:  B5549115m
 *
 *    Description:  C Business Function - Invokes process and returns to
 *                                        current application.
 *
 *        History:
 *          Date        Programmer  SAR# - Description
 *          ----------  ----------  -------------------------------------------
 *   Author 11/22/2004  JJ          Created  
 *
 ****************************************************************************/

#include <B550411A.h>
#include <string.h>
#include <process.h>
#include <stdio.h>
#include <shellapi.h>

 /**************************************************************************
 *  Business Function:  InvokeProcessInsideCurrentApp
 *
 *        Description:  Invokes process and returns to current application.
 *
 *         Parameters:
 *           LPBHVRCOM            lpBhvrCom    Business Function Communications
 *           LPVOID               lpVoid       Void Parameter - DO NOT USE!
 *           LPDSW5542520A        lpDS         Parameter Data Structure Pointer  
 *
 *************************************************************************/

JDEBFRTN (ID) JDEBFWINAPI InvokeProcessInsideCurrentApp (LPBHVRCOM    lpBhvrCom,
                                                                           LPVOID       lpVoid,
                                                                           LPDSD5549115 lpDS)  
{
   /************************************************************************
    * Declare pointers
    ************************************************************************/
     PFNJDE2CMdll lpJDE2CM;
       HINSTANCE hLibrary;

       WCHAR acCmd[MAX_PATH];
       DWORD ExecuteAndWaitForCompletion ( LPWSTR pszCmd);
  /************************************************************************
    * Check for NULL pointers
    ************************************************************************/
   if ((lpBhvrCom == (LPBHVRCOM) NULL) ||
       (lpVoid    == (LPVOID)    NULL) ||
       (lpDS      == (LPDSD5549115)      NULL))
   {
     jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL);
     return ER_ERROR;
   }
   /************************************************************************
    * Main Processing
    *  
    ************************************************************************/
    wsprintf(acCmd, _J("boldvr.exe %s"), lpDS->szDescriptn01);
    ExecuteAndWaitForCompletion(acCmd);

return (ER_SUCCESS);
}
/************************************************************************
 *  
 ************************************************************************/

DWORD ExecuteAndWaitForCompletion ( LPWSTR pszCmd)
{
   STARTUPINFO         si;
   PROCESS_INFORMATION pi;
   BOOL                bRes;
   DWORD               dwCode  =   0;
   MSG                 msg;

   ZeroMemory ( &si, sizeof ( STARTUPINFO));

   si.cb          = sizeof ( STARTUPINFO);
   si.dwFlags     = STARTF_USESHOWWINDOW;
   si.wShowWindow = SW_HIDE;

   bRes = CreateProcess ( NULL,
                          pszCmd,
                          NULL,
                          NULL,
                          TRUE,
                          NORMAL_PRIORITY_CLASS,
                          NULL,
                          NULL,
                          &si,
                          &pi
                         );

   WaitForSingleObject ( pi.hProcess, INFINITE);

   GetExitCodeProcess ( pi.hProcess, &dwCode);

   CloseHandle ( pi.hProcess);
   CloseHandle ( pi.hThread);

   return ( dwCode);
}


Compiler message log:

Generating Makefile:  C:\B9\DV9\obj\CALLBSFN.mak
Makefile generated.

Building business functions.

************CALLBSFN************

B550411A.c
C:\B9\DV9\source\B550411A.c(48) : warning C4210: nonstandard extension used : function given file scope
Replacing B550411A.obj
jdertdll.c
   Creating library C:\B9\DV9\lib32\CALLBSFN.lib and object C:\B9\DV9\lib32\CALLBSFN.exp


************Build Finished************

CALLBSFN.dll -   0 error(s),    1 warning(s):  Built successfully.
0
 
BPBEEAuthor Commented:
Yes !!!!! It works !!!!!! Yes, yes, yes !!!!! You deserve those points !!!
0
 
jkrCommented:
Thanks :o)

BTW, you probably will get rid of the last warning when you declare that function as 'static', e.g.

static DWORD ExecuteAndWaitForCompletion ( LPWSTR pszCmd);

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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