Tuesday, November 19, 2013

DLL for UTM <--> Geodetic Coordinate Transformation

[Reference] http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.htm

The DLL implement the coordinate transformation between UTM (Universal Transverse Mercator) and Geodetic coordinate system (latitude & longitude). Functions for transformation between TWD97 ( and TWD67) and Geodetic coordinate system are also included.

The file package also include a VB example.

Download: http://www.mlidar.com/MTMToGeoDLL.rar

Monday, August 12, 2013

[Android] Service

[Reference]
http://www.vogella.com/articles/AndroidServices/article.html


[Android] 在 Service 中啟動 Activity
[Reference] http://www.myandroid.tw/bbs-topic-66.sea

!!很重要!!
Server要啟動Activity一定要加上 Intent.FLAG_ACTIVITY_NEW_TASK的Flag

Intent i = new Intent();
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

[Android] 用 bind 啟動 Service

Service 裏要有如下的程式,在 onBind 傳回 mBinder, Activity 裏的 onServiceConnected() 才能收到 bind 完成的訊號, 預設傳回 null 沒用。

public class LocalBinder extends Binder {
MusicService getService() {
return MusicService.this;
}
}
private final IBinder mBinder = new LocalBinder();
@Override
public IBinder onBind(Intent intent) {
return
mBinder;
}

Friday, August 2, 2013

Setup QT for Android on Windows (C++)

[Reference]

1. Download the following packages:
        QT
        The Android NDK
        Apache Ant v1.8 or later
        OpenJDK v6 or later

2. Install packages:
        QT: Install
        The Android SDK Tools: extract and update 
        The Android NDK: Extract (Cannot contain SPACE in folder path)
        Apache Ant: Extract (Cannot contain SPACE in folder path)
        OpenJDK: Install

3. Set Path for Qt Creator
    [Tools] [Option] [Android]: Assign path for SDK, NDK, ant and JDK







Friday, July 5, 2013

[Visual C++] Run-Time Check Failure #2 - Stack around the variable was corrupted

This run time error often happens when you try to write a string to a char[ ] whose size is smaller than the string.

ex:

char str[10];
char s10[] = "1234567890";

str[10] = 'a';         <----- error, size of str is 10, can only access str[0] ~ str[9]
strcpy( str, s10);   <----- error, size of s10 is 11, don't forget the end character '\0' or NULL

Wednesday, June 26, 2013

[TeeChart] Add custom vertical/horizontal axis to a chart

// Create a new line series
  TLineSeries *Series = new TLineSeries(Chart);

// Create a new custom vertical axis
  TChartAxis *vertaxis = new TChartAxis(Chart);
// Assign custom vertical axis
  Series->CustomVertAxis = vertaxis;
// Set axis position
  vertaxis->PositionPercent = 0; //percentage
// Set axis size
  vertaxis->StartPosition = 10;  //percentage
  vertaxis->EndPosition   = 50;  //percentage

// Create a new custom horizontal axis
  TChartAxis *horiaxis = new TChartAxis(Chart);
// Set new axis as horizontal
  horiaxis->Horizontal = true;   
  
  Series->CustomHorizAxis = horiaxis;
  horiaxis->PositionPercent = 0;
  horiaxis->StartPosition   = 30;
  horiaxis->EndPosition     = 60;

// Add line series to chart
  Chart->AddSeries(Series);

Tuesday, May 28, 2013

[Note] Zero-length empty base class

For some application, eg., M LiDAR Viewer, I have to set the value of [Zero-length empty base class] and [Zero-length empty class member functions] at [C++ Compiler Compatibility] to "True" ( default are False), or the application doesn't run correct.
Why?

[Reference]
http://docwiki.embarcadero.com/RADStudio/XE4/en/C%2B%2B_Compiler_Compatibility

 

Friday, April 12, 2013

[InstallAWare] Delete registry keys created by your application after it was installed

[Reference] http://www.installaware.com/FlashHelp/precedeuninstall.htm
                   http://www.installaware.com/FlashHelp/deleteregistry.htm


