Hello, I'm receiving the following error message. I know I'm missing something simple, but I can't figure out what it is.
Possibly a local DLL security issue? I have been able to reference winmm.dll 's other methods without a problem though.
The only thing I can think of is I'm sending invalid Types.
Tested in VS 2005 (.NET 2.0), and C# Express 2008 (.NET 3.5)
I'm not an expert at making native calls but there are a few things that don't look right to me.
1) C# long is not necessarily the same as C/C++ long.
2) In mciGetErrorString param #3 represents the length of the buffer that param #2 points to, but you're passing in an empty string which is length zero and telling mciGetErrorString that it's 128 chars long. I think to return a string from native code to managed code you need to create a StringBuilder of the appropriate length and use that. In the article you linked to see how he used a StringBuilder for the variable strReturn in the declaration of mciSendString even though when he calls that function he passes null for the string pointer and zero for the length.
Yep, you guys were right on. The C++ to C# conventions types threw me a bit off. TY TY.
Now... You wouldn't have any idea why I can make winmm.dll MCI device calls from a windows forms app but not a console app? I believe a windows forms app uses the default sound device, but the console app attempts to use it (the default one windows is probably holding onto) and windows tells it...
"Unknown problem while loading the specified device driver."
This error shows up regardless if the audio file path is valid or not.
I would think the windows console process would have access to the windows audio devices.
I used the final code below to generate the error. Works in a form app, not in a console app.
VS 2005, and C# 2008.
Code is as follows...
[System.Runtime.InteropServices.DllImport("winmm.dll", EntryPoint = "mciGetErrorString")]
public static extern bool mciGetErrorString(int dwError, StringBuilder lpstrBuffer, int uLength);
private static extern int mciSendString(string strCommand, string strReturn, int iReturnLength, IntPtr hwndCallback);
static void Main(string args)
string Pcommand = "open \"" + "C:\\SomeNonExistantFile.mp3" + "\" type mpegvideo alias MediaFile";
int err = mciSendString(Pcommand, null, 0, IntPtr.Zero);
StringBuilder text = new StringBuilder(128, 128);
mciGetErrorString(err, text, int.MaxValue);
Console.WriteLine("Press Any Key");
audio yes, but video no. the type in your Pcommand is mpegvideo, but should a console app be able to play movies? the command succeeded when i tried it with a type waveaudio..
Also, if you pass a value into mciGetErrorString that is larger than the space that you have allocated for the buffer, then it will be able to write to invalid memory. Since the SB has a capacity of 128 it makes sense to pass in 128 instead of int.MaxValue
Yeah, good call on the SB, I just ran into the overflow problem. I made that change. Thanks!
Your right concerning the type also.
The reason I was using the mpegvideo instead of waveaudio was the decoder/codec functions of the mpegvideo option (specifically MP3's) eg. console mp3 player. From what I can tell, I have been unsuccessful in getting waveaudio to use MP3's. I believe it was designed for raw WAV's only.
I was hoping to stick with winmm.dll for the consistency. Any suggested workarounds? Time for a new lib?
DWORDs will never be a C# long - they are always unsigned 32-bit ints.
A BOOL is an int, which is a 32-bit signed int.
As Jimmanuel mentioned, you also can't use a string as an out parameter like that.
Put that all together and something like this should work:
i want to trace my application to get information how much memory allocate to each objects and ...
does visual studio has this tool ? (i don't implement this by code, i want to trace my app visually)
how to do ?
You can do this through VSTO or other third party software.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Microsoft Office Word Viewer 2003 lets you view and print Word documents on a computer that does not have Word installed. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
889347 (http://support.microsoft.com/kb/889347/) Description of the Microsoft Office Word Viewer 2003