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
I need to automate a web application. For this I am using C#.net and a Libary called "WatIn" whose reference I got from article on this site.
Using this it is simple to automate the general web applications. But My problem is different.
Also the combo buttons are arranged just as "Help", "Links", etc links are on this site, the only difference being that I can identify all the menu items under Help using Internet Explorer Deloper toolbar..
Can anybody out there help me in accessing those elements which are not identified by the Internet Explorer Developer toolbar.
I want a customized treeview where i want checkbox in a haphazard manner for eg. sometime i want to add checkbox in both parent and child node, and sometimes only in child node. for that i am trying to override the TreeNode class,so that i can add that class object(node) when i need a node with checkbox else the default TreeNode object(for this node.DrawDefault = false) but not getting any clue. Can somebody plz help me out.