Playing mp3 files with mciSendString (MCIERR_CANNOT_LOAD_DRIVER) - c++

I am trying to write some code that can play an .mp3 file. I thought I could use the mciSendString call, but I am getting a strange error.
So, when I have this code:
int rc=mciSendString(L"open songname.mp3 alias song1", NULL, 0, 0);
rc returns with the number 266, and the error string returned with GetErrorString was:
"Unknown problem while loading the specified device driver."
Error 266 is MCIERR_CANNOT_LOAD_DRIVER
I have also tried:
int rc=mciSendString(L"open songname.mp3 type mpegvideo alias song1", NULL, 0, 0);
and received the same error.
I thought it may be the mp3 file, but I tried a few different ones and kept getting the same error.
My code is in C++ and is running on Windows 7. Is my code missing something?

Try surrounding songname.mp3 with an extra pair of quotes (be sure to escape them with backslashes).

It looks like I didn't have an mp3 codec for MCI. (Actually answered by #LightnessRacesinOrbit in comments to the question.)

Related

Error loading cr2 with edsdk

I am trying to read cr2 images using canon sdk (canon_edsdk-2.12).
I seem to be loading the dll correctly, but when I try to get the actual image, I get an error.
I tried to run the sample program to see how that is different than mine, but the same thing happens.
Trying to look for the issue on the web, I found the actual source code of the sample: http://read.pudn.com/downloads107/sourcecode/graph/texture_mapping/440409/RAWDevelop/RAWDevelopDlg.cpp__.htm
My error, on the given source, is in the void CRAWDevelopDlg::LoadImage() function -
err = EdsGetImage( m_ImageRef , source , kEdsTargetImageType_RGB , rect , size , DstStreamRef );
if( err == EDS_ERR_OK ) {...}
else
{
AfxMessageBox("The error occurred with the EdsGetImage function.");
}
The above (on line 481 on the page) is the same method that I use, and i get the same error - with error code 35 (instead of 0).
The error seems to be
#define EDS_ERR_FILE_OPEN_ERROR 0x00000023L
So... could there be something wrong with the files ? I experimented with files taken by different versions, including the newest cameras... The files open in Photoshop... And the demo does show header information, as it gives the error. So it can see something.
Am I missing anything ?
All the required dll's used are on the system path...
Thank you.
Old question, still, might help someone:
To open a raw file with the SDK you need to call these functions (you should check for errors, of course):
EdsStreamRef stream = NULL;
EdsImageRef imgRef = NULL;
EdsCreateFileStream("filename", kEdsFile_OpenExisting, kEdsAccess_Read, &stream);
EdsCreateImageRef(stream, &imgRef);
EdsRelease(stream);
Then you can set and get properties with the imgRef.
To save the image as jpg/tiff/RGB image use EdsSaveImage function.

Use relative file path with LoadImage

