How to change and find Autoplay setting?

NET程式設計, 下一代視窗系統心得, VC++程式設計 No Comments »

AppPicker.JPG
(Application Picker dialog from XP)

Application Picker is a dialog which will show-up when you insert DVD title or new medium in your computer. It show all playable application and let you to choose one from the list.

One day, I just woundering where can I find the setting? How could I change the autoplay icon?  How could change the autoplay string?

Here is the detail document from MSDN: Preparing Hardware and Software for Use with AutoPlay

In follows steps, I will show you how to use “REGEDIT.EXE” to find out the setting and how it work.

Read the rest of this entry »

Use VC8 create ATL Service will failed in CoInitialize

NET程式設計, VC++程式設計 No Comments »

Use VC8 (Visual Studio 2005) to create project is more easy than VC6(VC98), but however we may not CoInitialize ATL service as well. It always happen failed since you use your API to CoInitialize this service. But it iswork if you use VC6 to create the ATL service. The root cause is the sercurity issue as follow:

http://msdn2.microsoft.com/en-us/library/xe2dxx5c(VS.80).aspx

class CATL_SERVERModule : public CAtlServiceModuleT< CATL_SERVERModule, IDS_SERVICENAME >
{
public :
    DECLARE_LIBID(LIBID_ATL_SERVERLib)
    DECLARE_REGISTRY_APPID_RESOURCEID(IDR_ATL_SERVER, “{C08654FF-A0F1-4CFD-8A09-93D4768BCF14}”)
    HRESULT InitializeSecurity() throw()
    {
        // TODO : Call CoInitializeSecurity and provide the appropriate security settings for
        // your service
        // Suggested - PKT Level Authentication,
        // Impersonation Level of RPC_C_IMP_LEVEL_IDENTIFY
        // and an appropiate Non NULL Security Descriptor.
        return S_OK;
    }
};

The problem is VC8 move the the security implement the base-class and you at-least implement one security check in this section of code. The easy way to implement it is copy code from VC6 as follow:

        // TODO : Call CoInitializeSecurity and provide the appropriate security settings for
        // your service
        // Suggested - PKT Level Authentication,
        // Impersonation Level of RPC_C_IMP_LEVEL_IDENTIFY
        // and an appropiate Non NULL Security Descriptor.

            // This provides a NULL DACL which will allow access to everyone.
        CSecurityDescriptor sd;
        sd.InitializeFromThreadToken();
        hr = CoInitializeSecurity(sd, -1, NULL, NULL,
             RPC_C_AUTHN_LEVEL_PKT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);

        return S_OK;


Powered by Zoundry

DllRegisterServer/DllUnregisterServer failed in 0×80029C4A (TYPE_E_CANTLOADLIBRARY)

VC++程式設計 No Comments »

SYMPTOMS
When you try to register or unregister a COM server, it will pop failed in 0×80029C4A (TYPE_E_CANTLOADLIBRARY).

CAUSE
This is cuase by no TLB or missing TLB of this COM DLL. 

RESOLUTION
If your COM DLL is builded using /notlb. remember use
     CComModule::RgisterServer(FALSE);
     CComModule::DllUnregisterServer(FALSE);

otherwise, please make sure your TLB is well for register.

REFERENCE

CComModule::RegisterServer; CComModule::UnregisterServer

視窗影像處理推薦書目

VC++程式設計 No Comments »


(圖片來源: 悅仕網路書店)

書  名:
DirectShow開發指南
I S B N : 7-302-07650-2
出 版 社 :
北京科海電子出版社
裝  訂:
16開 平裝 黑白
隨書光碟:
0CD
書本頁數:
368 頁

推薦原因: 對於整個DirectShow 有完整的說明,原作者陸齊明為微軟的MVP,對於整個DirectX有完整的了解,對於要處理影像問題的人這本是一本不可或缺的基本書籍。


(圖片來源: 悅仕網路書店)

書  名:
DirectShow實務精選
I S B N : 7-03-013654-3
出 版 社 :
北京科海電子出版社
裝  訂:
16開 平裝 黑白
隨書光碟:
1
書本頁數:
471 頁

推薦原因: 同為微軟MVP陸齊明的作品,這本書偏向於實務,舉凡DVD播放、Filter的製作都有相當好的範例~裡面的範例光碟可以讓你有快速的應用與了解。


(圖片來源: 悅仕網路書店)

書  名:
Windows Media編程導向
I S B N : 7-302-10944-3
出 版 社 :
北京科海電子出版社
裝  訂:
16開 平裝 黑白
隨書光碟:
1CD
書本頁數:
309 頁

推薦原因:  這本書我已經購買了,但是由於書還沒有拿到只能說陸齊明的作品我並不想錯過~~。


(圖片來源: 博客來網路書店)

COM本質論

 

作者:侯俊傑

出版社:碁峰

出版日期:1999 年 03 月 15 日

語言別:繁體中文

推薦原因:  涵蓋了所有COM的核心概念~所有學習COM的人都應該要好好的學習。


(圖片來源: 天瓏網路書店)

Windows 程式設計使用 MFC (Programming Windows with MFC, 2/e)

ISBN :
  9861252983
出版商 :
  文魁
出版日期 :
  2004-08-14
上架日期 :
  2004-08-14

推薦原因: 學習Windows Programming的第一本書,可以讓你對於視窗程式設計有基礎的概念。也可以讓你對於COM有一定的了解與應用。

