C++ 재미있는 private


#include

class Counter
{
private:

short itsVal;

public:

short GetItsVal()const{return itsVal;}

Counter operator++();

Counter();

Counter(const Counter &);
Counter(const CCount &);

~Counter();

};

Counter Counter::operator++()

{

++itsVal;

return *this;

}

Counter::Counter():itsVal(0)

{

cout<<“Constructor”<
}
Counter::Counter(const CCount & rhs)
{

cout<<“Copy Constructor”<
itsVal=rhs.itsVal;

}

Counter::Counter(const Counter & rhs)
{
cout<<“Copy Constructor”< itsVal=rhs.itsVal;
}
Counter::~Counter()
{
cout<<“Destructor”< }

void main()

{

Counter i, j, k;
cout<<” — Start — “< cout<<“The value of i is “< cout<<“The value of j is “< cout<<“The value of k is “< ++j;
k=++i;
++i;
cout<<“The value of i is “< cout<<“The value of j is “< cout<<“The value of k is “< }
/* 출력결과
Constructor
Constructor
Constructor
— Start —
The value of i is 0
The value of j is 0
The value of k is 0
Copy Constructor
Destructor
Copy Constructor
Destructor
Copy Constructor
Destructor
The value of i is 2
The value of j is 1
The value of k is 1
Destructor
Destructor
Destructor
Press any key to continue */

itsVal=rhs.itsVal 와같이 private로 설정된 멤버의 액세스가 가능하다. C++의 접근규칙은 class단위로 설정되므로 같은 클래스에서 생성된 다른 객체도 다른객체의 private에 접근가능하다..


출처 – Depia vc++문답게시판 –

NI Studio7.1을 이용한 배포프로젝트 에러 수정


Building Datasocket Setup Project with Measurement Studio 7.1 Returns Build Errors

Primary Software: Measurement Studio>>.NET Support
Primary Software Version: 7.1
Primary Software Fixed Version: 7.1
Secondary Software: N/A








Problem:
Building a Measurement Studio 7.1 Datasocket project (C++ or .NET) into a setup project using Visual Studio .NET 2003 returns the following errors.

…Setup1.vdproj Unable to find module dependency with signature ‘HTML WinHelp.418EB79A_933F_4406_9330_5F5078FF32FF’
…Setup1.vdproj Unable to import merge module ‘logosdll’
…Setup1.vdproj Unable to import merge module ‘logossrv’

How do I deploy a Datasocket application with Measurement Studio 7.1?

Solution:
You would need to replace the merge modules (.msm) that are provided with Measurement Studio 7.1 with the files attached to this document.
Download the attached files and copy them to the following location:

C:Program FilesCommon FilesMerge Modules

You must also include a ProgramFilesFolder and SystemFolder entry in the Directory Table. To include this entry in Visual Studio .NET, add a “Program Files Folder” as a Special Folder in the File System view of the deployment project. Repeat the same step to add the “System Folder” entry.

If you receive the MSI error 2920 during installation on the deployment machine, you might have not included the SystemFolder entry before building the installer.

Measurement Studio 7.1 allows deployment for Datasocket version 4.2.

위와같이 Path설정을 프로젝트내에 추가한다.

출처 – NI Faq

VC.NET2003 MFC DDE 에러 수정

 

This allows the application to register a document type and extension in the Registry database, allowing you to open the document by double-clicking the filename with a registered extension in Windows Explorer. it also allows for other shell commands, such as printing the document from Explorer.


Unfortunately, a code modification between versions 7.0 and 7.1 of Visual Studio introduced a bug that makes this feature inoperable. If you compile a program using VS 7.1 (.NET 2003) and try opening the file using a DDE mechanism, you will encounter no error message at all or the message:


Error: failed to execute DDE command” with no further explanation.


Sometimes, you can see that the process is not terminated and still running after that error and Task menager has to be used to terminate the application.


The code change was supposed to prevent a buffer overrun. See code below.


Microsoft coders somehow forgot abut one line of code that would copy a DDE command from a LPCTSTR string retrieved by UnpackDDElParam, to a TCHAR string used as a parameter in a call to a CWinApp virtual member, OnDDECommand. Therefore, the DDE command is always empty and the DDE fails to open or print the file.


We have two possibilities: Override OnDDECommand or handle message WM_DDE_EXECUTE. I have chosen the second one so the existing code will not be executed. Because the string is passed to the WM_DDE_EXECUTE handler and should be passed to OnDDECommand, overriding the WM_DDE_EXECUTE handler seems to be more appropriate.


