수안이의 컴퓨터 연구실

  • Mainpage
  • About Me
  • Tags
  • Metapage
  • Notice
  • Location
  • Keywords
  • Guestbook
  • Admin
  • Write an Article
  • Total | 1620899
  • Today | 279
  • Yesterday | 482

Programming/MFC2006/11/29 02:40

MS Script Control in MFC

 MSVB Script Constrol 객체를 만들기


  먼저 프로젝트에서 Project/Add Project/Controls and Component에서

 Registered ActiveX Controls 부분에서 Script Control을 얻어온다.


1. ActiveX 폼 붙이기 식


 다이얼로그 폼에다가 MSScript를 하나 붙인다. 그리고 Property에서 Language 를 VBScript로 준다.

그후 클래스 위자드에서 MSScript를 이용해 m_scptBro라는 맴버자료를 만든후 버튼을 누르면 다음 코드를 실행하게 한다.

#include <comdef.h>
#include <afxpriv.h>
#include "ScriptError.h"

를 한 후

   m_scptBro.AddCode( "                            \r\n\
       Function fnMethod ( i )         \r\n\
       a = cstr(i+1)               \r\n\
       a = a + \"날짜도\"+ cstr(date)      \r\n\
           fnMethod = a                \r\n\
       End Function                            \
       " );
   _variant_t vsRet = m_scptBro.Eval("fnMethod(100)");
   _bstr_t bsRet(vsRet);
  
  
   //char* pszRet = bsRet.Copy();
   MessageBox( (LPCTSTR)bsRet );

2. 코드로 스크립트 객체 생성

   CScriptControl  sc;
  
   if( sc.Create("aa", WS_CHILD, CRect(0,0,0,0), this, 6501 ) )
   {
       sc.SetLanguage(NULL);
       sc.SetLanguage("VBScript");
       MessageBox( sc.GetLanguage() );
      
       sc.AddCode( "                              \r\n\
           Functio 먼저 프로젝트에서 n fnMethod ( i )                          \r\n\
           a = cstr(i+1)                               \r\n\
           a = a + \"날짜도\"+ cstr(date)                              \r\n\
               fnMethod = a                              \r\n\
           End Function                                  \
           " );

       //_variant_t vsRet = m_scptBro.Eval("(\"xx\" =  \"yy\")");
       _variant_t vsRet = sc.Eval("fnMethod(100)");
       _bstr_t bsRet(vsRet);
      
      
       //char* pszRet = bsRet.Copy();
       MessageBox( (LPCTSTR)bsRet );
   }

3. ocx 수준 COM 모듈로 불러 쓰기

// 다음은 MSVBScript Control 엑티브 엑스를 추가하지 않고 하는 방법이다.
// ocx위치를 탐색기로 찾아내서 import 패스를 넣으면 된다.

#import "C:\Program Files\Microsoft Script Control\msscript.ocx"
또는
#import "C:\\winnt\\system32\\msscript.ocx"
using namespace MSScriptControl;
한후
IScriptControlPtr spScriptCtl(__uuidof(ScriptControl));


하면 된다. 즉 아래처럼 

  try  // Make sure exception handling is turned on.
  {
     _bstr_t bstrLanguage(L"VBScript");
     _bstr_t bstrCode(L"MsgBox \"Hello World\"");

     // Create the Script Control, initialize Language, and
     // add code for processing.
     IScriptControlPtr spScriptCtl(__uuidof(ScriptControl));
     spScriptCtl->put_Language(bstrLanguage);
     spScriptCtl->AddCode(bstrCode);
  }
  catch(_com_error e)
  {
     TRACE(_T("Error (%08x) in %s: %s\n"), e.Error(),
                          e.Source(), e.Description());
  }


