Translate your PERL code to execute file in Win32

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

Perl2EXE is a very useful program when you try to translate your PERL code to a execute file without PERL environment.

There should be noted if you happen the same problem.

  1. Active PERL need install:
    Although we try to use Perl2EXE  to translate PERL to execute file. We still need PERL runtime environment in the compiler machine. (Don’t need for running machine).
  2. Make sure Active PERL version is pair with your  Perl2EXE
    For example if you use Perl2Exe V7.02 for Win32 , you must use Perl 5.8.0, Perl 5.6.1, Perl 5.6.0 and Perl 5.005 which Active PERL version is ActivePerl Perl 5.8.0 Build 806. Or you may get error as follow:

 

C:\p2x-8.60-Win32>perl2exe.exe sample.pl
Perl2Exe V8.60 Copyright (c) 1997-2005 IndigoSTAR Software
Registered to evan:kkdai:20080010, ENT version
Converting ’sample.pl’ to sample.exe

C:\p2x-8.60-Win32>

 

 

Which I use Perl2EXE  V8.8 but I don’t have Active Perl  5.88

After I switch to Perl2EXE V8.6 and using Active PERL 5.86. It work as follows:

 

C:\p2x-8.60-Win32>perl2exe.exe sample.pl
Perl2Exe V8.60 Copyright (c) 1997-2005 IndigoSTAR Software
Registered to evan:kkdai:20080010, ENT version
Converting ’sample.pl’ to sample.exe

C:\p2x-8.60-Win32>

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

How to handle YouTube in your program

NET程式設計 No Comments »

Home

Summarized:
YouTube the world largest bideo braofcast company. People usually watch video under the web site or use the mashup to integrate into theirown blog. This article describes the way to deal with YouTube  via C++ coding. I will show you how to handle YouTube  API using Web Browser or using C++ to write a simple sample to demo how to get response from YouTube. Also I also tell you help to write a simple program to download YouTube video via HTTP connection client.

YouTube APIs
YouTube already provide lots of APIs which could help us to query video detail, get list by tag, list popular… All you have to do is open a url which like

http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id=XXXX_ID&tag=TakeThat

As you see the URL it separate into three part:

  1. "method=youtube.videos.list_by_tag": it
    is API name, whole API list is here.
  2. "dev_id=XXXX_ID": Every API request need a developer ID which you can request here.
  3. "&tag=TakeThat": This API could help to figure out the list of specific tag. Oh my favorite band is "Take That" ^_^.

After you send the Http request via your browser, you would get the result XML as follow:

Y_XML

Yes, a XML based response which you could full handle it in any kinds of program you like.

Download YouTube:
Pick up any video from YouTube which like: http://youtube.com/watch?v=abK9WNFbKus&eurl=%2Findex. How to download it via Http connection? First I want to introduce a web site which can help you to transform your YouTube URL to a download-able address. 男丁格爾’s 脫殼玩 - FLV Video Parser Web 版 is a one of this web site.

Because any playback from YouTube need request a SK(I don’t know what is stand for). How to get the SK? You can paste a URL like http://youtube.com/watch?v=abK9WNFbKus&eurl=%2Findex, and you open the source code of this page (Use IE to right click and "View Source"). Search a strinbg as follow:

 function writeMoviePlayer(player_div, force)
 {
  var v = "7";
  if (force)
   v = "0";

  var fo = new SWFObject("/player2.swf?hl=en&BASE_YT_URL=http://youtube.com/&video_id=1vjLC_gcftE&l=121&t=OEgsToPDskIwzbAyRDMe7MOVOjVzt-Qf&soff=1&sk=CxfMnY-qWhLIp4nOKIFWOgU", "movie_player", "450", "370", v, "#FFFFFF");

   fo.addVariable("playnext", 0);
  fo.addVariable("hl", getQueryParamValue("hl"));
  fo.addParam("allowFullscreen", "true");
    fo.addVariable("sourceid", "yw");
    fo.addVariable("sdetail", "m%3Auser%2Crv%3AabK9WNFbKus");
  player_written = fo.write(player_div);
 }

Use the "RED" string and connect with http://www.youtube.com/get_video? it should be http://www.youtube.com/get_video?video_id=1vjLC_gcftE&l=121&t=OEgsToPDskIwzbAyRDMe7MOVOjVzt-Qf&soff=1&sk=CxfMnY-qWhLIp4nOKIFWOgU it could download the video from YouTube directly. (The URL may invalid after a period time, please request it again.)

