Windows Media Foundation fails to create decoder when executed as Windows Service - c++

I'm experiencing a problem with the Windows Media Foundation's decoder. I don't get why my code works when running as part of an executable lunched thru the UI of the OS, but doesn't work when executed from the context of a Windows Service.
Basically the problem is in the creation of the decoder. It seams that the codec is not found.
I've configured the Windows Service to run with the same account as the one running the non-service executable - it is not working.
I've configured the Windows Service to run with the Local System account (allowing the service to interact with desktop) - it is not working.
Here's what I observe in mftrace when the decoder fails to create:
2332,1D90 12:30:05.27759 CMFPlatExportDetours::MFTEnumEx # Activate 00 #0285F8A0, MFT_FRIENDLY_NAME_Attribute=MPEG2VideoExtension;{3C0FBE52-D034-4115-995D-95B356B9855C}=1;MFT_INPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 26 80 6d e0 46 db cf 11 b4 d1 00 80 5f 6c bb ea 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4d 50 47 31 00 00 10 00 80 00 00 aa 00 38 9b 71 ;{7347C815-79FC-4AD9-877D-ACDF5F46685E}=C:\Program Files\WindowsApps\Microsoft.MPEG2VideoExtension_1.0.50901.0_x64__8wekyb3d8bbwe\x86\msmpeg2vdec_store.dll;MFT_OUTPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4e 56 31 32 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 49 59 55 56 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 ;MF_TRANSFORM_FLAGS_Attribute=1;{957193AD-9029-4835-A2F2-3EC9AE9BB6C8}=Microsoft.MPEG2VideoExtension_1.0.50901.0_x64__8wekyb3d8bbwe;{9D8B61A8-6BC8-4BFF-B31F-3A31060AFA3D}=Microsoft.MPEG2VideoExtension_8wekyb3d8bbwe;{BB49BC51-1810-4C3A-A9CF-D59C4E5B9622}={8103D590-5DC4-4825-A0D4-284395381C54};MF_TRANSFORM_CATEGORY_Attribute=MFT_CATEGORY_VIDEO_DECODER;{DE106D30-42FB-4767-808D-0FCC6811B0B9}=MPEGDecoder.MFTMPEGDecoderTransform;{F9542F80-D069-4EFE-B30D-345536F76AAA}=0;{F9A1EF38-F61E-42E6-87B3-309438F9AC67}=0
2332,1D90 12:30:05.27768 CMFPlatExportDetours::MFTEnumEx # Activate 01 #02861048, MFT_FRIENDLY_NAME_Attribute=Microsoft MPEG Video Decoder MFT;MFT_INPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 26 80 6d e0 46 db cf 11 b4 d1 00 80 5f 6c bb ea 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4d 50 47 31 00 00 10 00 80 00 00 aa 00 38 9b 71 ;MFT_TRANSFORM_CLSID_Attribute={2D709E52-123F-49B5-9CBC-9AF5CDE28FB9};MFT_OUTPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4e 56 31 32 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 59 56 31 32 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 ;MF_TRANSFORM_FLAGS_Attribute=1;MF_TRANSFORM_CATEGORY_Attribute=MFT_CATEGORY_VIDEO_DECODER
2332,1D90 12:30:05.27964 COle32ExportDetours::CoCreateInstance # Created {0000034B-0000-0000-C000-000000000046} () #01D825D8 - traced interfaces:
2332,1D90 12:30:05.28801 COle32ExportDetours::CoCreateInstance # Created {00000323-0000-0000-C000-000000000046} - ignored
2332,1D90 12:30:05.29134 COle32ExportDetours::CoCreateInstance # Created {00000339-0000-0000-C000-000000000046} () #01FD5610 - traced interfaces:
2332,1D90 12:30:05.29494 COle32ExportDetours::CoCreateInstance # Created {22F5B1DF-7D7A-4D21-97F8-C21AEFBA859C} () #01DE59BC - traced interfaces:
2332,1D90 12:30:05.29524 COle32ExportDetours::CoCreateInstance # Created {0000034B-0000-0000-C000-000000000046} () #01F48C48 - traced interfaces:
2332,1D90 12:30:05.31066 COle32ExportDetours::CoCreateInstance # Created {00000339-0000-0000-C000-000000000046} () #01F47A60 - traced interfaces:
**2332,1D90 12:30:05.31298 COle32ExportDetours::CoCreateInstance # Failed to create {2D709E52-123F-49B5-9CBC-9AF5CDE28FB9} Microsoft MPEG Video Decoder MFT (C:\Windows\SysWOW64\msmpeg2vdec.dll) hr=0xC004F011 (null)**
And this is the mftrace output then the decoder is successfully created:
14724,5784 13:40:53.00531 CMFPlatExportDetours::MFTEnumEx # Activate 00 #0371A2C8, MFT_FRIENDLY_NAME_Attribute=MPEG2VideoExtension;{3C0FBE52-D034-4115-995D-95B356B9855C}=1;MFT_INPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 26 80 6d e0 46 db cf 11 b4 d1 00 80 5f 6c bb ea 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4d 50 47 31 00 00 10 00 80 00 00 aa 00 38 9b 71 ;{7347C815-79FC-4AD9-877D-ACDF5F46685E}=C:\Program Files\WindowsApps\Microsoft.MPEG2VideoExtension_1.0.50901.0_x64__8wekyb3d8bbwe\x86\msmpeg2vdec_store.dll;MFT_OUTPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4e 56 31 32 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 49 59 55 56 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 ;MF_TRANSFORM_FLAGS_Attribute=1;{957193AD-9029-4835-A2F2-3EC9AE9BB6C8}=Microsoft.MPEG2VideoExtension_1.0.50901.0_x64__8wekyb3d8bbwe;{9D8B61A8-6BC8-4BFF-B31F-3A31060AFA3D}=Microsoft.MPEG2VideoExtension_8wekyb3d8bbwe;{BB49BC51-1810-4C3A-A9CF-D59C4E5B9622}={5A73C951-DE09-4E99-89B9-CE0671C2B3A6};MF_TRANSFORM_CATEGORY_Attribute=MFT_CATEGORY_VIDEO_DECODER;{DE106D30-42FB-4767-808D-0FCC6811B0B9}=MPEGDecoder.MFTMPEGDecoderTransform;{F9542F80-D069-4EFE-B30D-345536F76AAA}=0;{F9A1EF38-F61E-42E6-87B3-309438F9AC67}=0
14724,5784 13:40:53.00541 CMFPlatExportDetours::MFTEnumEx # Activate 01 #03715648, MFT_FRIENDLY_NAME_Attribute=Microsoft MPEG Video Decoder MFT;MFT_INPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 26 80 6d e0 46 db cf 11 b4 d1 00 80 5f 6c bb ea 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4d 50 47 31 00 00 10 00 80 00 00 aa 00 38 9b 71 ;MFT_TRANSFORM_CLSID_Attribute={2D709E52-123F-49B5-9CBC-9AF5CDE28FB9};MFT_OUTPUT_TYPES_Attributes=76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 4e 56 31 32 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 59 56 31 32 00 00 10 00 80 00 00 aa 00 38 9b 71 76 69 ;MF_TRANSFORM_FLAGS_Attribute=1;MF_TRANSFORM_CATEGORY_Attribute=MFT_CATEGORY_VIDEO_DECODER
14724,5784 13:40:53.05267 COle32ExportDetours::CoCreateInstance # Created {0000034B-0000-0000-C000-000000000046} () #03080608 - traced interfaces:
14724,5784 13:40:53.06348 COle32ExportDetours::CoCreateInstance # Created {00000323-0000-0000-C000-000000000046} - ignored
14724,5784 13:40:53.06760 COle32ExportDetours::CoCreateInstance # Created {00000339-0000-0000-C000-000000000046} () #03037CB0 - traced interfaces:
14724,5784 13:40:53.07307 COle32ExportDetours::CoCreateInstance # Created {22F5B1DF-7D7A-4D21-97F8-C21AEFBA859C} () #02E7716C - traced interfaces:
14724,5784 13:40:53.07353 COle32ExportDetours::CoCreateInstance # Created {0000034B-0000-0000-C000-000000000046} () #03080B30 - traced interfaces:
**14724,5784 13:40:53.09256 CMFActivateDetours::ActivateObject #0371A2C8 New MFT #03086DEC**
14724,5784 13:40:53.09270 CMFTransformDetours::Attach #03086DEC Rate control #03086DD4
14724,5784 13:40:53.09272 CMFActivateDetours::GetGUID #0371A2C8 attribute not found guidKey = MFT_TRANSFORM_CLSID_Attribute
14724,5784 13:40:53.09275 CMFAttributesDetours::GetUINT32 #00FFE438 attribute not found guidKey = {FB5D2347-4DD8-4509-AED0-DB5FA9AA93F4}
14724,5784 13:40:53.09278 CMFTopologyNodeDetours::GetGUID #03718870 attribute not found guidKey = MF_TOPONODE_TRANSFORM_OBJECTID
14724,5784 13:40:53.09278 CMFTransformDetours::Attach #03086DEC Rate control #03086DD4
14724,5784 13:40:53.09287 CMFAttributesDetours::GetUINT32 #0371B6F0 attribute not found guidKey = MF_TRANSFORM_ASYNC
14724,5784 13:40:53.09288 CMFAttributesDetours::GetStringLength #0371B6F0 attribute not found guidKey = MFT_ENUM_HARDWARE_URL_Attribute
14724,5784 13:40:53.09296 CMFTopologyDetours::GetUINT32 #036F9A18 attribute not found guidKey = MF_TOPOLOGY_DXVA_MODE
14724,5784 13:40:53.09300 CMFAttributesDetours::GetUINT32 #0371B6F0 attribute not found guidKey = GUID_NULL
14724,5784 13:40:53.09310 CMFAttributesDetours::GetUINT32 #0371B6F0 attribute not found guidKey = MF_TRANSFORM_ASYNC
14724,5784 13:40:53.09310 CMFAttributesDetours::GetUINT32 #0371B6F0 attribute not found guidKey = MF_TRANSFORM_ASYNC
14724,5784 13:40:53.09311 CMFAttributesDetours::GetStringLength #0371B6F0 attribute not found guidKey = MFT_ENUM_HARDWARE_URL_Attribute
14724,5784 13:40:53.09312 CMFTopologyDetours::GetUINT32 #036F9A18 attribute not found guidKey = {E48E1D3B-859A-40EC-928E-A5889EF0B458}
14724,5784 13:40:53.09312 CMFAttributesDetours::GetUINT32 #0371B6F0 attribute not found guidKey = MF_TRANSFORM_ASYNC
14724,5784 13:40:53.09312 CMFTopologyNodeDetours::GetUINT32 #03718870 attribute not found guidKey = MF_TOPONODE_LOCKED
14724,5784 13:40:53.09320 CMFTransformDetours::SetInputType #03086DEC Succeeded MT: MF_MT_FRAME_SIZE=3092376453696 (720,576);MF_MT_AVG_BITRATE=9700400;MF_MT_COMPRESSED=1;MF_MT_MPEG_SEQUENCE_HEADER=00 00 01 b3 2d 02 40 23 17 ae e3 80 00 00 01 b5 14 8a 00 01 00 00 ;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_DEFAULT_STRIDE=0;MF_MT_AM_FORMAT_TYPE=FORMAT_MPEG2Video;MF_MT_AVG_BIT_ERROR_RATE=0;MF_MT_MPEG2_LEVEL=2;MF_MT_MPEG2_PROFILE=2;MF_MT_FIXED_SIZE_SAMPLES=1;{C380465D-2271-428C-9B83-ECEA3B4A85C1}=0;MF_MT_FRAME_RATE=107374182401 (25,1);MF_MT_PIXEL_ASPECT_RATIO=68719476751 (16,15);MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_SAMPLE_SIZE=1;MF_MT_INTERLACE_MODE=2;MF_MT_SUBTYPE=MEDIASUBTYPE_MPEG2_VIDEO
Any help would be appreciated as I'm already stuck on this.

