프로그래밍/C/C++2007.06.08 23:48

출처 : http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=51&MAEULNo=20&no=4002&ref=1340

 

간단하게. 웹에 있는 파일크기를 알아오는 함수임다...

서버에 파일이 없거나 하면,,, -1을 리턴합니다...

 

WININET.LIB를 프로젝트에 넣으면 사용하실수 있습니다.

 

#include <afxinet.h>

DWORD GetUrlFileLength (CString url)

{

DWORD filesize;

 

     TCHAR   szCause[255];

     CString CauseOfError;

      TRY

     {

CInternetSession session;

CHttpFile *remotefile= (CHttpFile*)session.OpenURL(url,1,INTERNET_FLAG_TRANSFER_BINARY);

               TCHAR szContentLength[32];

               DWORD dwInfoSize = 32;

               DWORD dwFileSize = 0;

               BOOL bGotFileSize = FALSE;

               if (remotefile->QueryInfo ( HTTP_QUERY_CONTENT_LENGTH, szContentLength, &dwInfoSize , NULL))

               {

                   bGotFileSize = TRUE;

                   dwFileSize = (DWORD) _ttol(szContentLength);

                   filesize = dwFileSize;// Return 값에 할당.

               }

               else

               { // 에러나 나서 파일이 없을경우에

                    filesize = -1 ;

               }

           remotefile->Close ();

          session.Close ();

     }

 

     CATCH_ALL(error)

     {

         AfxMessageBox ("서버로부터 파일 크기를 얻어오는 과정에서 에러발생");

          error->GetErrorMessage(szCause,254,NULL);

          CauseOfError.Format("%s",szCause);

          AfxMessageBox (CauseOfError);

     }

     END_CATCH_ALL;

 

return filesize;

}

Posted by 시난

댓글을 달아 주세요

프로그래밍/C/C++2007.05.23 11:34

이 기술은 자동화기술의 하나로, MS에서 제공되는 것을 이용하여
MFC에서 워드 문서를 사용하는 것에 대한 설명이다.

http://support.microsoft.com/kb/q238611/

 

 How to embed and automate a Word document with MFC

SUMMARY

Documents that are embedded in other application documents, using OLE embedding, can be modified by automation without double-clicking the embedded document to activate it in "edit" or "open"' mode.

This article demonstrates how to embed and automate a Microsoft Office Word document in an MFC Single Document Interface application. The same approach works with any version of Word. The distinction is not which version of Word created the document, but rather, which version of Word you use in the automation process.

The Word type libraries are as follows:
For Microsoft Office Word 2007, the type library is Msword.olb and is located in the "C:\Program Files\Microsoft Office\Office12" folder.
For Microsoft Office Word 2003, the type library is Msword.olb and is located in the "C:\Program Files\Microsoft Office\Office11" folder.
For Microsoft Word 2002, the type library is Msword.olb and is located in the "C:\Program Files\Microsoft Office\Office10" folder.
For Microsoft Word 2000, the type library is Msword9.olb and is located in the "C:\Program Files\Microsoft Office\Office" folder.
For Microsoft Word 97, the type library is Msword8.olb and is located in the "C:\Program Files\Microsoft Office\Office" folder.

 중략.. 직접 링크를 가서 보세요..


http://support.microsoft.com/kb/q238611/

Posted by 시난

댓글을 달아 주세요

프로그래밍/C/C++2007.05.17 18:06

 #include <stdio.h>
#include <tchar.h>

#include <iostream>
using namespace std;

#include <map>


enum EVENT_TYPE {
 EVENT_MOUSE_DOWN,
 EVENT_MOUSE_UP
};

typedef struct {
 int x, y;
} EventArgs;

typedef void (*fnpoint)(EventArgs);


class Button
{
public:
 void AddEvent(EVENT_TYPE eventType, fnpoint fn)
 {
  m_mapEvent[eventType] = fn;
 }

 void FireEvent(EVENT_TYPE eventType, EventArgs args)
 {
  m_mapEvent[eventType](args);
 }

 void Click()
 {
  EventArgs args;
  args.x = 0;
  args.y = 50;

  FireEvent(EVENT_MOUSE_DOWN, args);
 }

private:
 map<EVENT_TYPE, fnpoint> m_mapEvent;

};


void OnMouseDown(EventArgs args)
{
 printf("button clicked! (%d, %d)\n", args.x, args.y);
}

int _tmain(int argc, _TCHAR* argv[])
{
 Button button;

 button.AddEvent(EVENT_MOUSE_DOWN, OnMouseDown);

 button.Click();

 return 0;
}


Posted by 시난

댓글을 달아 주세요

프로그래밍/C/C++2007.05.17 17:20

 #include <stdio.h>
#include <tchar.h>

#include <iostream>
using namespace std;

#include <map>

enum EVENT_TYPE {
 EVENT_MOUSE_DOWN,
 EVENT_MOUSE_UP
};

//void (*pEventHandler[3])(void);
typedef void (*fnpoint)(void);

fnpoint g_eventListener;

void sayHello()
{
 printf("hello!\n");
}

void OnMouseDown()
{
 printf("OnMouseDown!\n");
}

void OnMouseUp()
{
 printf("OnMouseUp!\n");
}

map<EVENT_TYPE, fnpoint> eventMap;


void AddEventListener(EVENT_TYPE eventType, fnpoint e)
{
 g_eventListener = e;
}

void FireEvent(EVENT_TYPE eventType)
{
 switch (eventType) {
  case EVENT_MOUSE_DOWN:
   g_eventListener();
   break;
 }

}

