|
-
May 17th, 2001, 12:44 AM
#1
Thread Starter
Hyperactive Member
Last Question.
GOT ANOTHER QUESTION. HOW WOULD I USE THE mciSendString function to play a multimedia file. I want to use pure API. I know how to do it in vb6, so all i need is one conversion of how to open the multimedia file for PLAY, and then i can do the rest. heres the code in vb6 on opening the multimedia file. I WANT TO USE API ONLY. NO EXTERNAL MCI CONTROLS OR WHATEVER.
Code:
Dim cmdToDo As String * 255
Dim tmp As String * 255
Dim lenShort As Long
Dim ShortPathAndFile As String
Dim Filename As String
Filename = "C:\video.mpg"
lenShort = GetShortPathName(FileName, tmp, 255)
ShortPathAndFile = left$(tmp, lenShort) 'cut short path from buffer
cmdToDo = "open " & ShortPathAndFile & " type " & typeDevice & " Alias " & _
AliasName & " parent " & hWnd & " Style " & WS_CHILD
call mciSendString(cmdToDo, 0&, 0&, 0&)
If you can convert this one call, i will be glad to send u the finished multimedia player sourcecode once its done. The source and exe will be available for everyone to download once its done from my website anyways.
-
May 17th, 2001, 12:54 AM
#2
Thread Starter
Hyperactive Member
Forgot To Add One Thing.
I've already converted the GetShortPathName. The c++ code is below.
//i first call an opendialog function that assigns szFileName with a filepathname.
Code:
char szFileName[MAX_PATH];
long srtaviname[255];
GetShortPathName(szFileName, srtaviname, 255);
MessageBox(0, srtaviname, "Shortened Path",MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
-
May 17th, 2001, 01:29 AM
#3
Frenzied Member
Code:
char szFileName[MAX_PATH];
long szAviName[255];
long lenShort;
char szCmdToDo[255];
lenShort = GetShortPathName(szFileName, szAviName, 255);
MessageBox(0, szAviName, "Shortened Path",MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
char *szShortPathAndFile = new char[lenShort];
int x;
for(x = 0; x<lenShort; x++)
szShortPathAndFile[x] = szAviName[x];
sprintf(szCmdToDo, "open %s type %s alias %s parent %l style %l",
szShortPathAndFile,
typeDevice,
AliasName,
(long)hWnd,
(long)WS_CHILD);
delete [] szShortPathAndFile;
Well that should do it I think, not absolutely certain but I think so. You will have to change the types of the variables in the sprintf() format string to whatever the types of the variables you want in the string are, since I don't know what they are so I was just guessing. I'm also assuming you have the right headers included.
Harry.
"From one thing, know ten thousand things."
-
May 17th, 2001, 02:35 AM
#4
Thread Starter
Hyperactive Member
ran into yet another prob.
your code works and assigns all the strings into 1 string, but when you put
(long)hwnd, (long)WS_CHILD
all that outputs from those is
%l %l
the function needs the hWnd of the parent, and the WS_CHILD to open the video properly. the mcisendstring is returning 0 which means its the function is being called succesfully, but that doesn't neccesarly mean that its opening the way i want it too. here is the code i have done.
Code:
char szFileName[MAX_PATH];
long szAviName[255];
long lenShort;
char szCmdToDo[255];
GetFileName(hwnd, szFileName, FALSE); //here is the function for the open dialog
lenShort = GetShortPathName(szFileName, szAviName, 255);
char *szShortPathAndFile = new char[lenShort];
int x;
for(x = 0; x<lenShort; x++)
szShortPathAndFile[x] = szAviName[x];
sprintf(szCmdToDo, "open %s type %s Alias %s parent %s Style %l",
szShortPathAndFile,
"MPEGVideo",
"movie",
(long)hwnd,
(long)WS_CHILD);
dwreturn == mciSendString(szCmdToDo, 0, 0, 0);
sprintf(szCmdToDo, "play %s%s%s%s%s", "movie", " from ", "0", " to ", "1500");
SetWindowText(txtpass, itoa(dwreturn, buffer, 10));
delete [] szShortPathAndFile;
thats it. it runs without error, and returns 0. but i get no playback because of the 'hwnd', and the WS_CHILD.
-
May 17th, 2001, 03:04 AM
#5
Frenzied Member
Okay, it's because I assumed the type field character for a long variable was %l, but looking at the help files there isn't one for a long. So use an integer (they're the same thing with Windows anyway), which is %i.
Don't you check the help files and try to fix things?
Harry.
"From one thing, know ten thousand things."
-
May 17th, 2001, 03:10 AM
#6
Frenzied Member
Oh yeah, and this doesn't do anything:
Code:
dwreturn == mciSendString(szCmdToDo, 0, 0, 0);
== is for equality, = is for assignment. This is an expression, and isn't doing anything with the return value of the function.
I don't really see the point in your second sprintf() function either, you don't seem to be doing anything with that string, but I guess that's just because you didn't post all your code and you're doing something with it elsewhere.
Harry.
"From one thing, know ten thousand things."
-
May 17th, 2001, 03:20 AM
#7
Thread Starter
Hyperactive Member
uhh yea
yea ofcourse i look at the help files. but sometimes i donot know what to look for and thats why i turned to vb-world. like i tried looking for the %i, %s. tell me where to find or what to look under for these. i use borland c++ 5.0. i also believe that the %s for szShortPathAndFile is wrong also. it doesn't display when i get the outputed data. tell me what to look under and i will see if i can figure it out. thanx for all your help man, i really appreciate it.
-
May 17th, 2001, 03:31 AM
#8
Frenzied Member
Oh well I don't have Borland so I don't know what the help files are like for that. If you can't find something you can look in the MSDN library at http://msdn.microsoft.com
It's not the %s that's wrong, I forgot to put a null-terminator on the end of the string. Replace the for loop with this:
Code:
char *szShortPathAndFile = new char[lenShort+1];
int x;
for(x = 0; x<lenShort; x++)
szShortPathAndFile[x] = szAviName[x];
szShortPathAndFile[lenShort] = '\0';
Harry.
"From one thing, know ten thousand things."
-
May 17th, 2001, 03:45 AM
#9
Thread Starter
Hyperactive Member
didn't work.
yo that still doesn't output the filepathname. i'm not sure what your doing with the For statement otherwise i would try and fix it. u also changed how i go about getting the shortpathname, when my way worked right, why did u change it, i'm curious ?
-
May 17th, 2001, 03:49 AM
#10
Thread Starter
Hyperactive Member
i got it.
here is the old for loop
char *szShortPathAndFile = new char[lenShort];
int x;
for(x = 0; x<lenShort; x++)
szShortPathAndFile[x] = szAviName[x];
u had put to display the szShortPathAndFile when you were supposed to put szAviName. now it shows the filename.
-
May 17th, 2001, 03:51 AM
#11
Thread Starter
Hyperactive Member
-
May 17th, 2001, 04:08 AM
#12
Frenzied Member
Oh I didn't realise you already had the short filename - I was making a C++ version of the VB Left() function. Well you probably don't need the for statement then. Oops
Glad to hear it's working anyway.
Harry.
"From one thing, know ten thousand things."
-
May 17th, 2001, 05:05 AM
#13
Thread Starter
Hyperactive Member
yea :) Got another question though.
ok, i need to know the function for the InStr function in c++.
in vb6 its
InStr(1, string, "searchphrase")
i thought it would be the same in c++ as its an API call i believe but it says InStr is not a recognized function. i need to do this in order to get the size of a movie thats being played. when i call the function to get the size of the movie it returns 0 0 320 240 for a movie thats 320x240. in vb6, i would do the following to seperate into 2 seperate parts from the string 'size'.
Code:
sz1 = InStr(1, size, " ") 'find the space after the first character
sz2 = InStr(sz1 + 1, size, " ") 'find the space after the second space
sz1 = InStr(sz2 + 1, size, " ") 'find the space after the third space
width = Mid(size, s2, s1 - s2) 'get the 320
height = Mid(size, s1, s1 + 1) 'get the 240
i believe thats right, i did it from my head, but i'm pretty good in vb so i'm pretty sure it works. thanx for the input.
-
May 17th, 2001, 05:13 AM
#14
Frenzied Member
If you want to do a lot of this stuff you probably ought to use the STL string class. It has lots of methods, like substr() if I remember right. I think you would find things much less confusing with the string class.
You can make your own functions to do it with a little thought. Char strings are just arrays of characters. They're not hard to deal with.
If you want to use char arrays, there are some functions, like strstr() that do the things you want. I don't know them all though, I'd probably just make my own.
Harry.
"From one thing, know ten thousand things."
-
May 17th, 2001, 05:43 AM
#15
Thread Starter
Hyperactive Member
ok hmm
i've looked at the different functions you've given me. i've gone thru the help files, and have used them succesfully, but they do not do what i want. they do not return the position of the first space i search for, it returns only the data after the first space i search for. SubStr is wierd and i could not get it to work. sorry. it said
String SubString(int startPos[, int length]);
i'm not sure what that means, i tried a few different things and i could not get a succesful build oh well. i really need something that will split up 0 0 320 240 this is vital to the players functionality. can u direct me somewhere for help on string functions in c++ ????
thanx for all the help
-
May 17th, 2001, 05:56 AM
#16
Frenzied Member
You don't need string handling functions to do this, you can do it yourself. The functions are just useful if you know them.
SubStr is the equivalent of the VB Mid() function. It works exactly the same way, it's not hard to see that from the help files, or just the function prototype.
Anyway you want the strchr() function to search for a character withing a string, strcmp() to compare two strings, strstr() to find a string within a string.
Like I said, if you can't find the details in your help files then go to http://msdn.microsoft.com and look there, they have far more information than my help files do.
Harry.
"From one thing, know ten thousand things."
-
May 17th, 2001, 06:13 AM
#17
Thread Starter
Hyperactive Member
aight thanx.
the borland help files aren't very informative unless its for the winapi and stuff. but for basic stuff its always just like the format of the string and no explanation 
thanx again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|