Sample Program:
Any handle of YouTube could via Http connection clien which IE/FireFox… CHttpClient is a very useful simple http client program which write by C++. 

It has a clear GUI and useful connection API to get/post and request to Web Site via HTTP. I modify this application and change it to deal with YouTube.

Please download in
http://www.badongo.com/file/3563196

Any comment is welcome.

在C#上使用類似sprintf的字串轉換

NET程式設計 No Comments »

Solving Constraints

English Summary: This article describe about how to use String.Format to implement the same with sprintf or printf in C++. For English, Please refer this article for more detail.

中文: 最近遇到一些好玩的現象~~ 再次就把解決方式寫下來吧~~ (這篇就不用寫英文了,要看英文的部份請看這篇文章)。

最近在C#上面,想要輸出固定2個位元小數點浮點數~ 為了這件事情~~ 覺得有點難搞~~ 由於傳下來的數字是Double 來儲存的,並且有可能是循環小數 (比如說: 10/3 = 3.333)。 如果~~ 你單純的使用Math.Round() 比如以下的範例:

Double buf = 3.33333333333333333;
buf = Math.Round(buf , 2);

這個時候~ 你還是會發現 buf 還是那一連串的小數點~ 而沒有再小數點第二位去取四捨五入。原因在於小數點數字過多~ 而產生了 exception 的發生。 這個時候我又想了一個方法,參考以下的code:

Double buf = 3.33333333333333333;
buf = Math.Abs(buf*100);
buf = bug/100;

很奇怪的~~ 這樣也是無法轉換到兩個小數點~ 還會變成原來的數字~~ (難道是最佳化?) 難道我得使用CallingConvention Enumeration  的方式,把sprintf 當作外在function call嗎?

Imports System
Imports Microsoft.VisualBasic
Imports System.Runtime.InteropServices

Public Class LibWrap
‘ Visual Basic does not support varargs, so all arguments must be
‘ explicitly defined. CallingConvention.Cdecl must be used since the stack
‘ is cleaned up by the caller.
‘ int printf( const char *format [, argument]… )

<DllImport("msvcrt.dll", CallingConvention := CallingConvention.Cdecl)> _
Overloads Shared Function printf ( _
    format As String, i As Integer, d As Double) As Integer
End Function

<DllImport("msvcrt.dll", CallingConvention := CallingConvention.Cdecl)> _
Overloads Shared Function printf ( _
    format As String, i As Integer, s As String) As Integer
End Function
End Class ‘LibWrap

Public Class App
    Public Shared Sub Main()
        LibWrap.printf(ControlChars.CrLf + "Print params: %i %f", 99, _
                       99.99)
        LibWrap.printf(ControlChars.CrLf + "Print params: %i %s", 99, _
                       "abcd")
    End Sub ‘Main
End Class ‘App

還好之後在網路上有找到相關的程式String.Format() 去做類似~ sprintf 的轉換.

Double buf = 3.33333333333333333;
string outputStr = String.Format("{0:f}", buf);

要更多範例~~ 可以去這邊查詢

Write a simple Windows SideShow program

NET程式設計 No Comments »

筆記型電腦上的 Windows SideShow

Windows SideShow is a new technology in Windows Vista that supports a secondary screen on your mobile PC. With this additional display you can view important information whether your laptop is on, off, or in sleep mode. Windows SideShow is available in Windows Vista Home Premium, Windows Vista Business, Windows Vista Enterprise, and Windows Vista Ultimate. For more detail, please refer http://www.microsoft.com/windows/products/windowsvista/features/details/sideshow.mspx