To do so:


Add #include <dde.h> to your StdAfx.h file for a WM_DDE_EXECUTE definition.


In the CMainFrame class, insert a mapping macro:

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)    

ON_MESSAGE(WM_DDE_EXECUTE, OnDDEExecute) END_MESSAGE_MAP()

And the definition of OnDDEExecute:

LRESULT CMainFrame::OnDDEExecute(WPARAM wParam, LPARAM lParam) {
    // unpack the DDE message
    UINT_PTR unused;    HGLOBAL hData;
    //IA64: Assume DDE LPARAMs are still 32-bit
    VERIFY(UnpackDDElParam(WM_DDE_EXECUTE, lParam, &unused,  (UINT_PTR*)&hData));
     // get the command string 
    TCHAR szCommand[_MAX_PATH * 2] = {0}; 
    LPCTSTR lpsz = (LPCTSTR)GlobalLock(hData);
    int commandLength = lstrlen(lpsz);
    // This line is added to original MS code.
    int arrayLen = sizeof(szCommand)/sizeof(TCHAR); 
    // This line is changed to avoid _countof (another include file). 
   if (commandLength >= arrayLen)    {
// The command would be truncated. this could be a security
   // problem.       
       TRACE0(“Warning: Command was ignored because it was too long.\n”);
       return 0;
    } 
    // This line is needed to rectify a problem. 
    lstrcpyn(szCommand, lpsz, arrayLen);
    GlobalUnlock(hData);
     // acknowledge now – before attempting to execute
    ::PostMessage((HWND)wParam, WM_DDE_ACK, (WPARAM)m_hWnd, 
//IA64: Assume DDE PARAMs are still 32-bit
ReuseDDElParam(lParam, WM_DDE_EXECUTE, WM_DDE_ACK, (UINT)0x8000, (UINT_PTR)hData));
    // don’t execute the command when the window is disabled
    if (!IsWindowEnabled())
    {
       TRACE(traceAppMsg, 0, _T(“Warning: DDE command ‘%s’ ignored 
because window is disabled.\n”), szCommand);
       return 0;
    }
     // execute the command
    if (!AfxGetApp()->OnDDECommand(szCommand))
       TRACE(traceAppMsg, 0, _T(“Error: failed to execute DDE
command ‘%s’.\n”), szCommand);
       return 0L;
 } 

In the header file:

afx_msg LRESULT OnDDEExecute(WPARAM wParam, LPARAM lParam);
The preceding change properly copies the string that is passed to OnDDECommand; 

now, DDE works like a charm.


출처 : Codeguru http://www.codeguru.com/cpp/w-d/doc_view/misc/print.php/c8549/

Tomcat 5.x + JSP 한글 인코딩

1. EUC-KR로 인코딩할 때 JSP파일 첫줄에 다음과 같이 추가한다.

<%@ page contentType=”text/html; charset=euc-kr” pageEncoding=”euc-kr”%>

2. 서블릿 필터를 이용하거나 서블릿, JSP첫줄에 다음과 같이 추가한다.
request.setCharacterEncoding(encoding);

3. Tomcat/conf의 server.xml파일에 connector설정에 URIEncoding=”euc-kr”을 추가한다.

결과

pageEncoding에 의해 JSP페이지가 인코딩되어 처리되며

contentType에 의해 response의 charset이 지정되며

setCharacterEncoding에 의해 request body에 대해 charset이 지정된다.

URIEncoding에 의해 GET방식의 파라미터에 encoding이 적용된다.

추가

Encoding방법은 Servlet Spec에서 정의되어 있다. 지원하는 Servlet버전에 따라 처리하는 방법도 달라지므로 자신의 WAS의 서블릿 지원 규격을 확인하여 처리한다.(이내용은 Tomcat 5.x버전을 기준)

parameter를 한번이라도 읽게되면 setCharacterEncoding이 적용되지 않으므로 파라미터를 읽는 로그파일을 생성하지 않는다. (Tomcat valve도 parameter를 읽는것이 읽다. 로깅레벨이 debug이하인경우 파라미터를 덤프하므로 warn레벨 이상으로 둘것)

추가
직접 변환할경우 기본 encoding이 cp1252이므로 다음과 같이 한다.
(request.getParameter().getBytes(“Cp1252″),”euc-kr”)