#### Archived

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

# Problems with Direct Show

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

## 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 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 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.

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

Feel free to correct me if I'm wrong.

-hellz

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 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 on other sites
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>

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631706
• Total Posts
3001835
×