Solved

Windows API Help

Posted on 1998-07-06
5
346 Views
Last Modified: 2010-05-18
I am making a mIRC bot. And I have been using DDE to send commands to mIRC. Quite frankly, its getting anoying. I was told that I could use Windows API and the statement SendMessage. How do I do it? Can someone give me an example?
0
Comment
Question by:demon69
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:khaledc
Comment Utility
Decleration for SendMessage is as followed:
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
where,
hwnd: handle of the window to receive the message
wMsg: The identifier of the message
wParam: Depends on the message
lParam: Depends on the message
or try the two functions,
SendMessageByString, or SendMessageByNum
0
 

Author Comment

by:demon69
Comment Utility
I do not understand what ByVal wParam and IParam are. What would go in their place if I was to send the text "Hello all!" to mIRC? SendMessage(mIRC32, "Hello all!",  ...... what next?
0
 

Author Comment

by:demon69
Comment Utility
I do not understand what ByVal wParam and IParam are. What would go in their place if I was to send the text "Hello all!" to mIRC? SendMessage(mIRC32, "Hello all!",  ...... what next?
0
 
LVL 1

Expert Comment

by:khaledc
Comment Utility
Out of Memory wParam is a setting flag, and lparam is a returned value (means that you don't have to worry about, just declare lParam as shown above).
I have to go back to my documentation and tell you what all the flags are.
until then
0
 
LVL 7

Accepted Solution

by:
tward earned 20 total points
Comment Utility
Here are the messages that can be send for DDE through SendMessage:

Following are the messages used with DDE.
WM_DDE_ACK
WM_DDE_ADVISE
WM_DDE_DATA
WM_DDE_EXECUTE
WM_DDE_INITIATE
WM_DDE_POKE
WM_DDE_REQUEST
WM_DDE_TERMINATE
WM_DDE_UNADVISE

Here is the explanation of each from Visual C/C++ Online Help:

The WM_DDE_ACK message notifies a DDE application of the receipt and processing of a WM_DDE_POKE, WM_DDE_EXECUTE, WM_DDE_DATA, WM_DDE_ADVISE, WM_DDE_UNADVISE, or WM_DDE_INITIATE message, and in some cases, of a WM_DDE_REQUEST message.
WM_DDE_ACK  
// Response to WM_DDE_INITIATE
wParam = (WPARAM) hwnd;          // handle of posting application
lParam = MAKELPARAM(aApp, aTopic) // application and topic atoms
 
// Response to WM_DDE_EXECUTE
wParam = (WPARAM) hwnd;         // handle of posting application
lParam = (LPARAM) lPackedVal;   // packed status flags and data handle
 
// Response to all other messages
wParam = (WPARAM) hwnd;         // handle of posting application
lParam = (LPARAM) lPackedVal;   // packed status flags and item
 
Parameters
When responding to WM_DDE_INITIATE:
hwnd
Value of wParam. Identifies the server window posting the message.
aApp
Value of the low-order word of lParam. Contains an atom that identifies the replying application.
aTopic
Value of the high-order word of lParam. Contains an atom that identifies the topic for which a conversation is being established.
When responding to WM_DDE_EXECUTE:
hwnd
Value of wParam. Identifies the server window posting the message.
lPackedVal
Value of lParam. The component parameters that are packed into lPackedVal are extracted by calling the UnpackDDElParam function. The low-order word is wStatus. The high-order word is the same hCommands that was received in the WM_DDE_EXECUTE message.
Parameter      Description
wStatus      Specifies a DDEACK structure containing a series of flags that indicate the status of the response.
hCommands      Identifies a global memory object that contains the command string.
 
When replying to all other messages:
hwnd
Value of wParam. Identifies the client or server window posting the message.
lPackedVal
Value of lParam. The component parameters that are packed into lPackedVal are extracted by calling the UnpackDDElParam function. The low-order word is wStatus. The high-order word is aItem.
Parameter      Description
wStatus      Specifies a DDEACK structure containing a series of flags that indicate the status of the response.
aItem      Contains a global atom that identifies the name of the data item for which the response is sent.
 
Remarks
Posting
Except in response to the WM_DDE_INITIATE message, the application posts the WM_DDE_ACK message by calling the PostMessage function, not by calling the SendMessage function. When responding to WM_DDE_INITIATE, the application sends the WM_DDE_ACK message by calling SendMessage. In this case, neither the application-name atom nor the topic-name atom should be NULL (even if the WM_DDE_INITIATE message specified NULL atoms).
When acknowledging any message with an accompanying aItem atom, the application posting WM_DDE_ACK can either reuse the aItem atom that accompanied the original message, or it can delete it and create a new one.
When acknowledging WM_DDE_EXECUTE, the application that posts WM_DDE_ACK should reuse the global memory object identified in the original WM_DDE_EXECUTE message.
All posted WM_DDE_ACK messages must create or reuse the lPackedVal parameter by calling the PackDDElParam function or the ReuseDDElParam function.
If an application has initiated the termination of a conversation by posting WM_DDE_TERMINATE and is awaiting confirmation, the waiting application should not acknowledge (positively or negatively) any subsequent messages sent by the other application. The waiting application should delete any atoms or shared memory objects received in these intervening messages. Memory objects should not be freed if the fRelease flag is set to FALSE in WM_DDE_POKE, and WM_DDE_DATA messages.
Receiving
The application that receives a WM_DDE_ACK message should delete all atoms accompanying the message. If the application receives a WM_DDE_ACK in response to a message with an accompanying hData object, and the object was sent with the fRelease flags set to FALSE, the application is responsible for deleteing the hData object.
If the application receives a negative WM_DDE_ACK message posted in reply to a WM_DDE_ADVISE message, the application should delete the global memory object posted with the original WM_DDE_ADVISE message (in hOptions). If the application receives a negative WM_DDE_ACK message posted in reply to a WM_DDE_DATA, WM_DDE_POKE, or WM_DDE_EXECUTE message, the application should delete the global memory object posted with the original WM_DDE_DATA, WM_DDE_POKE, or WM_DDE_EXECUTE message (in hCommands).
The application that receives a posted WM_DDE_ACK message must free the lPackedVal parameter by using the FreeDDElParam function.
See Also
DDEACK, FreeDDElParam, PackDDElParam, PostMessage, ReuseDDElParam, SendMessage, UnpackDDElParam, WM_DDE_ADVISE, WM_DDE_DATA, WM_DDE_EXECUTE, WM_DDE_INITIATE, WM_DDE_POKE, WM_DDE_REQUEST, WM_DDE_TERMINATE, WM_DDE_UNADVISE

A DDE client application posts the WM_DDE_ADVISE message to a DDE server application to request the server to supply an update for a data item whenever the item changes.
WM_DDE_ADVISE  
wParam = (WPARAM) hwnd;        // handle of posting application
lParam = (LPARAM) lPackedVal;  // packed DDEADVISE and item atom
 
Parameters
hwnd
Value of wParam. Identifies the client window posting the message.
lPackedVal
Value of lParam. The component parameters packed into lPackedVal are extracted by calling the UnpackDDElParam function. The low-order word is hOptions. The high-order word is aItem.
Parameter      Description
hOptions      Identifies a global memory object containing a DDEADVISE structure that specifies how the data is to be sent.
aItem      Contains an atom that identifies the requested data item.
 
Remarks
If a client application supports more than one clipboard format for a single topic and item, it can post multiple WM_DDE_ADVISE messages for the topic and item, specifying a different clipboard format with each message. Note that a server can support multiple formats only for hot data links, not warm data links.
Posting
The client application posts the WM_DDE_ADVISE message by calling the PostMessage function, not the SendMessage function.
The client application allocates hOptions by calling the GlobalAlloc function with the GMEM_DDESHARE option. It allocates aItem by calling the GlobalAddAtom function.
The client application must create or reuse the WM_DDE_ADVISE lPackedVal parameter by calling the PackDDElParam function or the ReuseDDElParam function with hOptions supplied as the low-order word and aItem supplied as the high-order word.
If the receiving (server) application responds with a negative WM_DDE_ACK message, the posting (client) application must delete the hOptions object.
The fRelease flag is not used in WM_DDE_ADVISE messages, but their data-freeing behavior is similar to that of WM_DDE_DATA and WM_DDE_POKE messages where fRelease is TRUE.
Receiving
The server application posts the WM_DDE_ACK message to respond positively or negatively. When posting WM_DDE_ACK, the application can reuse the aItem atom or delete it and create a new one. If the WM_DDE_ACK message is positive, the application should delete the hOptions object; otherwise, the application should not delete the object.
The server must create or reuse the WM_DDE_ACK lPackedVal parameter by calling the PackDDElParam function or the ReuseDDElParam function with wStatus supplied as the low-order word and aItem supplied as the high-order word.
See Also
DDEADVISE, FreeDDElParam, GlobalAddAtom, GlobalAlloc, PackDDElParam, PostMessage, ReuseDDElParam, SendMessage, UnpackDDElParam, WM_DDE_ACK, WM_DDE_DATA, WM_DDE_POKE, WM_DDE_REQUEST

A DDE server application posts a WM_DDE_DATA message to a DDE client application to pass a data item to the client or to notify the client of the availability of a data item.
WM_DDE_DATA  
wParam = (WPARAM) hwnd;         // handle of posting application
lParam = (LPARAM) lPackedVal;   // packed DDEDATA and item atom
 
Parameters
hwnd
Value of wParam. Identifies the server window posting the message.
lPackedVal
Value of lParam. The component parameters that are packed into lPackedVal are extracted by calling the UnpackDDElParam function. The low-order word is hData or NULL. The high-order word is aItem.
Parameter      Description
hData      Identifies a global memory object containing a DDEDATA structure with the data and additional information. The handle should be set to NULL if the server is notifying the client that the data-item value has changed during a warm data link. A warm link is established by the client sending a WM_DDE_ADVISE message with the fDeferUpd bit set.
aItem      Contains an atom that identifies the data item for which the data or notification is sent.
 
Remarks
Posting
The server application posts the WM_DDE_DATA message by calling the PostMessage function, not the SendMessage function.
The server application allocates hData by calling the GlobalAlloc function with the GMEM_DDESHARE option. It allocates aItem by calling the GlobalAddAtom function.
The server must create or reuse the WM_DDE_DATA lPackedVal parameter by calling the PackDDElParam function or the ReuseDDElParam function with hData supplied as the low-order word and aItem supplied as the high-order word.
If the receiving (client) application responds with a negative WM_DDE_ACK message, the posting (server) application must delete the hData object; otherwise, the client must delete the hData object after extracting its contents by calling the UnpackDDElParam function.
If the server application sets the fRelease member of the DDEDATA structure to FALSE, the server is responsible for deleting hData upon receiving either a positive or negative acknowledgement.
The server application should not set both the fAckReq and fRelease members of the DDEDATA structure to FALSE. If both members are set to FALSE, it is impossible for the server to determine when to delete hData.
Receiving
If fAckReq is TRUE, the client application should post the WM_DDE_ACK message to respond positively or negatively. When posting WM_DDE_ACK, the client can either reuse the aItem atom, or it can delete it and create a new one.
The client must create or reuse the WM_DDE_ACK lPackedVal parameter by calling the PackDDElParam function or the ReuseDDElParam function with wStatus supplied as the low-order word and aItem supplied as the high-order word.
If fAckReq is FALSE, the client application should delete the aItem atom.
If the posting (server) application specified hData as NULL, the receiving (client) application can request the server to send the data by posting a WM_DDE_REQUEST message.
After processing a WM_DDE_DATA message in which hData is not NULL, the client should free hData, unless one of the following conditions is true:
7      The fRelease member is FALSE.
7      The fRelease member is TRUE, but the client application responds with a negative WM_DDE_ACK message.
 
See Also
DDEDATA, FreeDDElParam, GlobalAddAtom, GlobalAlloc, PackDDElParam, PostMessage, ReuseDDElParam, SendMessage, UnpackDDElParam, WM_DDE_ACK, WM_DDE_ADVISE, WM_DDE_POKE, WM_DDE_REQUEST

A DDE client application posts a WM_DDE_EXECUTE message to a DDE server application to send a string to the server to be processed as a series of commands. The server application is expected to post a WM_DDE_ACK message in response.
WM_DDE_EXECUTE  
wParam = (WPARAM) hwnd;        // handle of posting application
lParam = (LPARAM) hCommands;   // handle to global object
 
Parameters
hwnd
Value of wParam. Identifies the client window posting the message.
hCommands
Value of lParam. Contains a global memory object that references an ANSI or Unicode command string, depending on the types of windows involved in the conversation.
 
Remarks
The command string is a null-terminated string consisting of one or more opcode strings enclosed in single brackets ([ ]).
Each opcode string has the following syntax, where the parameters list is optional:
opcode parameters
The opcode is any application-defined single token. It cannot include spaces, commas, parentheses, brackets, or quotation marks.
The parameters list can contain any application-defined value or values. Multiple parameters are separated by commas, and the entire parameter list is enclosed in parentheses. Parameters cannot include commas or parentheses except inside a quoted string. If a bracket or parenthesis character is to appear in a quoted string, it need not be doubled, as was the case under the old rules.
Following are some valid command strings:
[connect][download(query1,results.txt)][disconnect]  
[query("sales per employee for each district")]
[open("sample.xlm")][run("r1c1")]
[quote_case("This is a "" character")]
[bracket_or_paren_case("()s or []s should be no problem.")]
 
Note that, under the old rules, parentheses and brackets had to be doubled, as follows:
[bracket_or_paren_case("(())s or [[]]s should be no problem.")]  
 
Servers should be able to parse commands in either form.
Unicode execute strings should be used only when both the client and server window handles cause the IsWindowUnicode function to return TRUE.
Posting
The client application posts the WM_DDE_EXECUTE message by calling the PostMessage function, not the SendMessage function.
The client application allocates hCommands by calling the GlobalAlloc function with the GMEM_DDESHARE option.
When processing the WM_DDE_ACK message that the server posts in reply to a WM_DDE_EXECUTE message, the client application must delete the hCommands object sent back in the WM_DDE_ACK message.
Receiving
The server application posts the WM_DDE_ACK message to respond positively or negatively. The server should reuse the hCommands object.
Unless specified otherwise by a sub-protocol, the server should not post the WM_DDE_ACK message until all the actions specified by the execute command string are completed. The one exception to this rule is when the string causes the server to terminate the conversation.
See Also
GlobalAlloc, IsWindowUnicode, PackDDElParam, PostMessage, ReuseDDElParam, SendMessage, UnpackDDElParam, WM_DDE_ACK


A DDE client application sends a WM_DDE_INITIATE message to initiate a conversation with a server application responding to the specified application and topic names. Upon receiving this message, all server applications with names that match the specified application and that support the specified topic are expected to acknowledge it. (For more information, see the WM_DDE_ACK message.)
WM_DDE_INITIATE  
wParam = (WPARAM) hwnd;             // handle of posting appl.
lParam = MAKELPARAM(aApp, aTopic);  // appl. and topic atoms
 
Parameters
hwnd
Value of wParam. Identifies the client window sending the message.
aApp
Value of the low-order word of lParam. Contains an atom that identifies the application with which a conversation is requested. The application name cannot contain slashes (/) or backslashes (\). These characters are reserved for network implementations. If aApp is NULL, a conversation with all applications is requested.
aTopic
Value of the high-order word of lParam. Contains an atom that identifies the topic for which a conversation is requested. If the topic is NULL, conversations for all available topics are requested.
 
Remarks
If aApp is NULL, any server application can respond. If aTopic is NULL, any topic is valid. Upon receiving a WM_DDE_INITIATE request with the aTopic parameter set to NULL, a server must send a WM_DDE_ACK message for each of the topics it supports.
Sending
The client application sends WM_DDE_INITIATE by calling the SendMessage function, not the PostMessage function. The client broadcasts the message to all top-level windows by setting the first parameter of SendMessage to -1.
If the client application has already obtained the window handle of the desired server, it can send WM_DDE_INITIATE directly to the server window by passing the server's window handle as the first parameter of SendMessage.
The client application allocates aApp and aTopic by calling GlobalAddAtom.
When SendMessage returns, the client application must delete the aApp and aTopic atoms.
Receiving
To complete the initiation of a conversation, the server application must respond with one or more WM_DDE_ACK messages, where each message is for a separate topic. When sending WM_DDE_ACK message, the server should create new aApp and aTopic atoms; it should not reuse the atoms sent with WM_DDE_INITIATE.
See Also
GlobalAddAtom, GlobalAlloc, PostMessage, SendMessage, WM_DDE_ACK


A DDE client application posts a WM_DDE_POKE message to a DDE server application. A client uses this message to request the server to accept an unsolicited data item. The server is expected to reply with a WM_DDE_ACK message indicating whether it accepted the data item.
WM_DDE_POKE  
wParam = (WPARAM) hwnd;        // handle of posting application
lParam = (LPARAM) lPackedVal;  // packed DDEPOKE and item atom
 
Parameters
hwnd
Value of wParam. Identifies the client window posting the message.
lPackedVal
Value of lParam. The component parameters that are packed into lPackedVal are extracted by calling the UnpackDDElParam function. The low-order word is hData. The high-order word is aItem.
Parameter      Description
hData      Identifies a global memory object containing a DDEPOKE structure with the data and additional information.
aItem      Contains a global atom that identifies the data item for which the data or notification is being sent.
 
Remarks
Posting
The client application posts the WM_DDE_POKE message by using the PostMessage function.
The client application must allocate memory for the hData object by using the GlobalAlloc function with the GMEM_DDESHARE option. The client application must delete the hData object if either of the following conditions is true:
7      The server application responds with a negative WM_DDE_ACK message.
7      The fRelease member is FALSE, but the server application responds with either a positive or negative WM_DDE_ACK.
 
The client application must create the aItem atom by using the GlobalAddAtom function.
The client application must create or reuse the WM_DDE_POKE lPackedVal parameter by calling the PackDDElParam function or the ReuseDDElParam function with hData supplied as the low-order word and aItem supplied as the high-order word.
Receiving
The server application should post the WM_DDE_ACK message to respond positively or negatively. When posting WM_DDE_ACK, the server can either reuse the aItem atom, or it can delete it and create a new one.
The server must create or reuse the WM_DDE_ACK lPackedVal parameter by calling the PackDDElParam function or the ReuseDDElParam function with wStatus supplied as the low-order word and aItem supplied as the high-order word.
To free the hData object, the server should call the GlobalFree function. Also, if the data format is either CF_DSPMETAFILEPICT or CF_METAFILEPICT, the server must also call DeleteMetaFile with the embedded metafile handle. These two formats have an extra level of indirection; that is, an application must lock hData to get a pointer to a handle, then lock that handle to get a pointer to a METAFILEPICT structure, and finally call DeleteMetaFile with the handle from the hMF member of the METAFILEPICT structure.
To free the lPackedVal object, the server should call the FreeDDElParam function.
See Also
DDEPOKE, DeleteMetaFile, FreeDDElParam, GlobalAddAtom, GlobalAlloc, GlobalFree, METAFILEPICT, PackDDElParam, PostMessage, ReuseDDElParam, SendMessage, UnpackDDElParam, WM_DDE_ACK


A DDE client application posts a WM_DDE_REQUEST message to a DDE server application to request the value of a data item.
WM_DDE_REQUEST  
wParam = (WPARAM) hwnd;        // handle of posting application
lParam = (LPARAM) lParam;      // holds cfFormat and aItem
 
Parameters
hwnd
Value of wParam. Identifies the client window sending the message.
lParam
Holds the cfFormat and aItem parameters.
Parameter      Description
cfFormat      This is the LOWORD of lParam. Specifies a standard or registered clipboard format.
aItem      This is the HIWORD of lParam. Contains an atom that identifies the data item requested from the server.
 
Remarks
Posting
The client application posts the WM_DDE_REQUEST message by calling the PostMessage function, not the SendMessage function.
The client application allocates aItem by calling the GlobalAddAtom function.
Receiving
If the receiving (server) application can satisfy the request, it responds with a WM_DDE_DATA message containing the requested data. Otherwise, it responds with a negative WM_DDE_ACK message.
When responding with either a WM_DDE_DATA or WM_DDE_ACK message, the server application can either reuse the aItem atom or it can delete the atom and create a new one.
See Also
GlobalAddAtom, PackDDElParam, PostMessage, ReuseDDElParam, SendMessage, UnpackDDElParam, WM_DDE_ACK, WM_DDE_DATA


A DDE application (client or server) posts a WM_DDE_TERMINATE message to terminate a conversation.
WM_DDE_TERMINATE  
wParam = (WPARAM) hwnd; // handle of posting window
lParam = 0;             // not used, must be zero
 
Parameters
hwnd
Value of wParam. Identifies the client or server window posting the message.
 
Remarks
Posting
The client or server application posts the WM_DDE_TERMINATE message by calling the PostMessage function, not the SendMessage function.
While waiting for confirmation of the termination, the posting application should not post any other messages to the receiving application. If the sending application receives messages (other than WM_DDE_TERMINATE) from the receiving application, it should delete any atoms or shared memory objects accompanying the messages, except hData objects associated with WM_DDE_POKE or WM_DDE_DATA messages that do not have the fRelease flag set.
Receiving
The client or server application should respond by posting a WM_DDE_TERMINATE message.
See Also
PostMessage, SendMessage, WM_DDE_DATA, WM_DDE_POKE


A DDE client application posts a WM_DDE_UNADVISE message to inform a DDE server application that the specified item or a particular clipboard format for the item should no longer be updated. This terminates the warm or hot data link for the specified item.
WM_DDE_UNADVISE  
wParam = (WPARAM) hwnd;        // handle of posting application
lParam = (LPARAM) lParam;      // format and item atom
 
Parameters
hwnd
Value of wParam. Identifies the client window sending the message.
lParam
Holds the cfFormat and aItem parameters.
Parameter      Description
cfFormat      This is the LOWORD of lParam. Specifies the clipboard format of the item for which the update request is being retracted. If cfFormat is NULL, all active WM_DDE_ADVISE conversations for the item are to be terminated.
aItem      This is the HIWORD of lParam. Contains a global atom that identifies the item for which the update request is being retracted. When aItem is NULL, all active WM_DDE_ADVISE links associated with the conversation are to be terminated.
 
Remarks
Posting
The client application posts the WM_DDE_UNADVISE message by calling the PostMessage function, not the SendMessage function.
The client application allocates aItem by calling the GlobalAddAtom function.
Receiving
The server application posts the WM_DDE_ACK message to respond positively or negatively. When posting WM_DDE_ACK, the server can either reuse the aItem atom, or it can delete the atom and create a new one.
See Also
GlobalAddAtom, PackDDElParam, PostMessage, ReuseDDElParam, SendMessage, UnpackDDElParam, WM_DDE_ACK, WM_DDE_ADVISE

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

12 Experts available now in Live!

Get 1:1 Help Now