'Bit/C#'에 해당되는 글 26건
- 2012.02.03 C# 정말 굿이에요~굿~굿~굿~!! ㅋ.ㅋ
- 2012.02.03 c#에서 String 을 int 형으로 형변환
- 2012.02.03 csc 도움말? ㅋ
- 2012.02.03 c# dll 파일 만들어 메인클래스에 적용
- 2012.02.03 c# 클래스 파일로 저장
- 2012.02.03 c# Array list 파일로 저장
- 2012.02.03 오라클 접속
- 2012.02.03 오라클 bfile 을 이용하여 디렉토리 내의 파일 참조
- 2012.02.03 VC.NET 2005 로 컴파일된 프로그램 배포시 주의할 사항
- 2012.02.03 RegisterHotKey - Windows Hotkey 설정
c#에서 String 을 int 형으로 형변환
public static void Main(String[] args)
{
int a;
a = Int32.Parse(Console.ReadLine()); //입력받은 문자열을 int형으로 저장
Console.WriteLine("{0}",a);
}
csc 도움말? ㅋ
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
Visual C# 2005 컴파일러 옵션
- 출력 파일 -
/out:<file> 출력 파일 이름을 지정합니다(기본값: 주 클래스가
있는 파일 또는 첫째 파일의 기본 이름).
/target:exe 콘솔 실행 파일을 빌드합니다(기본값). (약식:
/t:exe)
/target:winexe Windows 실행 파일을 빌드합니다. (약식: /t:winexe)
/target:library 라이브러리를 빌드합니다. (약식: /t:library)
/target:module 다른 어셈블리에 추가될 수 있는 모듈을 빌드합니다.
(약식: /t:module)
/delaysign[+|-] 강력한 이름 키의 공개 부분만 사용하여 어셈블리
서명을 연기합니다.
/doc:<file> 생성할 XML 문서 파일
/keyfile:<file> 강력한 이름의 키 파일을 지정합니다.
/keycontainer:<string> 강력한 이름의 키 컨테이너를 지정합니다.
/platform:<string> 이 코드를 실행할 수 있는 플랫폼을 x86, Itanium,
x64 또는 anycpu로 제한합니다. 기본값은
anycpu입니다.
- 입력 파일 -
/recurse:<wildcard> 와일드카드 지정에 따라 현재 디렉터리와 하위
디렉터리에 있는 모든 파일을 포함합니다.
/reference:<alias>=<file> 지정한 어셈블리 파일에서 해당 별칭을 사용하여
메타데이터를 참조합니다. (약식: /r)
/reference:<file list> 지정한 어셈블리 파일에서 메타데이터를 참조합니다.
(약식: /r)
/addmodule:<file list> 지정한 모듈을 이 어셈블리에 링크합니다.
- 리소스 -
/win32res:<file> Win32 리소스 파일(.res)을 지정합니다.
/win32icon:<file> 이 아이콘을 사용하여 출력합니다.
/resource:<resinfo> 지정한 리소스를 포함합니다. (약식: /res)
/linkresource:<resinfo> 지정한 리소스를 이 어셈블리에 링크합니다. (약식:
/linkres)
resinfo 형식이 <file>[,<string
name>[,public|private]]인 경우
- 코드 생성 -
/debug[+|-] 디버깅 정보를 내보냅니다.
/debug:{full|pdbonly} 디버깅 형식을 지정합니다. 기본값은 'full'이며,
실행 중인 프로그램에 디버거를 연결합니다.
/optimize[+|-] 최적화를 사용합니다. (약식: /o)
- 오류 및 경고 -
/warnaserror[+|-] 모든 경고를 오류로 보고합니다.
/warnaserror[+|-]:<warn list> 특정 경고를 오류로 보고합니다.
/warn:<n> 경고 수준(0-4)을 설정합니다. (약식: /w)
/nowarn:<warn list> 특정 경고 메시지를 사용하지 않습니다.
- 언어 -
/checked[+|-] 오버플로 검사를 생성합니다.
/unsafe[+|-] 'unsafe' 코드를 사용할 수 있습니다.
/define:<symbol list> 조건부 컴파일 기호를 정의합니다. (약식: /d)
/langversion:<string> 언어 버전 모드를 'ISO-1' 또는 '기본값'으로
지정합니다.
- 기타 -
@<file> 추가 옵션에 대한 지시 파일을 읽습니다.
/help 사용법 메시지를 표시합니다. (약식: /?)
/nologo 컴파일러 저작권 메시지를 표시하지 않습니다.
/noconfig CSC.RSP 파일을 자동으로 포함하지 않습니다.
- 고급 -
/baseaddress:<address> 빌드할 라이브러리의 기준 주소
/bugreport:<file> '버그 보고서' 파일을 만듭니다.
/codepage:<n> 소스 파일을 열 때 사용할 코드 페이지를 지정합니다.
/utf8output 컴파일러 메시지를 UTF-8 인코딩으로 출력합니다.
/main:<type> 진입점을 포함하는 형식을 지정합니다. 다른 모든
가능한 진입점은 무시합니다. (약식: /m)
/fullpaths 컴파일러가 정규화된 경로를 생성합니다.
/filealign:<n> 출력 파일 섹션에 사용되는 맞춤을 지정합니다.
/pdb:<file> 디버그 정보 파일 이름을 지정합니다(기본값:
확장명이 .pdb인 출력 파일 이름).
/nostdlib[+|-] 표준 라이브러리(mscorlib.dll)를 참조하지 않습니다.
/lib:<file list> 참조를 검색할 추가 디렉터리를 지정합니다.
/errorreport:<string> 내부 컴파일러 오류를 처리하는 방법을 지정합니다.
prompt, send, queue 또는 none 중에서 선택할 수
있으며 기본값은 queue입니다.
/moduleassemblyname:<string> 이 모듈이 속할 어셈블리의 이름입니다.
c# dll 파일 만들어 메인클래스에 적용
using System;
public class SumTest
{
public int a = 0;
public int b = 0;
int total = 0;
public void PrintM()
{
Console.WriteLine("{0}",total);
}
public int Sum(int a,int b)
{
total = a+b;
return total;
}
}
csc /t:library /out:SumTest.dll SumTest.cs //SumTest.cs 파일로 SumTest.dll 을 생성
using System;
class SumTestMain
{
public static void Main(String[] args)
{
SumTest st = new SumTest();
Console.WriteLine("두수를 입력하세요");
st.a = Int32.Parse(Console.ReadLine());
st.b = Int32.Parse(Console.ReadLine());
int sum = st.Sum(st.a,st.b);
st.PrintM();
}
}
csc /r:SumTest.dll SumTestMain.cs //SumTest.dll 을 참조하여 컴파일 한다
c# 클래스 파일로 저장
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
namespace classsave
{
class Program
{
static void Main(string[] args)
{
Human h = new Human("dd","111","1123");
BinaryFormatter format = new BinaryFormatter();
try
{
Stream s = File.Open("c:\\human.txt", FileMode.Create, FileAccess.ReadWrite);
format.Serialize(s, h);
s.Close();
s = File.Open("c:\\human.txt", FileMode.Open, FileAccess.Read);
Object o = format.Deserialize(s);
Human r = (Human)o;
r.Print();
}
catch (IOException e)
{
Console.WriteLine(e.Message);
}
catch (SerializationException e)
{
Console.WriteLine(e.Message);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
c# Array list 파일로 저장
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.IO;
namespace arr
{
class Program
{
static void Main(string[] args)
{
ArrayList A = new ArrayList();
A.Add("ddd");
A.Add("eee");
A.Add("aaa");
BinaryFormatter format = new BinaryFormatter();
try
{
Stream s = File.Open("c:\\ArraySave.txt", FileMode.Create, FileAccess.ReadWrite);
format.Serialize(s, A);
s.Close();
s = File.Open("c:\\ArraySave.txt", FileMode.Open, FileAccess.Read);
Object o = format.Deserialize(s);
s.Close();
Print("파일저장후",(ArrayList)o);
}
catch (IOException e)
{
Console.WriteLine("File Write error");
Console.WriteLine(e);
}
catch (SerializationException e)
{
Console.WriteLine("binary 변환 에러");
Console.WriteLine(e.Message);
}
}
public static void Print(String info, ArrayList h)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OracleClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
String strcon = "Data Source=SEUNGWON;User ID=scott;Password=tiger";
String query = "INSERT INTO address VALUES(:id,:name,:addr)";
OracleConnection conn = null;
try
{
conn = new OracleConnection(strcon);
conn.Open();
OracleCommand comm = new OracleCommand(query, conn);
//파라미터의 타입정의
comm.Parameters.Add(":id", OracleType.Number);
comm.Parameters.Add(":name", OracleType.VarChar);
comm.Parameters.Add(":addr", OracleType.VarChar);
//파라미터의 값을 지정
comm.Parameters[":id"].Value = 2;
comm.Parameters[":name"].Value = "승원";
comm.Parameters[":addr"].Value = "대전시";
//쿼리 실행
int count = comm.ExecuteNonQuery();
Console.WriteLine("{0}행이 적용되었습니다.", count);
}
catch (OracleException e)
{
Console.WriteLine(e.Message);
}
finally
{
conn.Close();
SelectMethod();
}
}
static void SelectMethod()
{
OracleConnection conn = null;
String strcon = "Data Source = LES;User ID= scott;Password = tiger";
String query = "SELECT * FROM address";
try
{
conn = new OracleConnection(strcon);
conn.Open();
OracleCommand comm = new OracleCommand(query, conn);
OracleDataReader re = comm.ExecuteReader();
//한생씩 읽어온다.
while (re.Read())
{
//한행의 컬럼수 만큼 읽는다.
Console.WriteLine(re[0].ToString() + "\t"
+ re[1].ToString() + "\t"
+ re[2].ToString() + "\n");
}
}
catch (OracleException e)
{
Console.WriteLine(e.Message);
}
finally
{
conn.Close();
}
}
}
}
오라클 bfile 을 이용하여 디렉토리 내의 파일 참조
// 오라클 bfile 을 이용하여 디렉토리 내의 파일 참조
using System;
using System.IO;
using System.Data;
using System.Data.OracleClient;
public class Sample
{
public static void Main(string[] args)
{
OracleConnection connection = new OracleConnection(
"Data Source=won;User ID=scott;Password=tiger");
//OracleConnection connection = new OracleConnection(
// "Data Source=won;User ID=scott;Password=tiger;Integrated Security=yes;");
connection.Open();
OracleCommand command = connection.CreateCommand();
command.CommandText =
"CREATE or REPLACE DIRECTORY MyDir as 'c:\\img'"; //오라클상에 가상에 디렉토리 생성시
command.ExecuteNonQuery(); //대문자와 소문자의 조합으로 디렉토리명을 써도
command.CommandText =
"DROP TABLE test_bfile";
try
{
command.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
command.CommandText =
"CREATE TABLE test_bfile(id number, memo BFILE)";
command.ExecuteNonQuery();
command.CommandText =
"INSERT INTO test_bfile values (2, BFILENAME('MYDIR','b.jpg'))";//불러올때는 대문자로 불러와야한다
command.ExecuteNonQuery(); //소문자로 불러와서 하루 고생....ㅡ.,ㅡ;
command.CommandText = "SELECT * FROM test_bfile";
byte[] buffer = new byte[100];
OracleDataReader reader = command.ExecuteReader();
using (reader)
{
if (reader.Read())
{
OracleBFile bFile = reader.GetOracleBFile(1);
using (bFile)
{
Console.WriteLine(bFile.FileExists.ToString());
bFile.Seek(0, SeekOrigin.Begin);
bFile.Read(buffer, 0, 100);
}
}
}
connection.Close();
}
}
VC.NET 2005 로 컴파일된 프로그램 배포시 주의할 사항
비단 VC.NET 2005로 컴파일 된 프로그램뿐만 아니라 다른 버전의 컴파일러로 컴파일된 프로그램은 해당 버전의 컴파일러의 필수 라이브러리를 배포해야 합니다.
그러나 VC 6.0이나 VC.NET 2003등은 워낙 다른 프로그램들(VC6.0이나 VC.NET 2003으로 컴파일된)이 이미 윈도우즈에 필수 DLL들을 인스톨해 놓은 경우가 많아 따로 배포하지 않아도 문제되는 경우가 거의 없더군요.
근데, VC.NET 2005의 경우는 마이크로소프트가 배포하는 방식을 좀 다르게 한 것 같습니다.
참조
http://serious-code.net/moin.cgi/RedistributingVisualCppRunTimeLibrary
http://msdn2.microsoft.com/ko-kr/library/zebw5zk9(VS.80).aspx
Side-by-side Assembly 라는 방식이라는 데, 암튼 좀 귀찮아 졌습니다.
그래서, 기존에 windows/system32에 dll이 들어가던 것이 windows/winSxS에 들어가게 되었고
기존에 실행화일과 dll이 같이 있으면 해결되었던 것이 이제는 그냥은 통하지 않게 되었다고 합니다. 좀 뭔가 더 해주어야 한답니다.
해결방법은 위의 링크에서도 이야기합니다만 다음과 같습니다.
1) VC.NET 2005 재배포용 패키지를 설치한다.
아래 링크에서 다운받거나
Visual C++ 2005 Redistributable Package (x86)
Visual C++ 2005 Redistributable Package (x64)
Visual C++ 2005 Redistributable Package (ia64)
Visual C++ 2005 SP1 Redistributable Package (x86)
Visual C++ 2005 SP1 Redistributable Package (x64)
Visual C++ 2005 SP1 Redistributable Package (ia64)
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\vcredist_x86
에 있습니다.
2) 필요한 것을 같이 설치한다
릴리즈 버전은 C:\Program Files\Microsoft Visual Studio 8\VC\redist\x86
디버그 버전은 C:\Program Files\Microsoft Visual Studio 8\VC\redist\Debug_NonRedist
에서..
사용하는 dll과 함께 Microsoft.VC80.*.manifest 도 포함해서 실행파일과 같은 폴더에 넣어주어야 합니다.
그럼 필요한게 뭔지 어떻게 아느냐..라고 물어보시는 분들을 위해 다음과 같은 프로그램이 있다는 것을 상기시켜 드립니다.
http://www.dependencywalker.com
VC 2005를 깔았다면
C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin" 폴더에 depends.exe라는 이름으로 설치되어 있습니다.
위의 프로그램은 해당 프로그램화일이 어떤 dll을 참조하는 지 알려줍니다.