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

Activex Event use in JavaScript

Programming/JAVA,JSP 2016. 4. 14. 11:26 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

If you want to use Activex Event in JavaScript 



You commonly use JavaScript Event listener


1.  

<script type="text/javascript" for="ActiveXControl" event="LogOn()"></script>


2.   

var ctrl = document.getElementById("ActiveXControl");

ctrl.attachEvent('LogOn', ActiveXControl_LogOn);


function ActiveXControl_LogOn() {

        

}


3.   

var ctrl = document.getElementById("ActiveXControl");

ctrl.addEventListener('LogOn', ActiveXControl_LogOn, false);



function ActiveXControl_LogOn() {

        

}



This way can't use correctly alert method. you can see alert only in debug mode.


I think this situation is have a thread problem.



I suggest other way to use eventhandling


By use timer, This problem can be solved.



// make eventArray 

var eventArray = [];


// if event occured, when you add information to eventArray

eventArray.push(information);


// make Timer

setInterval(function () {

if (eventArray.length > 0) {

var information= eventArray.pop();

alert("information: " + information);

}

}, 100);



This method can be use alert method







'Programming > JAVA,JSP' 카테고리의 다른 글

Get client IP, Location, Address using just JavaScript?  (0) 2016.04.26
Web Browser 점유율 통계  (0) 2016.04.18
JDBC Realm  (1) 2016.03.09
ImageFrameTest  (0) 2016.02.05
Java 채팅 프로그램  (0) 2016.02.04
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

c# dll ClassLibrary 에서 MessageBox.Show(text,title);


c# dll 을 만들다가


c#의 MessageBox를 사용하고 싶을때가 있다.



그럴때는


바로


using System.Windows.Forms;


하면 안 되고




System.Windows.Forms 을 참조 해주어야한다.




VS2013


[프로젝트이름]우클릭 -> [추가] -> [참조] -> [어셈블리] -> [프레임워크] -> [System.Windows.Forms] 를 체크해주면 해당 라이브러리를 자동으로 참조해준다.



그 다음 



using System.Windows.Forms;



를 쓰고


MessageBox.Show("mySocket is Null", "strTitle");


MessageBox 를 사용하면 된다.



C# Class Library use in script

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

C# Class Library use in script




C# Class Library



namespace ClassLibrary2

{

    // Interface declaration.

    public interface ICalculator

    {

        int Add(int Number1, int Number2);

    };

    [ProgId("Test.SimpleCalc")]

    public class SimpleCalc : ICalculator

    {

        public int Add(int Number1, int Number2)

        {

            return Number1 + Number2;

        }

    }

}





이런 형태 일때

JavaScript 에서 부르는 방법



JavaScript 에서는 주로 


요런 형태로 DLL 을 로드한다.


<object name="Class1" id="Class1" classid="CLSID:*-*-*-*" width="0" height="0"></object>


일단 임의의 CLSID 를 만들어낸다


Visual Studio [도구] [GUID 만들기] 로 GUID 를 하나 만들어 낸다.



{3963CDD9-1079-463A-BCDA-0182D296C9B6}


namespace ClassLibrary2

{

    // Interface declaration.

    public interface ICalculator

    {

        int Add(int Number1, int Number2);

    };

    [ProgId("Test.SimpleCalc")]

    [Guid("3963CDD9-1079-463A-BCDA-0182D296C9B6")]

    public class SimpleCalc : ICalculator

    {

        public int Add(int Number1, int Number2)

        {

            return Number1 + Number2;

        }

    }

}



객체에 GUID 를 설정한다.




그다음 regasm 으로 등록한다.

등록할때 /codebase 옵션을 붙여야한다.

codebase 옵션을 붙이려면 어셈블리 서명이 필요하다.


어셈블리 서명은

Properties

[서명]

[어셈블리 서명] 에서 

새로만들기로 편한대로 만들면된다

키 파일 이름, 암호 없음







그다음 html 에서