I am attempting to load a file from a relative file path in win32 via the LoadImage function. The URL I am using definitely exists as I am, for testing purposes, using the same URL as an added bitmap in the resource file.
Image = (HBITMAP)LoadImage(NULL, "..\\..\\Images\\Mage default.bmp",
IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
However, it is returning error code 2, indicating the file can't be found. I have googled the issue at some length, and referred to MSDN, and I can't find anything stating how to use a relative file path with LoadImage.
It seems to work fine with LoadBitmap and a pre-defined bitmap, but doesn't seem to work in this case. Any help would be much appreciated
First of all, check that the file exist and current directory is the one you expected.
Also, you can use function like GetFullPathName to convert relative path to absolute.
The relative path you have is computed based on your process/run time working directory and not on your static files location in compile time.
This may be an old post, but having stumbled across this problem (in my case, a header file) and found an answer, here it is:
If referencing a relative path, the first directory is not preceeded by a backslash.
In this example, the line would be:
(HBITMAP)LoadImage(NULL,"Images\\Mage default.bmp",...

Streaming MP3 from Internet with FMOD

I thought this would be a relatively simple task with something like FMOD, but I can't get it to work. Even the example code netstream doesn't seem to do the trick. No matter what mp3 I try to play with the netstream example program, I get this error:
FMOD error! (20) Couldn't perform seek operation. This is a limitation of the medium (ie netstreams) or the file format.
I don't really understand what this means. Isn't this exactly what the netstream example program was for? to stream some file from the internet?
I can't get passed the createSound method
result = system->createSound(argv[1], FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING, 0, &sound);
EDIT:
This is what I modified after reading Mathew's answer
FMOD_CREATESOUNDEXINFO soundExInfo;
memset(&soundExInfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
soundExInfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
soundExInfo.suggestedsoundtype = FMOD_SOUND_TYPE_MPEG;
result = system->createSound(argv[1], FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING | FMOD_IGNORETAGS, &soundExInfo, &sound);
I get two different errors depending on which files I use.
Test 1
URL: http://kylegobel.com/test.mp3
Test 1 Error: (25) Unsupported file or audio format.
Test 2 URL: http://kylegobel.com/bullet.mp3
Test 2 Error: (20) Couldn't perform seek operation. This is a limitation of the medium (ie netstreams) or the file format.
Before I made the change, I could use netstream to play "C:\test.mp3" which is the same file named test.mp3 on the web, but that no longer works with the above changes. Maybe these files are just in the wrong formats or something? Sorry for my lack of knowledge in this area, I really don't know much about sound, but trying to figure it out.
Thanks,
Kyle
It's possible the MP3 has a large amount of tags at the start, so FMOD reads them then tries to seek back to the start (which it can't do because it's a net stream). Can you try using FMOD_IGNORETAGS and perhaps FMOD_CREATESOUNDEXINFO with suggestedsoundtype set to FMOD_SOUND_TYPE_MPEG?
If that does't work could you post the url to a known not working MP3 stream?
EDIT:
The file in question has around 60KB of tag data, FMOD is happy to read over that stuff but for the MPEG codec to work it needs to do some small seeks. Since you cannot seek a netstream all the seeks must be contained inside the low level file buffer. If you tweak the file buffer size, make it a bit larger you can overcome this restriction. See System::setFileSystem "blockalign" parameter.

MCI_OPEN fails for mp3 files in a C++ console application

This is what I did:
DWORD dwReturn;
MCI_OPEN_PARMS mciOpenParms;
mciOpenParms.lpstrDeviceType = _T("MPEGvideo");
mciOpenParms.lpstrElementName = m_tmpFileName;
dwReturn = mciSendCommand(NULL, MCI_OPEN,
MCI_OPEN_TYPE | MCI_OPEN_ELEMENT,
(DWORD)(LPVOID) &mciOpenParms);
if (dwReturn)
{
wchar_t chError[100];
mciGetErrorString(dwReturn,chError,sizeof(chError));
//report the error here
}
When I run the code, I see that dwReturn is 266 and chError is set to "Unknown problem while loading the specified device driver". What could be wrong?
Note: I also tried "mpegvideo" instead of "MPEGvideo"; it didn't help. Where are these things documented anyway?
It works for me. Maybe (likely) you have the MCI register all screwed up. Or maybe the file you are opening is corrupted somehow.
As far as I know these device names are not documented anywhere. But you can find the ones configured in your system in the registry: HKLM\Software\Microsoft\Windows NT\CurrentVersion\MCI32. My system has:
AVIVideo
CDAudio
MPEGVideo
Sequencer
WaveAudio
And given that the MCI is not used much nowadays, I'd say that they are pretty standard.
If you're specifying MCI_OPEN_ELEMENT then mciOpenParms.lpstrDeviceType must be null.
See the Remarks section.
*To use automatic type selection (via the entries in the registry), assign the filename and file extension to the lpstrElementName member of the structure identified by lpOpen, set the lpstrDeviceType member to NULL, and set the MCI_OPEN_ELEMENT flag.*

Deleting a bitmap resource in Visual C++

I am trying to delete a resource bitmap through code and am having trouble doing it. Went through several hours of headbanging with google. Here is the code:
int result;
HANDLE h;
h = BeginUpdateResource(L"C:\\Users\\Steve\\Desktop\\stub.exe", FALSE);
result = UpdateResource(h, RT_BITMAP, MAKEINTRESOURCE(IDB_BITMAP2), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0);
EndUpdateResource(h, FALSE);
When I debug, variable "result" ends up being NULL which means that the update didn't go through. Is there something incredibly basic that I'm missing?
Ok, I figured out what went wrong. First off, I used the "GetLastError()" command to help widdle down the possibilities. It gave me an error 0x57 which means ERROR_INVALID_PARAMETER.
When I experimented more, it seems that in the language paramters, I listed "MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)" instead of "MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)". Apparently, resources care about the language you are using even if it's something like a bitmap which doesn't use language.
Once I put in LANG_ENGLISH paramters, it worked. You can find out what language you are using by inspecting the text of the .rc that the resource is using to build.,