void MouseDown()
{
 //g_eventListener();

 FireEvent(EVENT_MOUSE_DOWN);
}

 


int _tmain(int argc, _TCHAR* argv[])
{
/*
 void (*pFn)(void);
 pFn = sayHello;
 pFn();
*/

 //AddEventListener(EVENT_MOUSE_DOWN, OnMouseDown);
 //MouseDown();

 eventMap[EVENT_MOUSE_DOWN] = OnMouseDown;

 eventMap[EVENT_MOUSE_DOWN]();

 //pEventHandler[0] = OnMouseDown;
 //pEventHandler[1] = OnMouseUp;


 //pEventHandler[0]();
 //pEventHandler[1]();

 return 0;
}


Posted by 시난

댓글을 달아 주세요

프로그래밍/C/C++2007.05.17 16:36

안녕하세요, 시난입니다.
함수포인터를 간단히 알아봅시다. ^^;


 #include <stdio.h>

void sayHello(void)
{
     printf("hello!\n");
}

int _tmain(int argc, _TCHAR* argv[])
{
     void (*pFn)(void);    // 리턴 값이 void 고 인자값이 void 인 함수를 가리키는 포인터를 생성
     pFn = sayHello;       // sayHello 라는 함수를 pFn로 가리킨다
     pFn();                    // pFn은 sayHello를 가리키고 있으므로, pFn(); 으로 호출하면 동일하게 된다. 

     return 0;


리턴 값과, 인자 값은 가리킬 함수에 맞게 수정하면, 여러개의 인자도 가능!


Posted by 시난

댓글을 달아 주세요

프로그래밍/C/C++2007.04.29 01:00

ex) #pragma comment(lib, "something.lib")

 

#pragma는 전처리기(precompiler)다.

#define 처럼 컴파일할 때 처리를 하게 된다.

 

위의 예와 같이 하게되면

project setting 에서 c/c++ 탭쪽에 project options 에 lib들을 지정할 수 있는데

이와 동일한 기능을 소스에 넣을 수 있다.

 

 

다음과 같은 형식을 같는다.

#pragma comment( comment-type [, commentstring] )

 

comment-type은 따옴표 필요없이 넣는 것이고,

commentstring은 따옴표 안에 문자열을 넣어야 한다.

 

comment-type에는 compiler, exestr, lib, linker, user 등을 넣을 수 있다.

 

일단은 lib만 알고 넘어가고, 자세한 것은 msdn에서 필요할 때 찾기로 한다.

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

C/C++ Preprocessor Reference 
comment (C/C++) 

Places a comment record into an object file or executable file.

#pragma comment( comment-type [,"commentstring"] )
RemarksRemarks

The comment-type is one of the predefined identifiers, described below, that specifies the type of comment record. The optional commentstring is a string literal that provides additional information for some comment types. Because commentstring is a string literal, it obeys all the rules for string literals with respect to escape characters, embedded quotation marks ("), and concatenation.

compiler

Places the name and version number of the compiler in the object file. This comment record is ignored by the linker. If you supply a commentstring parameter for this record type, the compiler generates a warning.

exestr

Places commentstring in the object file. At link time this string is placed in the executable file. The string is not loaded into memory when the executable file is loaded; however, it can be found with a program that finds printable strings in files. One use for this comment-record type is to embed a version number or similar information in an executable file.

exestr is deprecated and will be removed in a future release; the linker does not process the comment record.

lib

Places a library-search record in the object file. This comment type must be accompanied by a commentstring parameter containing the name (and possibly the path) of the library that you want the linker to search. The library name follows the default library-search records in the object file; the linker searches for this library just as if you had named it on the command line provided that the library is not specified with /nodefaultlib. You can place multiple library-search records in the same source file; each record appears in the object file in the same order in which it is encountered in the source file.

If the order of the default library and an added library is important, compiling with the /Zl switch will prevent the default library name from being placed in the object module. A second comment pragma then can be used to insert the name of the default library after the added library. The libraries listed with these pragmas will appear in the object module in the same order they are found in the source code.

linker

Places a linker option in the object file. You can use this comment-type to specify a linker option instead of passing it to the command line or specifying it in the development environment. For example, you can specify the /include option to force the inclusion of a symbol:

코드 복사
#pragma comment(linker, "/include:__mySymbol")

Only the following (comment-type) linker options are available to be passed to the linker identifier:

  • /DEFAULTLIB

  • /EXPORT

  • /INCLUDE

  • /MANIFESTDEPENDENCY

  • /MERGE

  • /SECTION

user

Places a general comment in the object file. The commentstring parameter contains the text of the comment. This comment record is ignored by the linker.

The following pragma causes the linker to search for the EMAPI.LIB library while linking. The linker searches first in the current working directory and then in the path specified in the LIB environment variable.

코드 복사
#pragma comment( lib, "emapi" )

The following pragma causes the compiler to place the name and version number of the compiler in the object file:

코드 복사
#pragma comment( compiler )
NoteNote

For comments that take a commentstring parameter, you can use a macro in any place where you would use a string literal, provided that the macro expands to a string literal. You can also concatenate any combination of string literals and macros that expand to string literals. For example, the following statement is acceptable:

코드 복사
#pragma comment( user, "Compiled on " __DATE__ " at " __TIME__ ) 
-----------------------------------------------------------------------------------

 

 

#

이러한 작은 지식이라도 모두 다 적어놓기로 했다..

Posted by 시난

댓글을 달아 주세요