Related

Segmentation fault error while installing dynd-python in Python 2.7 environment

I am trying to install dynd-python using
conda install -c anaconda dynd-python
On Debian and getting the following error,
INFO startup-script-url: Downloading and Extracting Packages
INFO startup-script-url: Preparing transaction: ...working... done
INFO startup-script-url: Verifying transaction: ...working... done
INFO startup-script-url: Executing transaction: ...working... done
[ 232.714462] conda[6368]: segfault at 0 ip 00007f1a73d295a0 sp 00007f1a2723d6c0 error 6 in libpython2.7.so.1.0.c~ (deleted)[7f1a73c4d000+17d000]
[ 232.727548] Code: 08 4c 89 ff ff 50 30 49 83 2e 01 75 27 49 8b 46 08 4c 89 f7 ff 50 30 eb 1b 90 48 8d 50 f8 48 89 94 24 a8 00 00 00 48 8b 78 f8 <48> 83 2f 01 0f 84 29 41 00 00 48 8b 84 24 a8 00 00 00 48 39 44 24
kernel: [ 232.714462] conda[6368]: segfault at 0 ip 00007f1a73d295a0 sp 00007f1a2723d6c0 error 6 in libpython2.7.so.1.0.c~ (deleted)[7f1a73c4d000+17d000]
kernel: [ 232.727548] Code: 08 4c 89 ff ff 50 30 49 83 2e 01 75 27 49 8b 46 08 4c 89 f7 ff 50 30 eb 1b 90 48 8d 50 f8 48 89 94 24 a8 00 00 00 48 8b 78 f8 <48> 83 2f 01 0f 84 29 41 00 00 48 8b 84 24 a8 00 00 00 48 39 44 24
INFO startup-script-url: ./init_actions.sh: line 52: 3309 ***Segmentation fault conda install -c anaconda dynd-python***
INFO startup-script-url: BuildFailed: Custom Image Initialization Actions Failed. Please check your initialization script.
Using Python2.7
Any advice how to resolve this issue?
Thanks

