Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Apache, CGI, Visual Basic, PostMessage combo question

Apache, CGI, Visual Basic, PostMessage combo question

Apache, CGI, Visual Basic, PostMessage combo question

Here's what I'm trying to do but need help achieving.

I want to service a web page request using a CGI program, which I'll call program A.  I would like the CGI request to start program A, which will in turn communicate with program B and return some valves.  Program B communicates with hardware and needs to run continuously.  In short, the CGI request starts program A, A talks to B (already running), and A returns the web page to be served.

I'm running Apache 2.2 under Win 2000 professional.  I have a basic web page that calls program A, which I have successfully written in Visual Basic 2005.  It's a console application (as required) that starts and returns properly formatted web html pages.  That part works.

I can also run program A DIRECTLY on the PC and it sends messages to program B.  (Its html-formatted output is ignored, of course.)  That part works.

However, when program A is called via the CGI call through Apache, it fails to be able to communicate with program B.

To be clear, the same exact program (A) run by me in windows will communicate with B successfully; however, when A is called by Apache through the CGI request, it fails to communicate.

Here are what I believe are the relevant details.

Program A finds and communicates with Program B using the core routine posted below.  Through debugging, I have come to learn that the failure lies (or at least starts) in GetConsoleWindow() returning an empty handle when called through Apache.  (When called directly by me, it returns a valid handle and the program works.)

I suspect that the problem is related to the "user identity" differences between me as a user and apache.  It might be that when called by Apache, it does not have the permission to get a valid answer from GetConsoleWindow().  This is about as far I know how to take this.

Any help or suggestions?  Perhaps I'm going about this all wrong.

' get a window handle, search for application "Message
' Recipient" and post a message
lWnd = GetConsoleWindow()
' the above returns a valid handle when run directly,
' but returns 0 when run through Apache/CGI call


 If lWnd = 0 Then
   bFound = False
   Exit Do
 End If

 lLen = GetWindowTextLength(lWnd)
 sCaption = New String(Chr(0), lLen)

 Call GetWindowText(lWnd, sCaption, lLen + 1)
 If sCaption = "Message Recipient" Then
   'send message to window
   PostMessage(lWnd, CUSTOM_MSG, 0, 0)

    bFound = True
    Exit Do
 End If

 lWnd = GetNextWindow(lWnd, 2)


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close