C# String.format 사용법

Programming/C,CPP,CS 2021. 3. 17. 14:15 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

String Format for Int [C#]

Integer numbers can be formatted in .NET in many ways. You can use static method String.Format or instance method int.ToString. Following examples show how to align numbers (with spaces or zeroes), how to format negative numbers or how to do custom formatting like phone numbers.

Add zeroes before number

To add zeroes before a number, use colon separator „:“ and write as many zeroes as you want.

[C#]
String.Format("{0:00000}", 15); // "00015" String.Format("{0:00000}", -15); // "-00015"

Align number to the right or left

To align number to the right, use comma „,“ followed by a number of characters. This alignment option must be before the colon separator.

[C#]
String.Format("{0,5}", 15); // " 15" String.Format("{0,-5}", 15); // "15 " String.Format("{0,5:000}", 15); // " 015" String.Format("{0,-5:000}", 15); // "015 "

Different formatting for negative numbers and zero

You can have special format for negative numbers and zero. Use semicolon separator „;“ to separate formatting to two or three sections. The second section is format for negative numbers, the third section is for zero.

[C#]
String.Format("{0:#;minus #}", 15); // "15" String.Format("{0:#;minus #}", -15); // "minus 15" String.Format("{0:#;minus #;zero}", 0); // "zero"

Custom number formatting (e.g. phone number)

Numbers can be formatted also to any custom format, e.g. like phone numbers or serial numbers.

[C#]
String.Format("{0:+### ### ### ###}", 447900123456); // "+447 900 123 456" String.Format("{0:##-####-####}", 8958712551); // "89-5871-2551"

 

 

출처 : www.csharp-examples.net/string-format-int/

 

String Format for Int [C#]

String Format for Int [C#] Integer numbers can be formatted in .NET in many ways. You can use static method String.Format or instance method int.ToString. Following examples show how to align numbers (with spaces or zeroes), how to format negative numbers

www.csharp-examples.net

 

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

 

 

 

ConfigurationSettings.AppSettings

 

->

 

System.Configuration.ConfigurationManager.AppSettings

Audio Wave Form Renderer

Programming/C# 2018. 10. 24. 15:13 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Audio Wave Form Renderer




Test Harness App


Test Harness UI


Example Waveforms


Basic solid colour waveform Basic solid color

Gradient vertical bars (old SoundCloud style) Gradient vertical bars

Blocks (SoundCloud style) Blocks

Orange Blocks

Transparent Backgrounds Transparent Background

Transparent Background

You can check out all the source code on GitHub





https://markheath.net/post/naudio-png-waveform-rendering

C# Panel DirectShow Video ScrollBar

Programming/C# 2018. 10. 22. 13:40 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

C# Panel DirectShow Video ScrollBar


        public System.Windows.Forms.Panel pnlVideo;



        public QuartzTypeLib.FilgraphManager m_objFilterGraph = null;

        public QuartzTypeLib.IBasicAudio m_objBasicAudio = null;

        public QuartzTypeLib.IVideoWindow m_objVideoWindow = null;

        public QuartzTypeLib.IMediaEvent m_objMediaEvent = null;

        public QuartzTypeLib.IMediaEventEx m_objMediaEventEx = null;

        public QuartzTypeLib.IMediaPosition m_objMediaPosition = null;

        public QuartzTypeLib.IMediaControl m_objMediaControl = null;





         m_objVideoWindow.SetWindowPosition(pnlVideo.ClientRectangle.Left,

                        pnlVideo.ClientRectangle.Top,

                        pnlVideo.ClientRectangle.Height * (int)videoResolutionRate,

                        pnlVideo.ClientRectangle.Height);



m_objVideoWindow shows the video at original rate



1. ScrollBar Padding 20px



                    m_objVideoWindow.SetWindowPosition(pnlVideo.ClientRectangle.Left,

                        pnlVideo.ClientRectangle.Top,

                        (pnlVideo.ClientRectangle.Height - 20) * (int)videoResolutionRate,

                        pnlVideo.ClientRectangle.Height - 20);


2. Size and Scroll Bar Enable



                pnlVideo.HorizontalScroll.Visible = true;

                pnlVideo.AutoScroll = true;

                pnlVideo.MaximumSize = new Size(this.ClientSize.Width, this.ClientSize.Height - 80);

                pnlVideo.AutoScrollMinSize = new Size((int)UserControl1.videoResolutionRate * (this.ClientSize.Height - 80), this.ClientSize.Height - 80);

                pnlVideo.ClientSize = new Size(this.ClientSize.Width, this.ClientSize.Height - 80);

                pnlVideo.Size = new Size(this.ClientSize.Width, this.ClientSize.Height - 80);




JNA Error

Programming/JAVA,JSP 2018. 2. 27. 15:48 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

JNA Error













int hr = m_pObjectKey.CreateInstance(__uuidof(KeyObject));


해당 구문에서


CreateInstance 의 리턴 값이



%x : 80040154


%d : -2147221164


형태로 계속 리턴되는 경우








80040154 오류
















System.Runtime.InteropServices.COMExcetption : 80040154 오류로 인해 CLSID가 {100202C1-E260-11CF-AE68-00AA004A34D5}인 구성 요소의 COM 클래스 팩터리를 검색하지 못했습니다.


https://social.msdn.microsoft.com/Forums/vstudio/ko-KR/03d5a6bd-e256-492a-a72b-f011b971834e/80040154-?forum=visualcsharpko
















쉽게 말하면 해당 라이브러리의 DLL 파일의 경로를 찾을수 없어서


객체를 만들 수 없다는 이야기이다.



















1) regasm, regsrv 를 이용하여 재등록을 시도해 보고,







그래도 안된다면









2) regasm 의 경우 /codebase 옵션을 사용 해 보라






























C# 에서 C++ DLL 불러서 쓰기 #4

Programming/C# 2018. 2. 14. 12:30 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

C# 에서 C++ DLL 불러서 쓰기 #4



4. 멤버 함수 가져오기





C++


#ifdef BOX_EXPORTS

#define BOX_API __declspec(dllexport)

#else

#define BOX_API __declspec(dllimport)

#endif






Class BOX_API Box{

public:

Box();

int setInt(int a);

void setString(char* str);

}






int setInt(int a);

void setString(char* str);




이 멤버 함수들을 가져와서 사용하고 싶다.



참고 : http://tansanc.tistory.com/526?category=772232 [TanSanC]





아래와 같이 사용하고 싶지만


불가능하다



namespace BoxConsoleApplication

{

    class Program

    {


        [DllImport("Box.dll", CallingConvention = CallingConvention.Cdecl)]

        static public extern IntPtr CreateCBox();

        

        

        [DllImport("Box.dll", CallingConvention = CallingConvention.Cdecl)]

        static public extern void DisposeCBox(IntPtr pTestClassObject);


        unsafe static void Main(string[] args)

        {


            IntPtr pCBoxClass = CreateCBox(); ;



            pCBoxClass.setInt(3);

            pCBoxClass.setString("HelloWorld");




            DisposeCBox(pCBoxClass );            




            pCBoxClass = IntPtr.Zero; 


        }

    }

}





            pCBoxClass.setInt(3);

            pCBoxClass.setString("HelloWorld");




클래스 내부 멤버 변수라 바로 가져올 수는 없다.






사용 할 수 있는 방법은


클래스 생성시와 같이


extern 으로 접근가능 하도록 만들어 주어야 한다.











기본 형태





C++






.h


extern "C" BOX_API int setInt(CBox* pObject, int a);






.cpp


extern "C" BOX_API int setInt(CBox* pObject, int a)

{

if (pObject != NULL)

{

pObject->setInt(a);

}

return -1;

}





이렇게 C++ DLL 내부에서 


클래스 객체에 접근하여


객체의 멤버 함수를 호출하여 준다.











void setString(char* str);



는 다음 글에서....






336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

C# 에서 C++ DLL 불러서 쓰기


도움되는 링크들





http://freeprog.tistory.com/220




https://docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/keywords/unsafe



http://heroeskdw.tistory.com/entry/C-MFC-DLL%EC%9D%84-C%EC%97%90%EC%84%9C-%EB%A1%9C%EB%94%A9%ED%95%98%EA%B8%B0


https://www.codeproject.com/Articles/18032/How-to-Marshal-a-C-Class




http://www.sysnet.pe.kr/2/0/11132







http://www.sysnet.pe.kr/2/0/11111







https://msdn.microsoft.com/ko-kr/library/62688esh.aspx












https://social.msdn.microsoft.com/Forums/en-US/b85fc9dd-acc5-42dc-a28e-b70953bf1170/unhandled-exception-systemruntimeinteropservicessehexception-additional-information-external?forum=vcgeneral

















https://msdn.microsoft.com/ko-kr/library/system.io.filestream.read(v=vs.110).aspx







http://storycompiler.tistory.com/214






























C# 에서 C++ DLL 불러서 쓰기 #2

Programming/C# 2018. 2. 13. 15:55 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

C# 에서 C++ DLL 불러서 쓰기 #2



2. DLL 참조하기




C++ DLL 을 C# 에서 사용하려면


일단 참조를 하여야 한다.




참조를 하는 방법은




Visual Studio 2013 버전에서는






[솔루션 탐색기] -> [솔루션] 하위 -> [프로젝트] 하위 -> [참조] -> 우클릭 -> [참조 추가] -> 우측 하단 [찾아보기(B)...] -> 원하는 DLL 찾아서 선택



선택을 하면 [참조] 하단에 참조된 DLL 이 보이게 된다.










여기서.......



이 글은


참조된 DLL 을 더블클릭하여 [개체 브라우저]로 보았을때도


하위 멤버들이 보이지 않는


C++ DLL 일 경우 해결하는 방법들을


순서...에 상관없이


메모해 두려고 한다.









Get Audio Device List

Programming/C# 2017. 12. 27. 11:02 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Get Audio Device List




using System.Management;


        public void getAudioDevice()
        {
            ManagementObjectSearcher objSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_SoundDevice");

            ManagementObjectCollection objCollection = objSearcher.Get();

            foreach (ManagementObject obj in objCollection)
            {
                String str = "";
                foreach (PropertyData property in obj.Properties)
                {
                    str += String.Format("{0}:{1}\n", property.Name, property.Value);
                }
                Console.Out.WriteLine(str + "\n\n");
            }
        }





참조 : https://stackoverflow.com/questions/1525320/how-to-enumerate-audio-out-devices-in-c-sharp

ATL,CPP,C# dll 배포

Programming/C,CPP,CS 2016. 5. 27. 10:56 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

ATL,CPP,C# dll 배포


dll 배포 관련 질문이 올라와서 저도 다시 한번 정리 할겸 올려 봅니다.







DLL reg 등록 방법


1. Visual Studio 기반으로 dll 을 만들어서


 디버그 옵션을 조절하여 


 html 이나 특정 app 을 실행하는 형태로 프로젝트 설정을 하였다면


 자동으로 Visual Studio 가 dll 을 해당 컴퓨터에 등록하게 됩니다.



배포를 하려면 배포할 컴퓨터에 일일이 Visual Studio 를 설치 할 수 없으므로


아래의 방법을 활용 합니다.




2.  regsvr32.exe 활용


regsvr32.exe 는 


C:\Windows\System32 경로에 존재합니다.



참고 64비트 버전의 Windows 운영 체제에는 다음과 같은 두 가지 버전의 Regsv32.exe 파일이 있습니다.

  • 64비트 버전은 %systemroot%\System32\regsvr32.exe입니다.
  • 32비트 버전은 %systemroot%\SysWoW64\regsvr32.exe입니다.



regsvr32.exe 사용중 오류는 msdn 문제 해결 방법이 제일 무난한것 같습니다.



https://support.microsoft.com/ko-kr/kb/249873






사용방법은


관리자 권한으로 cmd 를 연 후


등록 : regsvr32 xxxx.dll

등록해제 : regsvr32 xxxx.dll /u


인데


regsvr32 를 찾지 못할경우 system 경로로 이동하여 실행하거나


regsvr32 만 필요한 경로에 복사하여 사용하여도 됩니다.



regsvr32 는 C, CPP, ATL dll 을 올리기 위한 용도이고


같은 방법으로 regasm 을 활용하면 C# dll 을 올릴수 있습니다.


3. Install Uitility


인스톨 쉴드, 인스톨 팩토리등 인스톨 관련 유틸리티를 활용하여


setup.exe 파일을 만들경우 dll 을 등록하는 메뉴도 있기에 설치하며 등록 할 수도 있습니다.









'Programming > C,CPP,CS' 카테고리의 다른 글

Log4cxx Tutorial  (0) 2016.06.28
Log Librarys  (0) 2016.06.27
Free Dia Diagram Editor  (0) 2016.04.28
Windows 버전별 기본 포함 .NET Framework  (0) 2016.04.14
c# dll ClassLibrary 에서 MessageBox.Show(text,title);  (0) 2016.04.06