Run으로 실행한후 결과 받기

       IScriptControlPtr m_pScript; 라면 ...
       m_pScript.CreateInstance(__uuidof(ScriptControl));
       m_pScript.AddCode(코드);
      
                 :    
   SAFEARRAY* sa;    // 메소드의 인자가 들어갈 배열
   long ix[1];       // 1차원 배열
   _bstr_t bsParam(pszPram);
   _variant_t vsParam(bsParam);  // _variant_t에 넣음
       // 1칸짜리 배열을 만든다.
   sa = SafeArrayCreateVector(VT_VARIANT, 0, 1);
   ix[0] = 0;        // 첫째 인자
       // 배열에 값을 넣는다.
   SafeArrayPutElement(sa, ix, &vsMessage);

       _variant_t vsOut = m_pScript->Run(_bstr_t(L"Main"), &sa);
       TRACE("%s",(LPCTSTR)(_bstr_t)vsOut);

   코드는
   Function Main(sIn)
       sIn ="스크립트"+cstr(2+4)
   End Function

   그러면 스크립트6 라고 출력된다.

트러블 슈팅


1. MFC시 CScriptControl 객체를 만들어서 할경우 언어를 설정하지 않았다고 나는 경우

       sc.SetLanguage(NULL);
       sc.SetLanguage("VBScript");

이렇게 먼저 설정을 NULL로 한다음 하면 된다.


정리

MS VB Script Control을 MFC 에서 사용하는 방법에 대해서 간략하게 알아보았습니다.

"MFC" 카테고리의 다른 글
  • 특정 컨트롤에서 한글을 입력받고 싶지 않을 때 (0)2006/12/01
  • 연결 프로그램 찾기 다이얼로그 띄우기 (0)2006/12/01
  • MS Script Control in MFC (0)2006/11/29
  • 바탕화면, 즐겨찾기, 내 문서 등의 패스 얻기 (0)2006/11/25
  • Doc/View 구조 없는 SDI에서 스플릿 윈도우 만들기 (0)2006/11/25
2006/11/29 02:40 2006/11/29 02:40
Posted by webdizen
No Trackback No Comment

Trackback URL : http://www.webdizen.net/blog/trackback/2452

Leave your greetings.

[로그인][오픈아이디란?]

«Prev  1 ... 776 777 778 779 780 781 782 783 784 ... 2998  Next»

RSS HanRSS
Blog Image
webdizen
이 곳은 컴퓨터에 대해 연구하고, 공유하고, 소통하기 위한 연구실입니다. 개인적으로는 OLAP, Data Mining, Semantic Web, Data Modeling에 대해서 연구하고 있습니다.

Categories

전체 (2998)
Webdizen (134)
Life (6)
Diary (16)
Blog (9)
IDEA (1)
Travel (10)
Book (14)
Photo (7)
Movie (7)
Music (13)
Leisure Sports (10)
Funny (5)
Hardware (119)
Software (120)
Windows (5)
Unix & Linux (119)
Installation (4)
Kernel (10)
System (34)
Develop (22)
X-Window (0)
Applicaton (31)
Security (4)
Framework (2)
Hadoop (2)
Programming (805)
Algorithm & Data Structure (1)
Assembly (38)
UNIX/Linux C (95)
C++ (128)
STL (4)
Java (38)
Win32 API (92)
ATL/COM (44)
MFC (151)
.NET (26)
WCF/WPF (4)
C# (28)
Network Programming (17)
Database Programming (12)
OpenGL / DirectX (13)
Multimedia Programming (0)
Game Programming (21)
Parallel Distributed Progra... (0)
Reverse Engineering (0)
Debugging (9)
Python (1)
Ruby (1)
Ruby on Rails (1)
QT (4)
GTK (0)
JSP (0)
PHP (6)
ASP.NET (6)
ASP (3)
Development (28)
Useful Library (2)
Data Modeling (0)
Database (105)
Oracle (4)
MSSQL (41)
MySQL (2)
Data Warehouse (2)
Data Mining (3)
Network (66)
Web (78)
DHTML (4)
XHTML (1)
Javascript (1)
CSS (1)
AJAX (9)
XML (11)
Flex (1)
Silverlight (3)
Security (91)
DoS (1)
Kernel (10)
Scanning (3)
Sniffing (0)
Spoofing (4)
Overflow (28)
Web (11)
Shell (10)
Format String (14)
Window (2)
Embedded (70)
Multimedia (27)
Mobile (14)
Graphic (24)
Management (633)
Knowledge (581)
Hadoop (0)

