Home Documents>

Archive of materials

Notes: "You have exceeded the maximum number of open cursor ORA-01000" [Java]

Notes on the error of OracleDB that: "You have exceeded the maximum number of open cursor ORA-01000" came across the other day.

Became a problem like the following code
(. Unconfirmed operation. Thing for exposing the code to the translation work will not go, rewritten as a sample)

import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.List; public class cursorLeakeSample { public cursorLeakeSample(List idList) { try { // Oracle JDBC Driverのロード Class.forName("oracle.jdbc.driver.OracleDriver"); // コネクション取得 Connection connection = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:ORCL", "scott", "tiger"); String sql = "SELECT NAME FROM ITEM WHERE ID = ?"; PreparedStatement statement = null; try { for (String id : idList) { Object[] params = new Object[] { id }; // SQLにパラメータ埋め込みと実行statement = connection.prepareStatement(sql); statement.setObject(1, params[0]); statement.executeUpdate(); connection.commit(); } } catch (SQLException e) { // SQL実行失敗 connection.rollback(); e.printStackTrace(); } finally { statement.close(); connection.close(); } } catch (SQLException e) { // コネクションの接続・切断・ロールバック、ステートメントの解放に失敗 e.printStackTrace(); } catch (ClassNotFoundException e) { // Oracle JDBC ドライバが見つからなかった e.printStackTrace(); } } }  import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.List; public class cursorLeakeSample { public cursorLeakeSample(List idList) { try { // Oracle JDBC Driverのロード Class.forName("oracle.jdbc.driver.OracleDriver"); // コネクション取得 Connection connection = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:ORCL", "scott", "tiger"); String sql = "SELECT NAME FROM ITEM WHERE ID = ?"; PreparedStatement statement = null; try { for (String id : idList) { Object[] params = new Object[] { id }; // SQLにパラメータ埋め込みと実行statement = connection.prepareStatement(sql); statement.setObject(1, params[0]); statement.executeUpdate(); connection.commit(); } } catch (SQLException e) { // SQL実行失敗 connection.rollback(); e.printStackTrace(); } finally { statement.close(); connection.close(); } } catch (SQLException e) { // コネクションの接続・切断・ロールバック、ステートメントの解放に失敗 e.printStackTrace(); } catch (ClassNotFoundException e) { // Oracle JDBC ドライバが見つからなかった e.printStackTrace(); } } } 

Is the part where the emphasis that has caused.
Do you know Why not?
First, turn put a value to use as an empty box to create a variable statement, obtained in a loop, released at the end.
At first glance, it looks so causing the leak is a release, you can find the problem and follow the process a little.

"PrepareStatement" will create a cursor implicitly for the preparation of SQL.
The code in question is a lot of implicit that the cursor has been generated in the loop and know that this.
And it has been released only one of the "prepareStatement" The last that was stored when exiting out of the loop.

For example, 19 is not that it does not be released if the process was 20.

So, what should I write if

 import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.List; public class cursorLeakeSample { public cursorLeakeSample(List idList) { try { // Oracle JDBC Driverのロード Class.forName("oracle.jdbc.driver.OracleDriver"); // コネクション取得 Connection connection = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:ORCL", "scott", "tiger"); String sql = "SELECT NAME FROM ITEM WHERE ID = ?"; PreparedStatement statement = connection.prepareStatement(sql); try { for (String id : idList) { Object[] params = new Object[] { id }; // SQLにパラメータ埋め込みと実行 statement.setObject(1, params[0]); statement.executeUpdate(); connection.commit(); } } catch (SQLException e) { // SQL実行失敗 connection.rollback(); e.printStackTrace(); } finally { statement.close(); connection.close(); } } catch (SQLException e) { // コネクションの接続・切断・ロールバック、ステートメントの解放に失敗 e.printStackTrace(); } catch (ClassNotFoundException e) { // Oracle JDBC ドライバが見つからなかった e.printStackTrace(); } } }  import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.List; public class cursorLeakeSample { public cursorLeakeSample(List idList) { try { // Oracle JDBC Driverのロード Class.forName("oracle.jdbc.driver.OracleDriver"); // コネクション取得 Connection connection = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:ORCL", "scott", "tiger"); String sql = "SELECT NAME FROM ITEM WHERE ID = ?"; PreparedStatement statement = connection.prepareStatement(sql); try { for (String id : idList) { Object[] params = new Object[] { id }; // SQLにパラメータ埋め込みと実行 statement.setObject(1, params[0]); statement.executeUpdate(); connection.commit(); } } catch (SQLException e) { // SQL実行失敗 connection.rollback(); e.printStackTrace(); } finally { statement.close(); connection.close(); } } catch (SQLException e) { // コネクションの接続・切断・ロールバック、ステートメントの解放に失敗 e.printStackTrace(); } catch (ClassNotFoundException e) { // Oracle JDBC ドライバが見つからなかった e.printStackTrace(); } } } 

Maybe this way. If you use the "PreparedStatement".
What do I think; close () in the statement so if you want to use it for "Statement" Tadano.

Dynamic addition of [Java] Class path

Note: Now that we have implemented in my own way I look and you want to create a program with reference to the softening of Tomcat WEB-INF/classes Jar and other systems.
" One-Jar "or" Fat Jar If you think can respond with "and there had better take advantage of.
Incidentally, the operation check was confirmed that it works even when summarized in the Jar is JRE5.

 package jp.moonwing.net; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; /** * クラスパスの動的追加 * * @author $Author: U.Yobane $ * @version $Version: v 043b2b764886 2011/06/13 01:23:25+0900(JST) $ */ public final class ApplicationClassLoader { /** クラス情報格納フィールド */ private static final Class<?>[] PARAMETERS = new Class<?>[] { URL.class }; /** * コンストラクタ */ private ApplicationClassLoader() { } /** * メイン * * @param args 起動引数文字列配列 */ public static void main(String[] args) { try { // クラスパスの追加 addClassPath( {追加したいクラスパスディレクトリ} ); addClassPath( {追加したいJAR} ); // メインプログラムを実行 Application.execute(args); } catch (IOException e) { e.printStackTrace(); } } /** * クラスローダーにクラスパスを動的追加 * * @param classPath 追加するクラスパス * @throws IOException クラスパスの動的追加に失敗 */ public static void addClassPath(String classPath) throws IOException { addClassPath(new File(classPath)); } /** * クラスパスを再帰的にたどり、追加可能パスはすべて追加 * * @param classPath 追加するファイル * @throws IOException クラスパスの動的追加に失敗 */ private static void addClassPath(File classPath) throws IOException { if (classPath.isDirectory()) { // ディレクトリを追加 addClassPath(classPath.toURL()); // ディレクトリ配下を探索 File[] child = classPath.listFiles(); for (int i = 0; i < child.length; i++) { addClassPath(child[i]); } } else { String suffix = getSuffix(classPath.getName()); // 見つかったファイルがJARもしくはZipの場合は追加 if (suffix.equalsIgnoreCase("zip") || suffix.equalsIgnoreCase("jar")) { addClassPath(classPath.toURL()); } } } /** * システムクラスローダーにクラスパスを強制的に追加 * * @param classPathUrl クラスパス * @throws IOException クラスパスの動的追加に失敗 */ private static void addClassPath(URL classPathUrl) throws IOException { URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class<?> sysclass = URLClassLoader.class; try { Method method = sysclass.getDeclaredMethod("addURL", PARAMETERS); method.setAccessible(true); method.invoke(sysloader, new Object[] { classPathUrl }); } catch (NoSuchMethodException e) { throw new IOException("could not add " + classPathUrl + " to classpath"); } catch (InvocationTargetException e) { throw new IOException("could not add " + classPathUrl + " to classpath"); } catch (IllegalAccessException e) { throw new IOException("could not add " + classPathUrl + " to classpath"); } } /** * ファイル名から拡張子を返却 * * @param fileName ファイル名 * @return ファイルの拡張子 */ private static String getSuffix(String fileName) { if (fileName == null) { return null; } int point = fileName.lastIndexOf("."); if (point != -1) { return fileName.substring(point + 1); } return fileName; } } 

UAC support of the [C #] application

Note If you want to change the behavior in general and administrative rights and privileges on the application side

  1. Judging from the information whether the version of OS has been started since WindowsVista is <br /> or application is running in a (OS with UAC) and later WindowsVista

     using System; private bool IsUAC() { OperatingSystem osInfo = Environment.OSVersion; if (osInfo.Platform == PlatformID.Win32NT) { if (osInfo.Version.Major == 6) { if (osInfo.Version.Minor == 0) { // Windows Vista, Windows Server 2008 return true; } else if (osInfo.Version.Minor == 1) { // Windows 7, Windows Server 2008 R2 return true; } } else if (osInfo.Version.Major > 6) { // new Windows return true; } } return false; } 
  2. When they are ... "Run as administrator" is <br /> or application has been started the application with administrator privileges

     using System.Security.Principal; private bool IsAdministrator() { bool isAllowed = false; try { WindowsIdentity wi = WindowsIdentity.GetCurrent(); WindowsPrincipal wp = new WindowsPrincipal(wi); isAllowed = wp.IsInRole(WindowsBuiltInRole.Administrator); } catch { isAllowed = false; } return isAllowed; } 
  3. The user who started the application <br /> If you want to know whether the application can be promoted to the administrator user who started even if it has been started with the privileges that belong to the Administrators group or general

     using System.DirectoryServices.AccountManagement; private bool IsAdministrators() { bool isAllowed = false; try { PrincipalContext pc = new PrincipalContext(ContextType.Machine, null); UserPrincipal up = UserPrincipal.Current; GroupPrincipal gp = GroupPrincipal.FindByIdentity(pc, "Administrators"); if (up.IsMemberOf(gp)) { isAllowed = true; } } catch { isAllowed = false; } return isAllowed; } 

    Like not working well in some environments and that the above code? May ensure that more of the code below.

     using System.DirectoryServices.AccountManagement; private bool IsAdministrators() { bool isAllowed = false; try { PrincipalContext pc = new PrincipalContext(ContextType.Machine, null); UserPrincipal up = UserPrincipal.Current; foreach (GroupPrincipal gp in up.GetGroups()) { try { if (gp.Name.ToLower().Equals("Administrators".ToLower())) { isAllowed = true; } } finally { gp.Dispose(); } } } catch { isAllowed = false; } return isAllowed; } 
  4. With administrator privileges to restart itself if the administrative authority that was required when processing <br /> restart the application with administrator privileges

     using System; using System.Diagnostics; private void RestartApplication() { ProcessStartInfo psi = new ProcessStartInfo(); psi.UseShellExecute = true; psi.WorkingDirectory = Environment.CurrentDirectory; psi.FileName = Application.ExecutablePath; psi.Verb = "runas"; try { Process p = Process.Start(psi); } catch { return; } Application.Exit(); } 
  5. To display the icon of the (vertical) UAC on the button to inform the user that will require administrative privileges to continue the operation to display an icon <br /> (vertical) UAC to the button that must have administrator privileges (The shield icon and Win32API shield icon SystemIcons.Shield property there is a difference, it has been used as standard in Windows 7. which is more Win32 API)

     using System; using System.Windows.Forms; using System.Runtime.InteropServices; namespace Sample { public partial class Form1 : Form { [DllImport("user32.dll")] private static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam); // 第2パラメータ:盾アイコンを設定するフラグ uint BCM_SETSHIELD = 0x0000160C; public Form1() { InitializeComponent(); // ボタンの外観を「System」にする必要がある button1.FlatStyle = FlatStyle.System; } private void checkBox1_CheckedChanged(object sender, EventArgs e) { // 第1パラメータ:ボタンのウィンドウ・ハンドル HandleRef hwnd = new HandleRef(button1, button1.Handle); if (checkBox1.Checked) { SendMessage(hwnd, BCM_SETSHIELD, new IntPtr(0), new IntPtr(1)); } else { SendMessage(hwnd, BCM_SETSHIELD, new IntPtr(0), new IntPtr(0)); } } } } 

PSP backlight replacement fuse

PSPのバックライトヒューズの位置
PSP-1000 screen no longer appears suddenly.
I hear the sound, sound that is heard is also a button.

And stare hard, thin ー graphical display had been.

Come truly pioneers and examine the information on the net and then to guess the backlight has expired from this situation.

Immediately, decomposition, and then try to check the continuity of the fuse it was up to me to publish the location of the fuse of the backlight carefully.

With a digital multimeter but no reaction, the fuse itself did not know what that is properly squareness of its 1005 size chip fuses.
For example, it would not be measured or if there thin film on the surface.

I decided to replace on spec.
Replacement fuse of 0.5A for the F4501.
First, as I think giving up does not melt the solder but was thinking that you are replacing as a policy.
Therefore, we decided to put in parallel.
(If existing fuse was alive, because the current is split) if this, strictly speaking, but it also not good,
It is considered recovered if the backlight in this work, the fuse is not the same as off,
Separately as if there is no good cause, so by removing good.

Is, the recovery work was carried out safely backlight.
PSP was to play with again.

KuroBox repair of power

玄箱の電源回路のヒューズ リード付きヒューズ
Plug the power supply remains KuroBox sister, accidentally touched the power, note that since the repair work had to turn off the fuse

Gen is the first thing of the unbranded box.
But actually it was going to pull the power plug is pulled out another power plug, power KuroBox was not missing.
Blue spark had died would touch the foot with a fuse of the power of resistance due to the work as missing.

Power does not enter as expected also to apply power to the hand to go to sleep is in a hurry without giving eyes, to make sure you have not failed.
Yes, if the power was to go KuroBox tail. If this happens too late.

Had to recover and replace the fuse, must not have had people look like is short on the net while looking for information dents.

But for now, even if your own a blown fuse? To verify the continuity of the (F1) fuse with a digital multimeter and think.
Result has not been conducted. This means that the fuse has expired.
This may be lucky.
Fuse from the circuit meant to cut off so as not to damage the circuit when it becomes excessive current or excessive voltage, the abnormal temperature protection circuit, there is a possibility What other part is not damaged because might be that lucky.
And that you can see the continuity of the fuse to the contrary, will be part of the other is damaged, it is difficult to identify the cause.

Well, the radio center was Onuma was looking for a 3A fuse in Akihabara with lead based on the information on the net.
Was 150 yen in two. The problem was discovered with the return journey while And i think Akihabara indeed, do the work and immediately exchange

Because it is written with 2A fuse If you look closely at the original.
But moving from 3A fuse itself but the only thing connecting the circuit, even when it was 2A overcurrent becomes normal to 3A.
This is because the potential damage to other parts of the fuse when overcurrent is born, to exchange new people like to buy 2A.

It should be noted, was able to retrofit without problems with lead lead of the fuse you have purchased but was a little thick.
And, make sure that you can successfully starts When you power up.

If you find a fuse trying to replace leaded 2A · · ·

Create and sign for publisher's certificate [VS] software

Note of the method signature for how to create and sign a certificate to create things.

If you want to use ClickOnce to install the VSTO or self-signed certificate, the certificate shall be Oreore and he did, what you need.
The tool you use WindowsSDK which is included in the.

  • How to create
     rem 1.==== rem CA:Certificate Authority:認証局証明書rem 会社名 : MoonWing rem 組織名 : MoonWing Authority Root CA rem 県 名 : Tokyo rem 国 名 : JP rem 有効期限: 2012.12.31 "%ProgramFiles%\Microsoft SDKs\Windows\v7.1\Bin\makecert" -r -n "C=JP, S=Tokyo, OU=MoonWing Authority Root CA, O=MoonWing" -e 12/31/2012 -a sha1 -cy authority -sv moonwingCA.pvk moonwingCA.cer rem 秘密キーのパスワードの作成:Subject Key: rootCA rem 秘密キーのパスワードの入力:Subject Key: rootCA rem 2.==== rem EE:End Entity:署名用証明書rem コモン名: MoonWing rem 会社名 : MoonWing rem 組織名 : MoonWing Development rem 県 名 : Tokyo rem 国 名 : JP rem 有効期限: 2012.12.31 "%ProgramFiles%\Microsoft SDKs\Windows\v7.1\Bin\makecert" -n "CN=MoonWing, C=JP, S=Tokyo, O=MoonWing, OU=MoonWing Development" -e 12/31/2012 -sv moonwing.pvk -ic moonwingCA.cer -iv moonwingCA.pvk -nscp -cy end moonwing.cer rem 秘密キーのパスワードの作成:Subject Key: endEntity rem 秘密キーのパスワードの入力:Subject Key: endEntity rem 秘密キーのパスワードの入力:Issuer Signature: rootCA rem 3.==== rem SPC:Software Publisher's Certificate:ソフトウェア発行元証明書"%ProgramFiles%\Microsoft SDKs\Windows\v7.1\Bin\Cert2SPC" moonwing.cer moonwingCA.cer moonwing.spc rem 4.==== rem PFX:Personal Information Exchange:PKCS#12 rem -pi(pvkpassword):endEntity rem -po(pfxpassword):SPC "%ProgramFiles%\Microsoft SDKs\Windows\v7.1\Bin\pvk2pfx" -pvk moonwing.pvk -pi endEntity -spc moonwing.spc -pfx moonwing.pfx -po SPC 
  • Signature method
     rem 5.==== rem target.exeへ署名rem -t(time stamp server):http://timestamp.verisign.com/scripts/timstamp.dll rem -p(pfxpassword):SPC "%ProgramFiles%\Microsoft SDKs\Windows\v7.1\Bin\signtool" sign /f moonwing.pfx /a /t http://timestamp.verisign.com/scripts/timstamp.dll /p SPC target.exe 

Summary compliant version [VS] PIA

Version of the table. NetFramework version of the PIA with the version of Office and VSTO table created in passing.
PIA is ... and that PrimaryInteropAssembly more Microsoft Please ask.

PIA Office support . NetFramework support Windows support
XP XP 1.1 XP
2003 2003 1.1 2000 SP3, XP, Server 2003
2007 2007 1.1 2000 SP4, XP SP2, Server 2003
2010 2010 2.0 or higher 2000 SP4, XP SP2, Server 2003, Vista, 7, Server 2008

Summary compliant version [VS] VSTO

Was created because of want a version of the table. NetFramework version and the version of Office and VSTO.
VSTO is and

  • Microsoft Visual Studio 2005 Tools for Office Second Edition Runtime
  • Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System
  • Microsoft Visual Studio Tools for the Microsoft Office system (Version 3.0 Runtime)
  • Microsoft Visual Studio 2010 Tools for the Microsoft Office System (Version 4.0 Runtime)

Office for the extension of the component is that the name has changed subtly with.
Basically should not be a problem if the following three two eyes above was omitted.
(. Or that, may I also omitted the first three, but it will not be able to correspond to the two end up in 2003,2007,2010)

Vsto Office support . NetFramework support Support VisualStduio Windows support
2005 SE 2003, 2007 2.0 2005 2000, XP, Server 2003, Vista, 7, Server 2008
3.0 2007 3.5 SP1 2008 2000, XP, Server 2003, Vista, 7, Server 2008
4.0 2007,2010 3.5 SP1 2010 XP, Server 2003, Vista, 7, Server 2008

Directives

Note to isolate the portion of the platform-dependent preprocessor directives when writing cross-platform code.

  • Compiler
    • GCC
      • # Ifdef __ GNUC__
        • Or more # if __ GNUC__> = 3 / / GCC3.0
    • Borland C + +
      • # Ifdef __ BORLANDC__
    • intel Compiler
      • # Ifdef __ INTEL_COMPILER
    • Microsoft Compiler
      • # Ifdef _MSC_VER
        • # VC later if _MSC_VER> = 600 / / C Compiler 6.0 + + including
        • # VC later if _MSC_VER> = 700 / / C / C + + Compiler 7.0 + + including
        • # Later if _MSC_VER> = 800 / / VC + +1.0
        • # Later if _MSC_VER> = 900 / / VC + +2.0
        • # Later if _MSC_VER> = 1000 / / VC + +4.0
        • # Later if _MSC_VER> = 1010 / / VC + +4.1
        • # Later if _MSC_VER> = 1020 / / VC + +4.2
        • # Later if _MSC_VER> = 1100 / / VC + +5.0
        • # Later if _MSC_VER> = 1200 / / VC + +6.0
        • # If _MSC_VER> = 1300 / / VC2002 later (VC7.0)
        • # If _MSC_VER> = 1310 / / VC2003 later (VC7.1)
        • # If _MSC_VER> = 1400 / / VC2005 later (VC8.0)
        • # If _MSC_VER> = 1500 / / VC2008 later (VC9.0)
        • # If _MSC_VER> = 1600 / / VC2010 later (VC10.0)
  • UNIX system
    • UNIX
      • # Ifdef __ unix
      • # Ifdef __ unix__
    • Linux
      • # Ifdef __ linux
      • # Ifdef __ linux__
    • FreeBSD
      • # Ifdef __ FreeBSD__
    • NetBSD
      • # Ifdef __ NetBSD__
    • Cygwin
      • # Ifdef __ CYGWIN__
      • # Cygwin version ifdef __ CYGWIN32__ / / 32bit
    • MinGW (-mno-cygwin)
      • # Ifdef __ MINGW32__
  • Windows system
    • CUI
      • # Ifdef _CONSOLE
    • GUI
      • # Ifdef _WINDOWS
    • 32bit Windows
      • # Ifdef WIN32
      • # Ifdef _WIN32
    • 64bit Windows
      • # Ifdef _WIN64
    • Windows version
      • # Ifdef WINVER
        • Since # if (WINVER> = 0x030a) / / Windows 3.1
        • # Since 95 / NT4.0 (WINVER> = 0 × 0400) / / Windows if
        • Since # if (WINVER> = 0 × 0410) / / Windows 98
        • Since # if (WINVER> = 0 × 0500) / / Windows Me / 2000
        • Since # if (WINVER> = 0 × 0501) / / Windows XP / Server 2003
        • # Since 2003 SP1 (WINVER> = 0 × 0502) / / Windows XP SP2 / Server if
        • Since # if (WINVER> = 0 × 0600) / / Windows Vista / Server 2008
        • Since # if (WINVER> = 0 × 0601) / / Windows 7
      • # Ifdef _WIN32_WINDOWS / / Windows9x
        • # If later (_WIN32_WINDOWS> = 0 × 0400) / / Windows 95
        • # If later (_WIN32_WINDOWS> = 0 × 0410) / / Windows 98
        • # If later (_WIN32_WINDOWS> = 0 × 0500) / / Windows Me
      • # Ifdef _WIN32_WINNT / / WindowsNTx
        • / / Since Windows 2000 (0 × 0500)
          # If (_WIN32_WINNT> = _WIN32_WINNT_WIN2K)
        • / / Since 2003 Windows XP / Server (0 × 0501)
          # If (_WIN32_WINNT> = _WIN32_WINNT_WINXP)
        • / / Since 2003 SP1 Windows XP SP2 / Server (0 × 0502)
          # If (_WIN32_WINNT> = _WIN32_WINNT_WS03)
        • / / From Windows Vista (0 × 0600)
          # If (_WIN32_WINNT> = _WIN32_WINNT_VISTA)
        • / / From Windows Server 2008 (0 × 0600)
          # If (_WIN32_WINNT> = _WIN32_WINNT_WS08)
        • / / From Windows 7 (0 × 0601)
          # If (_WIN32_WINNT> = _WIN32_WINNT_WIN7)
      • # Ifdef _WIN32_WCE / / WindowsCE
        • # If (_WIN32_WCE> = 0 × 0420) / / Windows Mobile 2003 (PPC2003)
        • # If (_WIN32_WCE> = 0 × 0421) / / Windows Mobile 2003 SE (PPC2003SE)
        • # If (_WIN32_WCE> = 0 × 0501) / / Windows Mobile 5.0
        • # If (_WIN32_WCE> = 0 × 0502) / / Windows Mobile 6 Professional / Classic
        • # If (WINCEOSVER> = 0 × 0300) / / WindowsCE3.0 later (PPC2002)
        • # If (WINCEOSVER> = 0 × 0420) / / WindowsCE4.2 later (PPC2003)
        • # If (WINCEOSVER> = 0 × 0500) / / WindowsCE5.0 later (WM5.0)
    • Internet Explorer version
      • # Ifdef _WIN32_IE
        • # If (_WIN32_IE> = 0 × 0200) / / Windows 95/NT 4.0 (Comctl32.dll 4.00, Shell32.dll 4.00)
        • # If (_WIN32_IE> = 0 × 0300) / / Internet Explorer 3.0, 3.01, 3.02
        • # If (_WIN32_IE> = 0 × 0400) / / Internet Explorer 4.0
        • # If (_WIN32_IE> = 0 × 0401) / / Internet Explorer 4.01
        • # If (_WIN32_IE> = 0 × 0500) / / Internet Explorer 5.0, 5.0a, 5.0b
        • # If (_WIN32_IE> = 0 × 0501) / / Internet Explorer 5.01
        • # If (_WIN32_IE> = 0 × 0550) / / Internet Explorer 5.5
        • # If (_WIN32_IE> = 0 × 0600) / / Internet Explorer 6.0
        • # If (_WIN32_IE> = 0 × 0601) / / Internet Explorer 6.0 SP1
        • # If (_WIN32_IE> = 0 × 0603) / / Internet Explorer 6.0 SP2
        • # If (_WIN32_IE> = 0 × 0700) / / Internet Explorer 7.0
        • # If (_WIN32_IE> = 0 × 0800) / / Internet Explorer 8.0

Note <br /> preprocessor, to treat as 0 undefined identifier, # if __ GNUC__> = 3 or more, but can be used as GCC3,
If you try to determine # if __ GNUC__ <3 whether the system GCC2, include those that are not GCC.
Reference

Gets the version of Windows

But I do not think I can use, tentatively note.
If the compiler can be compiled without problems and I think system Windows.
Tentatively, compile and confirm the operation was carried out in MinGW.

 #include <windows.h> #include <stdio.h> int main(void) { unsigned int GV = GetVersion(); printf("GetVersion API(GV) = %08X\n\n", GV); printf("_winver = %08X\n", _winver); printf("_winmajor = %08X\n", _winmajor); printf("_winminor = %08X\n", _winminor); printf("_osver = %08X\n\n", _osver); printf("(( GV << 8 ) | (( GV >> 8 ) & 0XFF)) & 0XFFFF = %08X (= _winver)\n", (( GV << 8 ) | (( GV >> 8 ) & 0XFF)) & 0XFFFF ); printf("GV & 0XFF = %08X (= _winmajor)\n", GV & 0XFF ); printf("( GV >> 8 ) & 0XFF = %08X (= _winminor)\n", (( GV >> 8 ) & 0XFF)); printf("GV >> 16 = %08X (= _osver)\n\n\n", (GV >> 16) ); // Windows version(_winmajor, _winminor, _osver) printf("This system is ["); if ( _osver < 0X8000 ) { // NT Group (_osver LowWORD MSB = 0) switch (_winmajor) { case 3: case 4: printf ("Windows NT %u.%u Build %u", _winmajor, _winminor, _osver); break; case 5: switch (_winminor) { case 0: printf ("Windows 2000 Build %u", _osver); break; case 1: printf ("Windows XP Build %u", _osver); break; case 2: printf ("Windows Server 2003 family Build %u", _osver); break; default: printf ("NT Group Windows Build %u", _osver); } break; case 6: switch (_winminor) { case 0: printf ("Windows Vista or Windows Server 2008 Build %u", _osver); break; case 1: printf ("Windows 7 Build %u", _osver); break; default: printf ("NT Group Windows Build %u", _osver); } break; default: printf ("NTGroup Windows Build %u", _osver); } } else { switch (_winmajor ) { case 0: //Win32s Group case 1: case 2: case 3: printf ("Win32s Build %u", _osver & 0X7FFF); break; case 4: // 9X Group (_osver is invalid.) switch (_winminor) { case 0: printf ("Windows 95 Build ----"); break; case 10: printf ("Windows 98 Build ----"); break; case 90: printf ("Windows Me Build ----"); break; default: // To make sure printf ("Newer than Windows Me"); } break; default: // To make sure printf ("Newer than Windows Me"); } } printf("]"); return 0; } 
1 2 3

Home Documents>

Search
Feed
Translation
Japanese flagItalian flagKorean flagChinese (Simplified) flagChinese (Traditional) flagEnglish flagGerman flagFrench flagRussian flagVietnamese flagThai flag

Back to the top of the page