SMPP client is adding an ¿ to the end of the message

I'm trying to make a Windows desktop smpp client, and it's connecting and sending well, aside from a bug where an extra character (¿) is added to the end of the message content that I'm receiving on my phone.
So I'm sending "test" but my phone receives "test¿". Here's the contents of the pdu object, just before it gets sent:
size :58
sequence :2
cmd id :0x4
cmd status:0x0 : No Error
00000000 00 00 00 3a 00 00 00 04 00 00 00 00 00 00 00 02 |...:............|
00000010 00 05 00 74 65 73 74 66 72 6f 6d 00 01 01 34 34 |...testfrom...44|
00000020 37 37 37 37 37 37 37 37 37 37 00 00 00 00 00 00 |7777777777......|
00000030 00 00 00 00 05 74 65 73 74 00 |.....test.|
0000003a
I'm using this c++ smpp library as a base:
https://github.com/onlinecity/cpp-smpp
I had to make some slight changes to get it working on windows, but I don't think anything was changed that could have affected this.
Someone else ran a test using a different account on the smpp server, and their test added an # symbol instead.
Any ideas what could be causing this? Thanks!
Found the problem in the end, it was due to an option in the smpp library that defaults to true, called nullTerminateOctetStrings
It was adding the 00 to the end of the message, sound slike this was required by the SMPP 3.4 standards, but our smsc didn't like it. I suppose ideally I would fix the smsc, but that's provided by a 3rd party, so I've just switched off the null terminate instead.
Someone with a similar problem and more info here: https://www.mail-archive.com/devel#kannel.3glab.org/msg06765.html