Open firewall setting via netsh command

VC++程式設計 No Comments »

Firewall_Setting.JPG

From XP-SP2. the firewall setting default will block all app connection except user approval. So, you can approve every app you want to execute and let it work correctly under XP-SP2 (also in Vista).

But if your appllication is a Window Services? How it work under Microsoft firewall ?

It will be blocked the communication automatically!!

Yes, ~~  if your app is a P2P window services, you will find it doesn’t work when the service is work, even you never get a assert dialog box.

BlockAllowed.JPG

How do workaround with firewall, if my application is a Window Service?

Use "Netsh" to change your firewall setting. For example if you want to enable specific app "fooAPP.exe".

netsh firewall add allowedprogram "c:\fooAPP\fooAPP.exe" fooAPP ENABLE

if you want to disable a APP from firewall.

netsh firewall delete allowedprogram "c:\fooAPP\fooAPP.exe"

Notes to Migrate from VC6 to VC2005

VC++程式設計 No Comments »

  1. fstream.h 和iostream.h在VC8已經不存在 (參考VinceYuan Blog升级VC7项目到VC8的注意事项)
    #include <fstream>
    using namespace std;
  2. Depenency problem: 如果要引用某些其他project header file 在VC6中必須要設定dependency,在VC8中則沒有這樣的限制

其他詳細的步驟可以參考
VinceYuan Blog升级VC7项目到VC8的注意事项

Search from attributes use XPATH

XML程式設計, VC++程式設計 No Comments »

To search a attribute via XPATH. you can use Element[@Attr] to address it in XPATH.

So~~ to search some specific search as follow:

1. product@cost which is > 5000, you can write as follow.

product[@cost > ‘5000′]

2. product@name contains "yellow" (case-insensitivity).

contains(translate(product[@name], ‘ABC…Z’, ‘abc….z’), translate(’yellow’, ‘ABC…Z’, ‘abc….z’))

How to use KEY in xslt

XML程式設計, VC++程式設計 No Comments »

W3C

I think XML is a very simple storage medium that you can save and query in it. But all data is storage as a tree node in the XML. In this case, it can very simple to save hierarchy data structure. But how to handle it you have reference item?

Just use key in your XML code. For more detail please refer the sample as follow:

t1.xslt

x1.xml

Result

Runtime to start/stop another window sevice

VC++程式設計 No Comments »

WindowsService (WinCE).JPG 

Except to set the dependency of services in SCM(Service Control Manager). You have another way to make sure some services can run before your application (serivce).

Use StartService to start a Window Service

Please note as follow:

  1. If the service already start, it will return FALSE.
  2. The function will return if the Windows Service is in running status (maybe needs 30sec atmost) or failed.

For more detail, please refer MSDN. Refer the sample code.

 SC_HANDLE serviceControlManager = OpenSCManager(0, 0, SC_MANAGER_CONNECT);
 SC_HANDLE service;

 if (serviceControlManager)
  {
  service = OpenService(serviceControlManager,
         "SERVICE_NAME",
         SERVICE_START | SERVICE_QUERY_STATUS | DELETE);
// Make sure you have the privilege of SERVICE_START.

  if (service)
   {
   if (StartService(service, 0, NULL))
    {
    // Services already startup successes.
    }
   else
    {
    DWORD dwLastError = GetLastError();
    if (dwLastError == ERROR_SERVICE_ALREADY_RUNNING)
     {
     //Services already started
     }
    else
     {
     //Service can not start.
     hr = E_FAIL;
     return;
     }
    }
   }

Use ControlService to stop Windows Services

You may think it may have a function StopService to stop serivce. Unfortunately, you have use CotrolService to do that. Please refer the sample code for more detail.

SC_HANDLE serviceControlManager = OpenSCManager(0, 0, SC_MANAGER_CONNECT);
 SC_HANDLE service;

 if (serviceControlManager)
  {
  service = OpenService(serviceControlManager,
         "SERVICE_NAME",
         SERVICE_STOP | SERVICE_QUERY_STATUS | DELETE);
// Make sure you have the privilege of SERVICE_STOP.

  if (service)
   {
   SERVICE_STATUS serviceStatus;
   QueryServiceStatus( service, &serviceStatus );

   if (serviceStatus.dwCurrentState != SERVICE_STOPPED)
    {
    if (! ControlService(service,    // handle to service
          SERVICE_CONTROL_STOP,  // control value to send
          &serviceStatus) )  // address of status info
      {
      // ControlService failed 
      }
    }
   }
  } 

Head first design pattern–”Singleton pattern”

VC++程式設計 No Comments »

Head First Design Patterns
(Picturefrom Amazon)

Sometime you just write code without fully understanding the meaning. Like design pattern, maybe you already know part of them even use them very well. "Head First Design Patterns" is a good book, it use a story to let you know why you must use this pattern (some of us may not know forever).

As this chapter "Singleton pattern", I have already used it in my code everywhere. But I can not get fully understand why we have to use this, how to use this and how to prevent other this in multiple threading programming.

I list a example fot singleton implementation.

class CSingleton
{
public:
 static CSingleton * getInstance();
public: 
 void f1();
 void f2();
 void f3();

private:
 virtual ~CSingleton();
 CSingleton();

private:
 static CSingleton *m_uniInstance;
};

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS 登入