LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to Communicate with WinAmp

Solved!
Go to solution

Hi,

 

I am trying to communicate with WinAmp (MP3 player) through the sendmessage function in User32.dll

So far I can send commands like play, stop, forward, play next etc. but sending a filename to play gives no result.

 

 

This is the structure of the command: 

 

 

#define IPC_ENQUEUEFILE 100
/* This is sent as a WM_COPYDATA with IPC_PLAYFILE as the dwData member and the string
** of the file / playlist to be enqueued into the playlist editor as the lpData member.
** This will just enqueue the file or files since you can use this to enqueue a playlist.
** It will not clear the current playlist or change the playback state.
**
** COPYDATASTRUCT cds = {0};
**   cds.dwData = IPC_ENQUEUEFILE;
**   cds.lpData = (void*)"c:\\test\\folder\\test.mp3";
**   cds.cbData = lstrlen((char*)cds.lpData)+1;  // include space for null char
**   SendMessage(hwnd_winamp,WM_COPYDATA,0,(LPARAM)&cds);
**

 

WM_COPYDATA = 0x4A

 

In the VI you can see what I did. Before running the VI WinAmp must be already started. The led "windowfound" should be on.

I tried several things but no luck so far.

 

Can someone help me out with this problem ?

0 Kudos
Message 1 of 10
(5,417 Views)
Hi,

Can you post your code as 8.5? Or pist a picture?

I can't see it now (since it's 8.5), but I can guess what is wrong.

You probably made a cluster with the file name in it. This is where C
clusters are different from LabVIEW cluster. In LabVIEW, the actual string
data is in the memoery structure of the cluster, while in C (C++), the
string element is a pointer to the string data. So, you need to get some
memory (with LabVIEW's memory API's, Windows heap functions, or from a home
made dll), fill it with your string, and get a pointer to that data. Then
pass that pointer (an U32) to the dll.

Regards,

Wiebe.


0 Kudos
Message 2 of 10
(5,397 Views)

Hallo Wiebe,

 

I didn't make a cluster, but I tried to format a string with the data.

But as I understand you I have to do something else.

 

Here are the VI's in 8.0  (I also forgot the sub vi and a control)

0 Kudos
Message 3 of 10
(5,391 Views)
Solution
Accepted by K C
But you are clustering it! If you'd make a cluster, and flatten it, it would
look similar.

COPYDATASTRUCT cds = {0};
cds.dwData = IPC_ENQUEUEFILE;
cds.lpData = (void*)"c:\\test\\folder\\test.mp3;
cds.cbData = lstrlen((char*)cds.lpData)+1;  // include space for null
char
SendMessage(hwnd_winamp,WM_COPYDATA,0,(LPARAM)&cds);

The Data member is, an lp member, which indicates it is a pointer to the
string, not the string itself. Also, if you look it up in the header files
of C, the actual definition is:

struct COPYDATASTRUCT{
int dwData;
int cbData;
int lpData;
}

So, the string size should be before the string, not after. The example C
code is still correct, since they point the values to elements, the order is
irrelevant.

Use DSNewPtr(Size) to get a pointer to a memory block. Use MoveBlock(*src,
*dest, size) to move your string to this block (make *src a string input,
and * dest the new pointer).. Don't forget to call DSDisposePtr(*p) to
release the memory when done.

The prototypes are in the labview directory under cintools\extcode.h . In
the call libray node, you should simply type "labview" as library name.

Your "cluster" should have three U32 (or I32) values, dwData, cbData,
lpData. You could simply make a cluster with the three parameters, and set
the dll to adapt to type.

Regards,

Wiebe.


Message 4 of 10
(5,376 Views)

Wiebe, Thank you for your reply. It is not exactly clear to me (yet) but I will look into it and let you know.

 

Groeten, Kees

0 Kudos
Message 5 of 10
(5,349 Views)

"K C" <x@no.email> wrote in message
news:1234861806410-854460@exchange.ni.com...
> Wiebe, Thank you for your reply. It is not exactly clear to me (yet) but I
will look into it and let you know.&nbsp;Groeten, Kees

Kees,

Don't be afraid to pick up the phone. Our number is on our website.

Groeten,

Wiebe.


0 Kudos
Message 6 of 10
(5,344 Views)

Hi Wiebe,

 

Took me some time, but I got it working. See attached files.

 

Again thank you very much

 

Kees

Message 7 of 10
(5,314 Views)
Kees,

Looks ok. Thanks for posting, it might be usefull to future readers.

Regards,

Wiebe.


0 Kudos
Message 8 of 10
(5,302 Views)
Thank you for your priory information. I need to communicate with a C++ program using WM_COPYDATA. Since I need to send as well as receive data, I tried to write codes that send and receive WM_COPYDATA in LabVIEW. I think I succeeded to send WM_COPYDATA by following your example. However, I could not succeed in retrieving received COPYSTURCTURE data. Since I receive pointer I think I need to retrieve the data from the memory. I tried to use Moveblock, however, I failed.  I am attaching my example codes. Please take a look and give me comments.
0 Kudos
Message 9 of 10
(4,679 Views)

Hi YKee,

 

I am interested in this topic. Do you have the sample code which is workable? I found the file "smlib_WM_main.zip ‏29 KB", but it cannot work correct for me. Receive side cannot receive the string. Anyway, thanks for your sample code.

0 Kudos
Message 10 of 10
(3,128 Views)