<object name="Class1" id="Class1" classid="CLSID:3963CDD9-1079-463A-BCDA-0182D296C9B6" width="0" height="0"></object>

    <script>
        function TestAdd() {
            var ctrl = document.getElementById("Class1");
            ctrl.Add(13,4);
        }
    </script>





실행하면 잘 된다.





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

C# Class Library use in java (클래스 라이브러리)



Java 에서 C# 클래스 라이브러리를 불러오기




C# 클래스 라이브러리가


namespace ClassLibrary2

{

    // Interface declaration.

    public interface ICalculator

    {

        int Add(int Number1, int Number2);

    };

    public class SimpleCalc : ICalculator

    {

        public int Add(int Number1, int Number2)

        {

            return Number1 + Number2;

        }

    }

}



그리고

잊지 말아야할 설정들



[assembly: ComVisible(true)]


COM Interop 등록





JACOB 라이브러리를 활용하여 C# DLL 을 불러와 보겠다.



http://danadler.com/jacob/


에 들어가서 기본 라이브러리를 추가한다.




jacob.jar 를 Java Build Path 에 추가한다.


ActiveXComponent xl = new ActiveXComponent("Test.SimpleCalc");


try {

   System.out.println(Dispatch.call(xl, "Add", new Variant(1), new Variant(2)));

} catch (Exception e) {

e.printStackTrace();

}


JACOB 라이브러리는 기본적으로는 ProgID 를 통해 DLL 파일을 불러온다.




위의 C# 클래스 라이브러리는 ProgID 가 없다.


namespace ClassLibrary2

{

    // Interface declaration.

    public interface ICalculator

    {

        int Add(int Number1, int Number2);

    };

    [ProgId("Test.SimpleCalc")]

    public class SimpleCalc : ICalculator

    {

        public int Add(int Number1, int Number2)

        {

            return Number1 + Number2;

        }

    }

}



ProgID 를 추가하여 준다.




그 다음 해당 파일을 regasm 으로 등록한다.



그런 다음 Java 를 실행해 보면


Add 가 정상적으로 작동한다.


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

C# Class Library


VS2013


새 프로젝트 -> Visual C# -> 클래스 라이브러리 -> 프로젝트 이름(Library 이름이 된다, 예제에서는 ClassLibrary2 이다.) -> 


자동으로 Class1.cs 파일이 만들어진다.


이 Class1.cs 가 DLL 에서 불러쓸 객체의 이름이 된다.



참고 : https://support.microsoft.com/en-us/kb/828736




Class1.cs 를 우클릭하여 이름바꾸기 원하는 객체 이름으로 바꾼다.




예제에서는 SimpleCalc 로 진행한다.



----------------------------------------------------------------


SimpleCalc.cs


----------------------------------------------------------------


namespace ClassLibrary2

{

    public class SimpleCalc

    {

    }

}


----------------------------------------------------------------



interface 를 추가 구현한다.

// Interface declaration.
public interface ICalculator
{
    int Add(int Number1, int Number2);
};



----------------------------------------------------------------


SimpleCalc.cs


----------------------------------------------------------------


namespace ClassLibrary2

{

    // Interface declaration.

    public interface ICalculator

    {

        int Add(int Number1, int Number2);

    };

    public class SimpleCalc

    {

    }

}



----------------------------------------------------------------


interface를 상속 받고

interface 로 부터 상속받은 메서드를 구현한다.


// Interface implementation.
public class ManagedClass:ICalculator
{
    public int Add(int Number1,int Number2)
        {
            return Number1+Number2;
        }
}




----------------------------------------------------------------


SimpleCalc.cs


----------------------------------------------------------------


namespace ClassLibrary2

{

    // Interface declaration.

    public interface ICalculator

    {

        int Add(int Number1, int Number2);

    };

    public class SimpleCalc : ICalculator

    {

        public int Add(int Number1, int Number2)

        {

            return Number1 + Number2;

        }

    }

}




----------------------------------------------------------------


이제


Properties 를 열어서


AssemblyInfo.cs 를 열어보면


[assembly: ComVisible(false)] 를 찾아서



[assembly: ComVisible(true)]


로 변경한다.