Notice

  • 메타 블로그 사이트에 등록
  • 새해 맞이 블로그의 변화
  • 블로그 명칭 변경
  • 도메인(www.webdizen.net) 구...
  • TEXTCUBE 1.6.1로 업그레이드...

Tags

  • 의과대학
  • System
  • Events
  • 안내도
  • 싱크
  • 프로그래머
  • WIS
  • Cataloging
  • Datasheet
  • 한서관
  • 바탕화면
  • 파일 종류
  • 압축 프로그래밍
  • libpcap
  • 소프트웨어
  • 화면 정보
  • API
  • Website
  • tty
  • 최적화

Recent Articles

  • ASCII Code의 CRLF 제거 방법.
  • Hadoop 에서 c++ API 이용시....
  • Ubuntu Linux에서 Hadoop 구....
  • 내 심장을 한껏 뛰게한 "국가....
  • 스타 스키마 데이터베이스 설....

Recent Comments

  • ■ 온라인카지노 ▶ http://L....
    asdf 11/21
  • 그리고 혹시 해외여행자보험....
    kim 11/05
  • ★★실제 바다게임장과 똑같....
    asdf 11/04
  • sbsyama.co.to← 짱5000만당....
    asdf 11/04
  • ♡KicaZ??o(???) 바카라사....
    fdsf3fass 11/03

Recent Trackbacks

  • 파일 열기/저장하기 CFileDialog.
    은마군의 나태블록 02/11
  • World IT Show 2008.
    상우 :: Oranzie's BLOG 2008
  • cvs서버 설치하기.
    3인3색 2008
  • 속속 공개되는 Google Chart....
    PHP와 Web 2.0 2007
  • 마방진을 구하는 프로그램.
    Oranzie's BLOG 3 2007

Archive

  • 2009/09 (3)
  • 2009/08 (1)
  • 2009/03 (1)
  • 2009/02 (9)
  • 2009/01 (13)

Calendar

«   2009/11   »
일 월 화 수 목 금 토
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          

Bookmarks

    • Administration
      • IIS.NET
      • NTFAQ
      • OS의 모든 것
      • 리눅스포털
    • Database
      • SQL Server Central
      • SQL Team
    • Development
      • .NET Heaven
      • ASP Alliance
      • ASP.NET 2.0
      • Bullog.net
      • C# Corner
      • C++ (C PlusPlus.com)
      • C++ Reference
      • CodeGuru
      • CodePlex
      • DebugLab
      • Dev Articles
      • Devpia
      • DotNet Junkies
      • DotNet Zone
      • Driver Online
      • GOSU.NET
      • HOONS 닷넷
      • Joinc 팀블로그
      • KOSR
      • MSDN Home Page
      • OSR Online
      • Sky.ph - 개발자 커뮤니...
      • TAEYO.NET
      • The Code Project
      • WindowsClient.net
      • 김상욱의 개발자 Side
      • 조인시 위키
    • Human Networks
      • belief21c's e-space
      • I think I can
      • Invisible Rover's Blog :D
      • Rodman®
      • ■ Feel So Good~! ■
      • 까만 나비
      • 나를 가꾸는 시간.
      • 나만의 즐거움~~!
      • 단녕
      • 상우 :: Oranzie's BLOG
    • Information Technology
      • Microsoft TechNet
      • 지디넷코리아 - 글로벌...
    • Security
      • FoundStone
      • milw0rm
      • NewOrder
      • OpenRCE
      • Phrack.org
      • Reverse Engineering b1...
      • Reverse Engineering Team
      • RootKit
      • SecurityFocus
      • SecurityXploded by Nag...
      • Wow Hacker
      • Zone-H
Textcube
Louice Studio Inc.
Powered by Textcube. Original designed by Tistory.