How to get the location and index of an Icon in a ".lnk" shortcut with SHGetFileInfo in C++

I am using C++ (VS 2012) on Win7x64 and am trying to get the location and index of an icon using SHGetFileInfo with SHGFI_ICONLOCATION like this:
SHFILEINFO info;
memset(&info, 0, sizeof(info));
DWORD_PTR result = SHGetFileInfo(_T("C:\\Users\\Admin\\Desktop\\test.lnk"), 0, &info, sizeof(SHFILEINFO), SHGFI_ICONLOCATION);
I get a 1 as result and after inspecting info.szDisplayName I see this:
0x0022CDE0 00 00 3a 00 5c 00 50 00 72 00 6f 00 ..:.\.P.r.o.
0x0022CDEC 67 00 72 00 61 00 6d 00 20 00 46 00 g.r.a.m. .F.
0x0022CDF8 69 00 6c 00 65 00 73 00 20 00 28 00 i.l.e.s. .(.
0x0022CE04 78 00 38 00 36 00 29 00 5c 00 54 00 x.8.6.).\.T.
0x0022CE10 65 00 73 00 74 00 5c 00 54 00 65 00 e.s.t.\.T.e.
0x0022CE1C 73 00 74 00 2e 00 65 00 78 00 65 00 s.t...e.x.e.
0x0022CE28 00 00 00 00 00 00 00 00 00 00 00 00 ............
0x0022CE34 00 00 00 00 00 00 00 00 00 00 00 00 ............
What I find strange is that although the string info.szDisplayName appears empty due to the 00 00 at the start, the call to SHGetFileInfo seems to have filled in the entire path correctly and then replaced the drive letter in it with a 00 00 making it an "empty" string.
What I also have noticed is that when I choose a different icon from a different executable it appears to work alright. But when I then create a shortcut to that different executable and use the icon from it that worked before it again returns this "empty" string.
It seems to work sort of crisscross with the locations of the executable and the icon, but with the icon being from the same executable it always seems to exhibit this strange behaviour. The only exception to this is the index of the icon.
It does not matter if an executable has only one or many icons, but when I use an icon with an index greater than 0, it does fill in the location correctly and the index as well, even though the location of the executable and the icon in the shortcut is the same.
Why is SHGetFileInfo filling in icon.szDisplayName as an "empty" string when in the shortcut the location of the icon is the same as the executable and the index is 0?