[assembly: ComVisible(true)] 로 바꾸어야 ActiveX 로 사용이 가능하다.





이제 빌드하면


bin/Debug 폴더에


ClassLibrary2.dll 파일이 만들어진다.



궁극적으로 배포를 목적으로 하므로


Release 모드로 바꾸어준다.




빌드를 하게 되면


ClassLibrary2.dll 파일이 만들어진다.



하지만 클래스 내부의 구조가 보이게 하려면


tlb 파일이 필요하다


이 파일은


ClassLibrary2 프로젝트이름을 더블클릭하면 뜨는 속성 창에서


[빌드]


COM Interop 등록 을 체크해준다.


그러면 이제부터 빌드를 하면 tlb 파일도 같이 만들어진다.





tlb 파일과 dll 파일을 C# DLL 을 사용할 프로젝트의 폴더로 복사한다.




예제에서는 MFC 에서 해당 DLL 파일을 불러서 사용해보겠다.



사용할 cpp 파일에서



#import "ClassLibrary2.tlb" raw_interfaces_only

using namespace ClassLibrary2;


를 선언한다.





그 후 사용을 원하는 함수에서




HRESULT hr = CoInitialize(NULL);


// Create the interface pointer.

ICalculatorPtr pICalc(__uuidof(SimpleCalc));


long lResult = 0;


// Call the Add method.

pICalc->Add(5, 10, &lResult);


SetDlgItemInt(IDC_STERM, (int)lResult);


// Uninitialize COM.

CoUninitialize();





이렇게 사용을 하면 된다.



ICalculatorPtr 은 Interface 로 만든  ICalculator 의 스마트포인터이다


ICalculator* 와 같다.





pICalc-> 을 통해 내부에 있는 속성과 메서드에 접근이 가능하다.








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

ATL 프로젝트로 만든 DLL 을 MFC 프로젝트에서 사용하기



ATL 프로젝트로 만든 DLL 이름을 ComServer.DLL 이라고 가정하겠습니다.


ComServer 대신에 자신이 만든 DLL 을 쓰면 됩니다.



사용하고자하는 ComServer.dll 파일을 프로젝트 디렉토리에 복사한다.


stdafx.h 파일에 


#import "ComServer.dll" no_namespace named_guids


넣고


빌드를 하게 되면


빌드 폴더에 ComServer.tlh , ComServer.tli 가 생성된것을 확인 할 수 있습니다.



ComServer.tlh 파일을 열어 둡니다.




그다음 Dlg 의 OnInitDialog() 같은 곳에 아래의 코드를 삽입한다.


ComTest 는 객체 이름입니다.


try{


UpdateData();


HRESULT rc;


IComTestPtr pComTest; //IComTest *pComTest 도 가능 !!! (IComTest 의 스마트포인터)


rc = CoCreateInstance(CLSID_ComTest, NULL, CLSCTX_INPROC_SERVER, DIID_IComTest, (void**)&pComTest);


if (FAILED(rc)){


MessageBox("Failure in call to CoCreateInstance");


return;


}


pComTest->(사용하고 싶은 속성이나 메서드);


}


catch (_com_error &e){


CString strBuffer;


strBuffer.Format("Code = %08lXnCode meaning = %snSource = %snDescription = %sn",

e.Error(), e.ErrorMessage(), e.Source(), e.Description());

AfxMessageBox(strBuffer);

}






'Programming > COM,ATL' 카테고리의 다른 글

MFC 프로젝트에서 ATL 연동하기  (2) 2016.03.29
ATL/COM 강좌  (0) 2016.03.25
ATL 프로젝트에서 hWnd사용하기 #2  (0) 2016.03.25
ATL 프로젝트에서 hWnd사용하기  (0) 2016.03.25
ocx, dll 라이브러리 등록  (0) 2016.03.15

ocx, dll 라이브러리 등록

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

ocx, dll 라이브러리 등록


등록할 라이브러리를 32비트 운영체제의 경우 system32,


64비트 운영체제의 경우 syswow64에 넣어준다음


관리자권한 cmd.exe 에서


regsvr32 등록할라이브러리