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”)

ToolBar 이어붙이기

ToolBar를 이어 붙이기

CMainFrame에 다음과 같은 함수를 추가한다.

void CMainFrame::DockControlBarLeftOf(CToolBar* Bar, CToolBar* LeftOf)
{
 CRect rect;
 DWORD dw;
 UINT n;

 // get MFC to adjust the dimensions of all docked ToolBars
 // so that GetWindowRect will be accurate
 RecalcLayout(TRUE);

 LeftOf->GetWindowRect(&rect);
 rect.OffsetRect(1,0);
 dw=LeftOf->GetBarStyle();
 n = 0;
 n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
 n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
 n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
 n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;

 // When we take the default parameters on rect, DockControlBar will dock
 // each Toolbar on a seperate line. By calculating a rectangle, we
 // are simulating a Toolbar being dragged to that location and docked.
 DockControlBar(Bar,n,&rect);
}

사용예)

m_wndToolBar1.EnableDocking(CBRS_ALIGN_ANY);
 m_wndToolBar2.EnableDocking(CBRS_ALIGN_ANY);
 EnableDocking(CBRS_ALIGN_ANY);
 DockControlBar(&m_wndToolBar1);
 DockControlBarLeftOf(&m_wndToolBar2,&m_wndToolBar1);

출처 : CodeProject
http://www.codeproject.com/docking/toolbar_docking.asp?df=100&forumid=54&exp=0&select=1013370

Dialog EditBox에서 엔터키 처리

Dialog에서는 Edit에서 Enter키를 Want Return을 지정하더라도 Enter키 입력시 다이어로그가 종료된다.

1. PreTranslateMessage(MSG* pMsg)를 다음과 같이 오버라이드 한다.
2. 엔터키 입력시 원하는 처리를 각각 추가 한다.

BOOL CHMC_CleanerDlg::PreTranslateMessage(MSG* pMsg)
{
 if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
 {      
  if (GetDlgItem(IDC_EDIT1) == GetFocus())
  {
   return TRUE;
  }
  if (GetDlgItem(IDC_EDIT2) == GetFocus())
  {
   // 여기에 추가
   return TRUE;
  }
  if (GetDlgItem(IDC_EDIT4) == GetFocus())
  {
   // 여기에 추가
   return TRUE;
  }
 }
 return CDialog::PreTranslateMessage(pMsg);
}

 

Listview컨트롤 Text가져오기


I was recently trying to steal strings from another program’s listview control. You need to pass a pointer so it knows where to put the string. Normally this wouldn’t be a problem, but because Windows uses virtual memory pointers are not valid across programs.


Virtual memory is how Windows deals out memory to all it’s programs. It makes programs think they have 2 Gb of memory to use. It also protects programs from using each other’s memory so if one program crashes it doesn’t take down the whole system with it.


So after coding a fair bit, I realized my pointers were all invalid and it wouldn’t work. A few hours of digging through MSDN brought me to the functions VirtualAllocEx(), VirtualFreeEx(), WriteProcessMemory() and ReadProcessMemory(). Armed with this new information, I set out to modify my code. Here is what I had so far:


Collapse
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <windows.h>
#include <commctrl.h>
int main(void) {
/* Run through the windows until we find our listview. */
HWND hwnd=FindWindow(NULL, “Stealing Program’s Memory: ListView”);
HWND listview=FindWindowEx(hwnd, NULL, “SysListView32”, NULL);
int count=(int)SendMessage(listview, LVM_GETITEMCOUNT, 0, 0);
int i; char item[512], subitem[512];
/* Shove all items of listview into item and subitem
and print out one by one. */
LVITEM lvi;
lvi.cchTextMax=512;
for(i=0; i<count; i++) {
lvi.iSubItem=0;
lvi.pszText=item;
SendMessage(listview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)&lvi);
lvi.iSubItem=1;
lvi.pszText=subitem;
SendMessage(listview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)&lvi);
printf(“%s – %s\n”, item, subitem);
}

return 0;
}


As I said before, this won’t work. The pointers to lvi, item, and subitem all get screwed when they go across process. The solution? Use WriteProcessMemory() and ReadProcessMemory() to use the other programs memory, perform LVM_GETITEMTEXT on it, and read it back. Hackish yes, but then again reading items from another program’s listview control is one giant hack.


First, we get the process of the listview like this:

 unsigned long pid;
HANDLE process;
GetWindowThreadProcessId(listview, &pid);
process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|
PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, pid);

Next We create three pointers, LVITEM *_lvi, char *_item, and char *_subitem and allocate them in the other program’s virtual memory space with VirtualAllocEx():

LVITEM *_lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM),
MEM_COMMIT, PAGE_READWRITE);
char *_item=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,
PAGE_READWRITE);
char *_subitem=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,
PAGE_READWRITE);

Now we point lvi.pszText to _item, and copy it’s memory to _lvi using WriteMemoryProcess():

lvi.pszText=_item;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);

Now that we have an LVITEM pointer that is valid in the other programs virtual memory, we can shoot off LVM_GETITEMTEXT to listview and copy _item‘s text into item so we can read it in our program:

SendMessage(hwnd, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
ReadProcessMemory(process, _item, item, max, NULL);

Repeat that for subitem, then free the memory we used in the other program’s memory:

VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _item, 0, MEM_RELEASE);
VirtualFreeEx(process, _subitem, 0, MEM_RELEASE);

Yay, all done. In case that didn’t make too much sense to you, here is our new code, all fixed up:


Collapse
#define WIN32_LEAN_AND_MEAN #include <stdio.h> 
#include <windows.h>
#include <commctrl.h>
int main(void) {
HWND hwnd=FindWindow(NULL, “Stealing Program’s Memory: ListView”);
HWND listview=FindWindowEx(hwnd, NULL, “SysListView32”, NULL);
int count=(int)SendMessage(listview, LVM_GETITEMCOUNT, 0, 0);
int i;
LVITEM lvi, *_lvi;
char item[512], subitem[512];
char *_item, *_subitem;
unsigned long pid;
HANDLE process;
GetWindowThreadProcessId(listview, &pid);
process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|
PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, pid);
_lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM),
MEM_COMMIT, PAGE_READWRITE);
_item=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,
PAGE_READWRITE);
_subitem=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,
PAGE_READWRITE);
lvi.cchTextMax=512;
for(i=0; i<count; i++) {
lvi.iSubItem=0;
lvi.pszText=_item;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
SendMessage(listview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
lvi.iSubItem=1;
lvi.pszText=_subitem;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
SendMessage(listview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
ReadProcessMemory(process, _item, item, 512, NULL);
ReadProcessMemory(process, _subitem, subitem, 512, NULL);
printf(“%s – %s\n”, item, subitem);
}
VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _item, 0, MEM_RELEASE);
VirtualFreeEx(process, _subitem, 0, MEM_RELEASE);
return 0;
}

If you’re looking to use a program’s memory for another reason, or have had a similar problem to mine, adapting this should be fairly easy.

출처- codeproject-