Detecting Memory Leaks in C++ Windows application

I have a C++ windows application which has some memory leak issues. Is it possible to analyze the memory leak from the dump using NTSD ? If so please guide me how to do that ?
I have also heard that we can do it using User Mode Dump. I am not very familiar with finding leaks in windows. It is very easy in Linux with Valgrind.
Is there any other better options to check this ?
see here for details about Visual Leak Detector. I have used it on Windows.
all you do in your application is to
#include <vld.h>
and you will see a report about detected leaks in terminal when debugging your program, something like this:
---------- Block 1199 at 0x04BE1058: 136 bytes ----------
Call Stack:
d:\Foobar\FooLog.cpp (26): FooLog::getInstance
d:\Foobar\FooMain.cpp (75): FooMain::init
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (578): __tmainCRTStartup
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): WinMainCRTStartup
0x759A3677 (File and line number not available): BaseThreadInitThunk
0x770C9D42 (File and line number not available): RtlInitializeExceptionChain
0x770C9D15 (File and line number not available): RtlInitializeExceptionChain
Data:
9C 33 2D 6B 74 2A 2D 6B C8 11 BE 04 00 00 00 00 .3-kt*-k ........
00 00 00 00 70 14 BB 6C 70 14 BB 6C 00 00 00 00 ....p..l p..l....
00 00 00 00 68 14 BB 6C 68 14 BB 6C 00 00 00 00 ....h..l h..l....
00 00 00 00 6C 14 BB 6C 6C 14 BB 6C 20 12 BE 04 ....l..l l..l....
00 00 00 00 CD 00 CD CD 00 00 00 00 01 CD CD CD ........ ........
68 14 BB 6C 78 33 2D 6B 00 00 00 00 00 00 00 00 h..lx3-k ........
I've had great success tracking down memory and resource leaks with DrMemory. It works with both GCC and MSVC and it's very straight forward to use.

How to programmatically load a Java card applet ( a .cap file ) using Visual C++/PCSC

I am currentlly on a project that requires me to load a JavaCard application Applet ( a .cap ) file to a JavaCard. Our framework is based on Visual C++ and PCSC, so we need to load the same applet to a series of JavaCards. Does anyone know how this can be processed? I mean, where should I start. Thanks!
You are correct that this is not a trivial job.
There are differences between different javacards, but generally you need to do 4 things:
initialize secure communications with the card (because many javacards are "global platform" cards they require a secure channel)
send a command saying "i wanna install an applet"
send the binary data for the applet to be installed
send a command to "instantiate" the applet after the binary data is sent
I'd recommend using the eclipse plugin to install the applet initially, because you can see the APDUs generated by the plugin to do the steps above. Once you know the APDU commands you must send to install your applet, you can directly send these commands using the PCSC interface from your C++ code to automate installation on a large number of cards.
My company makes a web browser plugin called Card Boss for doing this kind of thing (card communications via pcsc) from a browser - there's a web page you can use where you can type your own APDUs and send them to the card at the follwing URL:
https://cardboss.cometway.com/content.agent?page_name=Card+Boss+Lab
If you use our tool, your applet installation script should look something like this (note that this is a script for a JCOP card using the default jcop keys)
MESSAGE BOX Installing applets...
INIT CHANNEL 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f, 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
// INSTALL CAP:
SEND 80 E6 02 00 1D 10 A0 00 00 00 09 00 03 FF FF FF FF 89 10 71 00 01 08 A0 00 00 00 03 00 00 00 00 00 00
// LOADING CAP:
SEND 80 E8 00 00 FA C4 82 01 03 01 00 25 DE CA FF (snip, I removed a bunch
of binary data representing the cap file to shorten this post, and you might
need multiple SEND commands because of limits on the size of APDUS)
// INSTANTIATING Applet
SEND 80 E6 0C 00 1E 05 63 6F 6D 65 74 07 63 6F 6D 65 74 00 01 05 00 00 00 00 00 01 00 06 C9 04 68 2C 00 03 00 00