[컴][윈도우즈] Active X 강좌





Visual Studio 2012 에서 ActiveX 만들기

ActiveX Project 만들기







Code


  1. using System.Runtime.InteropServices; 
  2. ProgId,
  3. ClassInterface
  4. Guid
  5. ComVisible : class, method, assembly 3곳에 해줘야 한다.

을 아래 처럼 해주자.



// MyActiveX.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.InteropServices; namespace MyActiveX { [ProgId("MyActiveX.FileTest")] [ClassInterface(ClassInterfaceType.AutoDual)] [Guid("0A100052-66B0-45F8-9D39-96FE43B8B06F")] [ComVisible(true)] public class FileTest { [ComVisible(true)]  public void saveFile(String path, String b64Str) { byte[] bytes = Convert.FromBase64String(b64Str); File.WriteAllBytes(path, bytes); }
} }




HTML page

// AssemblyInfo.cs
<!DOCTYPE>
<html>
   <head>
          <title>MyActiveX webpage</title>
   </head>
   <body>
       <OBJECT id="myActiveX" classid="clsid:0A100052-66B0-45F8-9D39-96FE43B8B06F" codebase="MyActiveX.cab"></OBJECT>  
 
        <script type="text/javascript">
            try {
                var obj = document.myActiveX;
                if (obj) {
                    alert(obj.saveFile("f:\\a.txt", "fjdksfjsdl"));
                } else {
                    alert("Object is not created!");
                }
            } catch (ex) {
                alert("Some error happens, error message is: " + ex.Description);
            }
       
        </script>
   </body>
</html>


ActiveX 등록

local 에서 위의 html 을 통해 ActiveX를 test 해 보려면 ActiveX 를 등록해야 한다. 참고로 아래 path 의 버전을 잘 선택해야 한다. 다른 버전의 regasm 을 선택하게 되면 아래와 같은 error message 가 뜬다.

REGASM.exe error RA0000: Failed to load '...\filename.dll' because it is not a valid .net assembly

ActiveX 를 등록할 때는 아래처럼 하면 된다.(register)
C:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm /codebase <full path of dll file>

등록해지는 아래처럼 하면 된다.(unregister)
C:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm /u <full path of dll file>





Build 를 하면 위 그림처럼 .dll 이 생성된다. 이 dll 을 regasm 을 통해 register 하면 된다.


실행

이제 html page 를 IE 에서 열면 된다.



Download Source

위에서 얘기한 source code 는 아래에서 다운로드 할 수 있다.


Certificate 만들기


c:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\x64>makecert -sv myNew.pvk -ss myNewStore myNew.cer

를 실행하면 아래 2개의 file 을 생성 해 준다.

  1. myNew.pvk, 
  2. myNew.cer




Visual Studio 2013 에는 Setup Project 항목이 없다. 아래 항목을 설치해야 한다.
Microsoft Visual Studio Installer Projects extension


makecert download
Windows SDK download 를 download 받으면 makecert 가 있다.
http://www.microsoft.com/download/en/details.aspx?id=3138


개발자(開發者) a developer :: OCX 인증서 만들기
코드사인 인증 과정 및 적용 방법 - HanbiroSSL



괜찮은 강좌가 있어 일다 링크를 걸어놓는다. 일단 실제로 따라 해 보는 작업은 다음으로 미룬다.



http://www.soft005.com/zbxe/1131



How to develop and deploy ActiveX control in C# - AsiaTech: Microsoft APGC Internet Developer Support Team - Site Home - MSDN Blogs, 5 Dec 2011 12:24 AM

C# 에서 ActiveX Control 간단하게 만들어보기::녹두장군 - Android, java,, iPhone, C++ 개발, C#, 2009/04/07 21:19

댓글 없음:

댓글 쓰기