To delete registry keys created by your application after it was installed:

    Delete Registry
    This command deletes a value or an entire key from the system registry.
    Root
    Select the root of the delete operation using the drop down menu.
    Key
    Type the name of the key to delete (from).
    Value
    Type the value to delete. Leave empty to delete the default value. If you are deleting the entire key, this field is ignored.
    Delete Entire Key (and subkeys)
    Check this item to delete the entire key, along with any subkeys it contains.
    Delete Value Only
    Check this item to delete the named value only.
     Warning
    • Windows Installer does not provide an easily timed mechanism to delete registry keys. This action will not execute through the Windows Installer engine and is provided as a convenience for the setup developer.
    • We recommend you create all registry keys used by your application as part of your setup. Doing so assures Windows Installer will automatically remove all such keys upon uninstallation.

    Copyright© 1996-2013 InstallAware Software. All rights reserved.

    Tuesday, April 9, 2013

    Draw to TBitmap fail !

    [Reference] http://qc.embarcadero.com/wc/qcmain.aspx?d=43018


    At multi-thread program. The canvas handle of the Bitmap may be freed during the drawing procedure. So, lock the canvas before the drawing operation. And free after the drawing.
    Lock the canvas may reduce the performance. But sometimes you have to do this.

    Canvas->Lock();

    drawing....

    Canvas0->Unlock();

    Friday, April 5, 2013

    如何獲得GetLastError()的文字訊息

    [Reference] http://ascii-iicsa.blogspot.ca/2010/09/getlasterror.html

    int main()
    {
      CString strMsg;

      LPVOID lpMsgBuf;

      FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
                     FORMAT_MESSAGE_FROM_SYSTEM |
                     FORMAT_MESSAGE_IGNORE_INSERTS,
                     NULL,
                     GetLastError(), // 這裡也可以改成你想看的代碼值,例如直接打8L可得"空間不足"
                     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
                     (LPTSTR) &lpMsgBuf,
                     0,
                     NULL);

      strMsg.Format( _T("錯誤訊息:%s\n錯誤代碼:0x%x"), 
                     lpMsgBuf,     
                     GetLastError());

      LocalFree(lpMsgBuf); // 記得free掉空間

      return TRUE;
    }


    限制程式只能有一個執行個體?

    [Reference] http://www.programmer-club.com.tw/ShowSameTitleN/cb/10992.html


    在主程式 WinMain() 加入下面程式碼

    WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
    {
      HANDLE hMutex;
      // 設定互斥旗標所識別的應用程式名稱
      const char pProgName[]="~!@#$%^project1";
        try {
        // 取得互斥旗標的狀態
          hMutex=OpenMutex(MUTEX_ALL_ACCESS, false, pProgName);
          if ( NULL==hMutex ) {
          // 設定互斥旗標所識別的應用程式名稱
          hMutex=CreateMutex(NULL, true, pProgName);
        }
        else {
          // 系統中已開啟一份應用程式了,因此不啟動本程式
          return 0;
        }

        Application->Initialize();
        Application->CreateForm(__classid(TForm1), &Form1);
        Application->Run();
      }
      catch ( ... ) {
      ...
      }

      // **** 加入部份
      // 釋放互斥旗標
      return ReleaseMutex(hMutex);
    }

    Saturday, March 30, 2013

    [OpenGL] glShadeModel

    [Reference] The OpenGL SuperBible


    "The other shading model that can be specified with glShadeModel is GL_FLAT for flat shading. Flat
    shading means that no shading calculations are performed on the interior of primitives. Generally,
    with flat shading, the color of the primitive's interior is the color that was specified for the last
    vertex. The only exception is for a GL_POLYGON primitive, in which case the color is that of the first
    vertex."

    使用 glShadeModel() 可設定三角形或多邊形內部顏色的著色方式,有二個可使用的參數 GL_SMOOTH 和 GL_FLAT。
    GL_SMOOTH 將三角形或多邊形的各個頂點的顏色加以計算,於其內部漸層著色。
    GL_FLAT只取用三角形或多邊形單一頂點的顏色作為其內部的顏色。在三角形取最後一點的顏色,多邊形則取用第一點的顏色。

    Friday, March 29, 2013

    [OpenGL] Lighting

    [Reference] The OpenGL SuperBible
    OpenGL 提供許多關於顏色、材質、光、影的功能。內容很多,慢慢添加。

    從開燈開始:

    01: glEnable(GL_LIGHTING);   //開燈


    // Bright white light – full intensity RGB values
    02: GLfloat ambientLight[] = { 1.0f, 1.0f, 1.0f, 1.0f };

    // Set light model to use ambient light specified by
    // ambientLight[]
    03: glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambientLight);


    第 1 行開啟光源。

    第 2 行設定環境(ambient)光源的顏色及強度。環境光是從各方向均勻照向物體的光源。 
    4個參數依序為 RGBA。值域為 0~1,數值愈大則物體愈亮,預設值為(0.2, 0.2, 0.2, 1.0)(很暗)

    第 3 行將環境光源的參數代入 OpenGL。

    若未使用第 2, 3行則表示使用預設的環境光源參數。難怪,只開燈而未設定其他燈光參數時,物體變暗。因為這裏設定環境光源為白色,開燈後物體呈現灰色。

    (再來, 設定材質, 或用 glColor )

    Thursday, March 21, 2013

    [OpenGL] Display List, Vertex Array, Vertex buffer object (VBO)

    Reference: http://www.songho.ca/opengl/gl_vbo.html
    Reference: http://www.gamedev.net/topic/487333-glgenbuffers-vs-glgenbuffersarb/

    "Using vertex array can reduce the number of function calls and redundant usage of the shared vertices. However, the disadvantage of vertex array is that vertex array functions are in the client state and the data in the arrays must be re-sent to the server each time when it is referenced.
    On the other hand, display list is server side function, so it does not suffer from overhead of data transfer. But, once a display list is compiled, the data in the display list cannot be modified.
    Vertex buffer object (VBO) creates "buffer objects" for vertex attributes in high-performance memory on the server side and provides same access functions to reference the arrays, which are used in vertex arrays, such as glVertexPointer(), glNormalPointer(), glTexCoordPointer(), etc."

    Vertex Array: 資料存放在 Client 端, 每次畫圖時要傳送至 Server 端。可修改資料內容。
    Display List: 資料放在 Serve 端(執行較快)。但不可修改資料內容。若要修改, 則必須重建 Display List。
    VBO:同時兼具 Vertex Array 和 Display List 的優點。資料放在 Server 端,而且可修改資料內容。

    OpenGL 1.4 版(含)之前,VBO 是 OpenGL 延伸功能 (GL_ARB_vertex_buffer_object),相關函數名後面加有 ARB。

    OpenGL 1.5 版(含)之後,VBO 是 OpenGL 內函功能,相關函數名後面不加 ARB。

    Wednesday, March 6, 2013

    Set Anyone (All users) radio button as default at Startmenu Dialog (InstallAWare)

    1. At Dialog Editor, set Checked of [Anyone] radio button to "true"  and  [Only for me] to "false"
    2. Creating Compressed Single Self-Installing EXE.
    3. At Group Policy Wizard, use ALLUSERS=TRUE as command line parameter.
    4. Create MSI from Group Policy Wizard.

    Reference:
    http://forums.installaware.com/viewtopic.php?f=2&t=3043


    Friday, February 22, 2013

    Sunday, February 17, 2013

    Android getApplication 用法


    http://www.cnblogs.com/renqingping/archive/2012/10/24/Application.html

    在 AndroidManifest.xml 設定自訂的 Application 物件名稱.

    Friday, January 18, 2013

    Path of header file for OpenGL at Mac OS (C++ Builder XE3)

    [Reference]

    OpenGL Multicolor Tetrahedron (C++)


    Adding the OpenGL and GLUT Frameworks

    When a C++ console application is created, the OpenGL and GLUT frameworks are by default not included. To include them, open the Remote Profiles panel and click the Add a new path item button from the right-hand side. In theAdd Remote Path Item or Edit Remote Path Item dialog:
    • For OpenGL, set the path on remote machine /System/Library/Frameworks, the file mask OpenGL, and the path type Framework.
    • For GLUT, set the path on remote machine /System/Library/Frameworks, the file mask GLUT, and the path type Framework.

    Update: The path on remote machine for newer version of XCode may change to /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks



    Update local file cache

    See also:
    http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_intro/opengl_intro.html

    and

    http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_drawing/opengl_drawing.html#//apple_ref/doc/uid/TP40001987-CH404-SW8

    C++ Builder XE3 Predefined Macros




    (http://docwiki.embarcadero.com/RADStudio/XE3/en/Predefined_Macros)

    The C++ compiler predefines certain global identifiers, known as manifest constants. Most global identifiers begin and end with two underscores (__).

    Note: For readability, underscores are often separated by a single blank space. In your source code, you should never insert whitespace between underscores.

    For macros whose value takes the form of 0x0nnn, the version number (nnn) is determined by the version number of the associated C++ compiler executable. Beginning with the XE release, you can verify the version number using the --version option to BCC32.EXE.

    MacroValueDescription
    __APPLE__
    Defined only in compilers that support cross compiling with a target of MAC OSX. See BCCOSX.EXE, the C++ Cross Compiler for OS X.
    __BCOPT__
    1
    Defined only in compilers that support optimization, therefore always defined.
    __BCPLUSPLUS__
    Values are listed in C++ Compiler Versions in this topic.
    Defined if you've selected C++ compilation; will increase in later releases.
    __BOOL__
    1
    Indicates that the bool keyword is accepted.
    __BORLANDC__
    Values are listed in C++ Compiler Versions in this topic.
    Version number.
    __CDECL__
    1
    Defined if Calling Convention is set to cdecl; otherwise undefined.
    _CHAR_UNSIGNED
    1
    Undefined by default. Using the -K switch to make the default character unsigned causes this macro to be defined. Ultimately, the -K option controls how a char is extended when converted to an int. By default, the compiler sign-extends, but if you enable _CHAR_UNSIGNED_, then the compiler zero-extends characters when converting to int.
    _clang_ 
    Defined if BCC64 is in use.
    __CODEGEARC__
    Values are listed in C++ Compiler Versions and in this topic.
    Version number.
    __CODEGEARC_VERSION__
    • Major version number is bits 31..24
    • Minor version number is bits 23..16
    • Internal version number is bits 15..0
    This internal macro expands to an integer that encodes the compiler's major version, minor version, and an internal number. See Example of __CODEGEARC_VERSION__ Macro.
    __CODEGUARD__
    Defined whenever one of the CodeGuard compiler options is used; otherwise it is undefined.
    __CONSOLE__
    1
    When defined, the macro indicates that the program is a console application.
    _CPPUNWIND
    1
    Enable stack unwinding. This is true by default; use -xd-!ALink(OSCGExceptions1) to disable.
    __cplusplus
    1
    Defined if in C++ mode; otherwise, undefined.
    __DATE__
    String literal
    Date when processing began on the current file.
    __DLL__
    1
    Defined whenever the -WD compiler option is used; otherwise it is undefined.
    __FILE__
    String literal
    Name of the current file being processed.
    __FLAT__
    1
    Defined when compiling in 32-bit flat memory model.
    __FUNC__ or__FUNCTION__
    String literal
    Name of the current function being processed. More details.
    __LINE__
    Decimal constant
    Number of the current source file line being processed.
    __MACH__
    Defined only in compilers that support cross compiling with a target of MAC OSX.
    _M_IX86
    0x12c
    Always defined. The default value is 300. You can change the value to 400 or 500 by using the /4 or /5 compiler options.
    __MT__
    1
    Defined only if the -tWM option is used. It specifies that the multithread library is to be linked.
    __PASCAL__
    1
    Defined if Calling Convention is set to Pascal; otherwise undefined.
    _PUSHPOP_SUPPORTED
    1
    Always defined; allows Microsoft standard headers to use push and pop to verify whether a feature is supported.
    _STDCALL_SUPPORTED
    1
    Always defined; defines the Microsoft stdcall calling convention.
    __STDC__
    1
    Defined if you compile with the -A compiler option; otherwise, it is undefined.
    __TCPLUSPLUS__
    Values are listed in C++ Compiler Versions in this topic.
    Version number.
    __TEMPLATES__
    1
    Defined as 1 for C++ files (meaning that templates are supported); otherwise, it is undefined.
    __TIME__
    String literal
    Time when processing began on the current file.
    __TLS__
    1
    Thread Local Storage. Always true.
    __TURBOC__
    Values are listed in C++ Compiler Versions and in this topic.
    Will increase in later releases.
    _UNICODE and UNICODE
    Defined for C++ programs that use the VCL.
    _WCHAR_T
    Defined only for C++ programs to indicate that wchar_t is an intrinsically defined data type.
    _WCHAR_T_DEFINED
    Defined only for C++ programs to indicate that wchar_t is an intrinsically defined data type.
    _Windows
    1
    Defined when compiling on the Windows platform.
    __WIN32__
    1
    Defined for console and GUI applications on the 32-bit Windows platform.
    _WIN64
    1
    Defined for console and GUI applications on the 64-bit Windows platform.
    Note: The predefined macros __DATE____FILE__ __FUNC____LINE____STDC__, and __TIME__ cannot be redefined or undefined.

    C++ Compiler Versions in Predefined Macros

    The macros defined for the C++ compiler (such as __CODEGEARC__) have the following version numbers:
    • 0x0570 for BDS 2006
    • 0x0590 for C++Builder 2007
    • 0x0591 for update 1 to C++Builder 2007
    • 0x0592 for RAD Studio 2007
    • 0x0593 for the December update to RAD Studio 2007
    • 0x0610 for C++Builder 2009 and for C++Builder 2009 Update 1
    • 0x0620 for C++Builder 2010 and for C++Builder 2010 Update 1
    • 0x0621 for C++Builder 2010 Update 2
    • 0x0630 for C++Builder XE
    • 0x0631 for C++Builder XE Update 1
    • 0x0640 for C++Builder XE2
    • 0x0650 for C++Builder XE3

    Macros Defined Elsewhere

    The following macros are defined for backwards-compatibility when you #include System.hpp:
    MacroValueDescription
    ANSISTRING_AS_TEMPLATE
    AnsiString type is defined as a template class, AnsiString<T>.
    _STRINGCHECKS_OFF
    (no longer supported)
    In past releases, C++ programs expected the Delphi compiler to not set the STRINGCHECKS directive. The Delphi compiler no longer supports the STRINGCHECKS directive, so the related _STRINGCHECKS_OFF C++ macro is unnecessary and is no longer set. Therefore if you are migrating pre-2009 code to the current version, you need to update the event-handler signature (because a pre-2009 event handler expects AnsiString, while the run time now sends UnicodeString). See Unicode in RAD Studio.

    See Also



    C++ Builder XE3 MAC OS X [ILINK32 Error] Fatal: Error detected (ILI1548)

    [Project]->[Options...]->[Packages]->[Runtime Packages]->[Link with runtime packages]  MUST be [true].


    Thursday, January 17, 2013

    [bccosx Error] sysmac.h(65): E2209 Unable to open include file 'CoreFoundation/CoreFoundation.h'

    Mac OS X  Client 端需安裝 XCode command line tools.
    安裝方法 :

    參考:
    http://www.itwriting.com/blog/7032-hands-on-cross-platform-windows-and-mac-with-c-builder-xe3.html

    or

    http://docwiki.embarcadero.com/RADStudio/XE3/en/Connecting_Your_PC_to_a_Mac#Xcode_Is_Required_on_the_Mac_for_C.2B.2B_and_FMX)


    Xcode Is Required on the Mac for C++ and FMX

    Xcode is the development and debug environment on the Mac, and provides the required development files for OS X applications.

    Installing Xcode on Your Mac

    You can install Xcode from any of the following sources:
    • On your "Mac OS X Install" DVD, under Optional Installs, double-click Xcode.mpkg to install Xcode on your system.
    • At the Mac App Store, download Xcode for free.
    • As a registered Apple Developer, you can download the free version of Xcode. To register and then download Xcode:
      1. Register (free of charge) as an Apple Developer at http://developer.apple.com/programs/register/.
      2. Go to the Mac Dev Center
      3. Click the View in Mac App Store link associated with Xcode, and download Xcode to your Mac.

    Installing Xcode Command Line Tools (for C/C++ Development)

    A clean install of the Lion operating system (OS X 107), even with Xcode, does not contain /usr/include. You also need to install the Xcode command-line tools.
    You can download the command line tools in either of two ways:
    To install the necessary Xcode tools from the Web:
    You can download the Xcode command line tools directly from the developer portal as a .dmg file.
    1. On the Mac, go to https://developer.apple.com/downloads/index.action
      You are asked for your Apple Developer login during the install process.
    2. On the "Downloads for Apple Developers" list, select the Command Line Tools entry that you want.
    To install the necessary Xcode tools from Xcode:
    1. Start Xcode on the Mac.
    2. Choose Preferences from the Xcode menu.
    3. In the General panel, click Downloads.
    4. On the Downloads window, choose the Components tab.
    5. Click the Install button next to Command Line Tools.
      You are asked for your Apple Developer login during the install process.


    [Qt] 執行檔需要哪些 Dll?

     1. 使用 Qt  的 windeployqt.exe 工具 (在 C:\Qt\Qt5.14.1\5.14.1\msvc2017\bin\)。   a. 把執行檔 myProgram.exe 放在某個資料夾。   b. 在檔案總管這個資料夾按 Shift 和滑鼠右鍵,開啟 Po...