?
Solved

API Refer...

Posted on 2003-03-15
8
Medium Priority
?
653 Views
Last Modified: 2008-02-26
Hi, im really muzzled when it comes down to this stuff so i would like to ask for your help?

Is it possible to make a program in vb6 which can be referenced externally?
(Example: MSN Messenger, Reference to it and you can control how messages are displayed etc with a bit of code)

Can i pass parameters to my prog to control it externally?
(Exmaple: Winamp, SendMessage (AMP_HANDLE, WM_COMMAND, Winampcommand, 0))

If so could you provide some links to documentation/source/tutorials whatever can help me.

Many Thanks.
0
Comment
Question by:JuleZzZ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 

Author Comment

by:JuleZzZ
ID: 8146053
Upto now i have subclassed my app so i can run checks on what commands are being passed to it.

Heres the check which i use...

If uMsg = WM_COMMAND And wParam = 999666 Then MsgBox "Works"

but what do i do if i want to return a value so i can report my apps status. Example..

(External Prog)
intret = sendmessagelong(hwnd,wm_command, 999666, 0&)
select case intret
case 1
   msgbox "Playing"
case 2
   msgbox "Stopped"
end select


Many Thanks.
0
 

Author Comment

by:JuleZzZ
ID: 8146095
Upto now i have subclassed my app so i can run checks on what commands are being passed to it.

Heres the check which i use...

If uMsg = WM_COMMAND And wParam = 999666 Then MsgBox "Works"

but what do i do if i want to return a value so i can report my apps status. Example..

(External Prog)
intret = sendmessagelong(hwnd,wm_command, 999666, 0&)
select case intret
case 1
   msgbox "Playing"
case 2
   msgbox "Stopped"
end select


Many Thanks.
0
 
LVL 3

Expert Comment

by:y2ksw
ID: 8147648
You could pass a windows handle by the lParam from the caller. So the callee could send back a user message to it.

BTW. WM_USER + 1 would be fine for messages :-)
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!

 

Author Comment

by:JuleZzZ
ID: 8149792
Cheers, but one problem

Private Sub Command1_Click()
    r = SendMessageLong(blah, WM_USER, 999666, Me.hwnd)
    MsgBox r
End Sub

always returns 0 although im using this in my subclassed program.

    If uMsg = WM_USER And wParam = 999666 Then
        Call SendMessage(lParam, WM_USER, mylstatus, 0&)
    End If

i think the program controlling the subclassed program would have to subclass itsself to check the messages but i would prefer it to get a return handle?
0
 
LVL 3

Expert Comment

by:y2ksw
ID: 8152672
MSDN: SendMessage Parameters

hwnd

Identifies the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.

uMsg

Specifies the message to be sent.

wParam

Specifies additional message-specific information.

lParam

Specifies additional message-specific information.

***Return Value***

The return value specifies the result of the message processing and depends on the message sent.

---

Therefore "r" could be anything and should not be evaluated from within VB.

Instead you should subclass the caller too, and after sending the message, wait for a reply on that subclassed procedure. Note that you may use PostMessage instead of SendMessage, which allowes to proceed and not to wait for a reply which could sensibly slow down your app (asyncronous).

So:

If uMsg = WM_USER And wParam = 999666 Then
    Call SendMessage(lParam, WM_USER, mylstatus, 0&)
End If

will work, as long as "lParam"  alias "Me.hWnd" is listening for that message too.
0
 

Author Comment

by:JuleZzZ
ID: 8156040
Yea i understand that but how does functions such as shellexecute return a handle without the caller subclassing itself? there must be a way?? :(
0
 
LVL 3

Accepted Solution

by:
y2ksw earned 120 total points
ID: 8166648
Well, ok, you might issue an event like WM_PAINT to the calling process. If this message is unlikely to happen, you may catch this with the Form_Paint Event and react on this. But this is not a good programming practice, because if your Form.AutoRedraw is on, then the Form_Paint Event will never fire. Or else you might have a control which receives a WM_CLICK event (such as a Command Button) out of sight, and inside the Command1_Click Event you will have your code. But all these examples are not standard and may give unpredictable results, while sending a specific message back and forth is standard and will run without troubles.

Note that quiet a lot of programs comunicate by sharing a temporary file or by using a named pipe (difficult to realize with VB), or by Callback Functions (Winamp).
0
 

Author Comment

by:JuleZzZ
ID: 8178194
Nice one, Thanks For Your Help :)
0

Featured Post

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!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

762 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