For Engineer to development a simple SideShow program:

  1. Make sure you using Vista RTM
  2. Download SideShow emulator: http://www.microsoft.com/downloads/details.aspx?FamilyID=bba99eb2-aa6d-4133-b433-933a2c4d41dc&displaylang=en
  3. Install VS2005.
  4. Install Windows Vista SDK and .NET (http://www.microsoft.com/downloads/details.aspx?FamilyId=C2B1E300-F358-4523-B479-F53D234CDCCF&displaylang=en)
  5. Open solution: C:\Program Files\Microsoft SDKs\Windows\v6.0\Samples\winui\sideshow\HelloWorld\HelloWorld.sln
  6. Build it
  7. Run registery "HelloWorld.reg"
  8. Run bin file in C:\Program Files\Microsoft SDKs\Windows\v6.0\Samples\winui\sideshow\HelloWorld\Debug\WindowsSideShowHelloWorld.exe
  9. Start Emulator, you should show "Hello World" here.~~~

Windows SideShow 頁面

Write simple WMI program

NET程式設計 No Comments »


(Diagram: 淺談CIM與WMI-名詞介紹)

WMI (Windows Management Instrumentation) provide a kind of easy way to let you query data from your system (Ex: OS version, share folder name … etc).

It is easy to understand, using WMI to query information is the same with query data from database. You can just using "SELECT * from Win32_Process" to find out all exist process in your computer.

There are some examples which describe how to create it using C# or C++ code.

There are serveral extension reading..
Here is sample code of C#

using System.Management;

//This is equivalent to "SELECT * FROM Win32_Service"
SelectQuery sysSQL = new SelectQuery("Win32_bios");

MnagementObjectSearcher sysRet =
  
new ManagementObjectSearcher(sysSQL);

// Display each entry for Win32_bios
foreach (ManagementObject sysInfo in sysRet.Get())
{
 
this.textBox1.Text = "Bios version: " + sysInfo["version"].ToString();
}

How to debug COM DLL registeration

NET程式設計 No Comments »

DebugSetting1

I know many people feel confuse if your COM DLL failed during registeration (using RegSvr32 to register it). I spent a little time, and find out how to debug it. It can help you to find out what is the root cause. OK! let get start.

How can we do if register COM dll failed?

Firstable, you can use "dumpbin /dependents YOURDLL.DLL" to find out if you lost some dependency DLL.

Ok! ~~ let go to debug DLL registeration.

  1. Right click you DLL project –> Open "Properties".
  2. Go to "Configuration Properties" –> "Debugging" .
  3. In "Command", fill it "C:\WINDOWS\system32\regsvr32.exe"
  4. In "Command Arguments", fill it "$(TargetPath)"
  5. Just press F5 to run it.

Please note, you should setting break point as follows:

  • DllMain
  • DllRegisterServer
  • DllUnregisterServer (if unregister failed).

That’s it~~~

利用VS2005來做ASP.NET 開發前的注意事項

NET程式設計 No Comments »

www.asp.net Home

利用VS2005來作為ASP.NET的開發平台~~ 說老實的~~ 寫過不少Web Application的我還真是沒試過~~  (我是使用無敵記事本~~ 加上FTP 上傳的笨蛋)  心血來潮之下~ 在家裡測試了一下~~ 反而發現~~ 原來在安裝上面~還有許多需要注意的地方~~~

  1. ASP.NET 使用者的權限: .Net FrameWork 2.0 在安裝的時候~ 都會幫你設定一個使用者~~ 叫作ASP.NET~ 而他的作用就是代表者~~ 你localhost 要執行ASP.NET的程式時~~ 所允許的權限. 很多時候~~ 大家可能會把這個使用者給封鎖或是刪除, 如果這個使用者已經被刪除了~~~ 重新安裝一次.Net FrameWork 2.0  就可以了~~~ 安裝完後~可以選擇提高 ASP.NET使用者的權限 (我自己是調到最高~大家可以自己決定).
  2. Integrated Windows authentication is not enabled:  這個問題~~是我在安裝完並且修改完權限之後所發現的.  要解決這個問題~~ 我搜尋網路之後~~ 發現這篇文章 Unable to start debugging on the web server.Debugging failes because integrated Windows authentication is not enabled.  有講解到解決方式~~其實很簡單~~我摘錄該文章裡面的附圖.

    就注意好~~ 把滑鼠指到的那個項目點到就好~~~

現在總算可以用平常上班的VS2005 來做網路程式的撰寫~~ 感覺就興奮異常阿~~~~

unresolved external symbol “wchar_t * __stdcall _com_util::ConvertStringToBSTR

NET程式設計 No Comments »

If you link code found some error like bellow:

error LNK2019: unresolved external symbol "wchar_t * __stdcall _com_util::ConvertStringToBSTR(char const *)" (?ConvertStringToBSTR@_com_util@@YGPA_WPBD@Z) referenced in function "public: __thiscall _bstr_t::Data_t::Data_t(char const *)" (??0Data_t@_bstr_t@@QAE@PBD@Z)

Solve:

Try to link "comsuppwd.lib" in debug AdditionalDependencies. Link "comsuppw.lib" in release AdditionalDependencies.

Reference:

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