Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Problems with Direct Show

This topic is 5342 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i wan''t to play mp3 with DS, and i''m using HRESULT AddSourceFilter( LPCWSTR lpwstrFileName, LPCWSTR lpwstrFilterName, IBaseFilter **ppFilter ); the problem is first and secon parameters, i wan''t to convert char * to LPCWSTR in some quick/easy/painfree way... i tried this, but i guess its wrong, because i get some memory problems: LPWSTR pfilename2 = new WCHAR[strlen(filename)]; MultiByteToWideChar(CP_ACP, 0, filename, -1, pfilename2, strlen(filename)); pfilename2[strlen(filename)] = ''\0''; please help me

Share this post

Link to post
Share on other sites
try using the bstr macro with the parameters.

_bstr_t(char *);

I believe the _bstr_t class can return a char * or a wchar * in its class (along with taking both as a parameter), so it works well for these type of situations/conversions.

Share this post

Link to post
Share on other sites
I could be wrong with what I'm about to say, but I'll say it anyway. I think the reason you get "memory problems" when using strlen(filename), is because WCHAR has a size of > 1 byte.

So for example, say your filename was, "test.mp3". strlen() would return 8, but if WCHAR was say 2 bytes wide, you'd be allocating half the size of which you required, because 8 * 2 = 16.

This might work instead:

LPWSTR pfilename2 = new WCHAR[strlen(filename) * sizeof(WCHAR)];

Feel free to correct me if I'm wrong.


Edit: Obviously you'd have to use this same method for when you're using strlen() in those other functions as well. Would be best to store the first result of strlen(), so that it doesn't have to be calculated over and over again.

Edit 2: You'd have to add space for the terminating null character as well, like so:

LPWSTR pfilename2 = new WCHAR[strlen(filename) * sizeof(WCHAR) + sizeof(WCHAR)];

[edited by - hellz on November 12, 2003 2:05:20 PM]

Share this post

Link to post
Share on other sites
hmm i tried the both way, but in the fisrt case i neded to include comutil.h which worked fine, but when compiling the compiler didn''t fin some source

and in the second case where still a memory leak.....

but i solved it in this way:

int nLen = MultiByteToWideChar(CP_ACP, 0,filename, -1, NULL, NULL);

which is the lenght of the new string, however, i have no clue what i did .....took it from the docs

hey! thanks both of you!

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
including <comutil.h> by itself will give you link errors if you are not using building a com library; it''s not that you are missing code.

simply includ ethe comsupp.lib

depending on the IDE you are using you can do it various ways; easiest and quickest is

#pragma comment(lib, "comsupp.lib"
#include <comutil.h>

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!