HI all,

Im trying to create a simple MP3 player. I hope that by amalgamating a series of strings, example 1, that they can collectively contain the full play and filename/path instruction instead of the self-contained method in example 2.

When I try to compile the solution in example 1 i get this error:-

error C2664: 'mciSendStringW' : cannot convert parameter 1 from 'System::String ^' to 'LPCWSTR'

parameter 1 being the 'spcomfull' part of this command 'mciSendString(spcomfull, NULL, 0, 0);'

The problem is, mciSendString wont allow a String^ to be used, it will allow
TCHAR spcomfull[PATH_MAX] = L"play bad.mp3"; but Im finding it a nightmare to convert String^ into TCHAR.
I really need the file to be stored as a string because i plan for the filename/path to be input by a user via a TextBox.
What I have noticed is that in Example 3 a media file can be opened and played via two commands and the filename/path is stored as myFile. Does anybody know the format in which the filename/path is taken from open to play commands, im guessing TCHAR??? Can I somehow manipulate alias myFile to take a String^ input???

Im beginning to think Im approaching the idea from the wrong angle? Any help would be really useful.
Cheers, Ian :)

Example 1
String^ spcom1 = "L\" play ";
String^ spcom2 = "bad.mp3";
String^ spcom3 = " \" ";
String^ spcomfull = spcom1+spcom2+spcom3;

mciSendString(spcomfull, NULL, 0, 0);

Example 2

mciSendString(L"play bad.mp3", NULL, 0, 0);

Example 3

mciSendString("open bad.mp3 type mpegvideo alias myFile", NULL, 0, 0);

mciSendString("play myFile", NULL, 0, 0);

Recommended Answers

All 6 Replies

How is this any different than your other thread?

The last post asks about String^ to TCHAR conversion and this one asks for peoples opinions on alternative approaches.
This post also asks about how mciSendString(L"open and mciSendString(L" and how the commands communicate (which is not mentioned in the previous post).
In fact it also mentions that the idea of converting String^ to TCHAR has been abandoned in favour of exploring other avenues.

It's still pretty much the same issue. I'd leave a link to this post at the end of your other one so people don't keep responding to it.

I've been looking around in the meantime, did you ever see this link http://www.dotnet247.com/247reference/msgs/25/129971.aspx (note their change to the method ending in "uni" in the second post). I think this is just one of those vexing things that arises with managed vs. unmanaged code (with all of the marshalling of pointers, etc. that has to go on).

Surely someone in the past used mci under C++/CLI, but those must be the people asking the question on the other boards.

>error C2664: 'mciSendStringW' : cannot convert parameter 1 from 'System:tring ^' to 'LPCWSTR'

Please show us your "DllImport" declaration.


Take a look at this sample:

using namespace System;
using namespace System::Text;

[System::Runtime::InteropServices::DllImport("winmm.dll")]
System::Int64 mciSendString(System::String ^strCommand, StringBuilder ^strReturn, long iReturnLength, int  hwndCallback);

int main(array<System::String ^> ^args)
{
    String^ spcom1 = "play"; 
    String^ spcom2 = "x:\\folder\\file.mp3";
    String^ spcomfull = spcom1+ " \"" + spcom2+ "\"";

    mciSendString(spcomfull,nullptr, 0,0);
    Console::Read();
	
    return 0;
}

I've found the answer,

std::wstring file;
std::wstring Command;

file = L"C:\\bad.mp3";

Command = L"play " + file + L" from 0";

mciSendString(Command.c_str(), NULL, 0, 0);

p.s use:-

#include <windows.h>
#include <mmsystem.h>
#pragma comment (lib, "winmm.lib")
#include <string>

I forgot to add, This method works in visual studio 2005 not 2010

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.