|
Thanks, GetModuleFileNameEx works but again it needs processid.
|
|
|
|
|
Okay, so call GetCurrentProcessId() first.
|
|
|
|
|
Hi All,
I am writing a MFC program. It has a splitter window which contains 2 CView and CFormView derived Views. I wrote it based on the acticle written by pt315 "Splitter Window Tutorial".(http://www.codeproject.com/splitter/splitterwindowtutorial.asp"
The program up and running in VC7 debug mode. However, when I run the .exe file built by VC7, it seems cannot create the CView derived View and the program abort with 2 messagebox, "Error setting up left view" and "Fail to create empty document".
And I dont have any idea about why it fail when running by .exe.
I attached the code where the problem occur. Could anyone provide me some advice why this is happened?
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) <br />
{<br />
<br />
CRect cr;<br />
GetWindowRect( &cr );<br />
<br />
if ( !m_mainSplitter.CreateStatic( this, 1, 2 ) )<br />
{<br />
MessageBox( "Error setting up m_mainSplitter", "ERROR", MB_OK | MB_ICONERROR );<br />
return FALSE;<br />
}<br />
<br />
if ( !m_mainSplitter.CreateView( 0, 0, RUNTIME_CLASS(CMPVIEWERView),<br />
CSize(cr.Width()/2, cr.Height()), pContext ) )<br />
{<br />
MessageBox( "Error setting up left view", "ERROR", MB_OK | MB_ICONERROR );<br />
return FALSE;<br />
}<br />
<br />
if ( !m_mainSplitter.CreateView( 0, 1, RUNTIME_CLASS(CSTATVIEW),<br />
CSize(cr.Width()/2, cr.Height()), pContext ) )<br />
{<br />
MessageBox( "Error setting up right view", "ERROR", MB_OK | MB_ICONERROR );<br />
return FALSE;<br />
}<br />
<br />
m_bInitSplitter = true;<br />
<br />
CMPVIEWERView * mpv ;
mpv = (CMPVIEWERView *) m_mainSplitter.GetPane(0,0); <br />
mpv->m_pStatView = (CSTATVIEW *) m_mainSplitter.GetPane(0, 1);<br />
<br />
m_pMPVIEWERView = mpv;<br />
<br />
return TRUE;<br />
}
|
|
|
|
|
I tried to swap the sequence of creating views... that is ... create the CFormView derived one first and then the CView derived one. It shown that the CFormView one can be created(" No error messagebox shown for it"), the the CView one still having the problem...
Any idea about this?
Help! I need somebody help!
Would you please help me?
|
|
|
|
|
Hi there,
Can you post how you've implemented the CMPVIEWERView. Also, look at the views files for where the #ifdef _DEBUG directives start and end just to make sure nothing has accidentally been included within them. Check your RUNTIME_CLASS macros too (IMPLEMENT_DYNCREATE and DECLARE_DYNCREATE).
Hope this helps,
Andy
|
|
|
|
|
Hi,
I have looked into the #ifdef _DEBUG directives and the RUNTIME_CLASS macros too...But nothing is find to be suspecious, may be I am dull about it.
I attach my code as follows(It may be too long , but I will attach both .h and .cpp file here... as it might help to find what is wrong), It is the CView derived class which cannot be created at the run-time. Anyone got idea what has happened that my .exe file fail to create the view, please let me know. I have been working on it for 3 days and no progress...
For the MPVIEWERView.h,
<br />
<br />
<br />
#pragma once<br />
#include "RegularExpression.h"<br />
#include "afxcoll.h"<br />
#include "MPVIEWERDoc.h"<br />
#include ".\InboundRecordArray.h"<br />
#include ".\STATVIEW.h"<br />
<br />
class CMPVIEWERView : public CView<br />
{<br />
protected:
CMPVIEWERView();<br />
DECLARE_DYNCREATE(CMPVIEWERView)<br />
<br />
public:<br />
CMPVIEWERDoc * GetDocument() const;<br />
<br />
public:<br />
<br />
public:<br />
virtual void OnDraw(CDC* pDC);
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);<br />
protected:<br />
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);<br />
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);<br />
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);<br />
<br />
public:<br />
virtual ~CMPVIEWERView();<br />
#ifdef _DEBUG<br />
virtual void AssertValid() const;<br />
virtual void Dump(CDumpContext& dc) const;<br />
#endif<br />
<br />
protected:<br />
<br />
protected:<br />
DECLARE_MESSAGE_MAP()<br />
public:<br />
afx_msg void OnFileStartlogging();<br />
<br />
virtual void OnInitialUpdate(void);<br />
<br />
static UINT run(LPVOID p);<br />
void run();<br />
volatile BOOL running;<br />
<br />
void plot(void);<br />
<br />
void CallbackGrepBlock(RegularExpression * cre, const REMatchInfo & Matches, unsigned LineIndex, unsigned StartOfLine, bool & bcontinue);<br />
void CallbackGrepInbound(RegularExpression * cre, const REMatchInfo & Matches, unsigned LineIndex, unsigned StartOfLine, bool & bcontinue);<br />
<br />
<br />
CStringArray ipColorArray;
CPen CMPVIEWERView::GetColorPen(CString colorCode);<br />
afx_msg void OnEditOptions();<br />
int m_MaxLineShown;<br />
int m_LineSpace;<br />
<br />
afx_msg void OnUpdateFileStartlogging(CCmdUI *pCmdUI);<br />
<br />
CString ReadConfig(CString option);<br />
void WriteConfig(CString option, CString value);<br />
<br />
void UpdateStatusBarText(CString newStatusText);<br />
<br />
int blockNum; <br />
int inboundNum;<br />
<br />
CInboundRecordArray inboundRecordArray;<br />
CSTATVIEW * m_pStatView;<br />
void SendStartLoggingMsg(void);<br />
CString systemStr;<br />
void dumpcall(void);<br />
void RemoveALine(void);<br />
<br />
void DrawBitmap( CDC *pDC, HBITMAP hBitmap, HPALETTE hPal, int xDest, int yDest );<br />
<br />
};<br />
<br />
#ifndef _DEBUG // debug version in MPVIEWERView.cpp<br />
inline CMPVIEWERDoc* CMPVIEWERView::GetDocument() const<br />
{ return reinterpret_cast<CMPVIEWERDoc*>(m_pDocument); }<br />
#endif
For the MPVIEWERView.cpp,
<br />
#include "stdafx.h"<br />
#include "MPVIEWER.h"<br />
#include "MPVIEWERDoc.h"<br />
#include "MPVIEWERView.h"<br />
#include ".\mpviewerview.h"<br />
#include ".\MainFrm.h"<br />
#include ".\STATVIEW.h"<br />
#include <WinSock.h><br />
#include <stdio.h><br />
#include <iostream><br />
#define SERVER_PORT htons(514) /* Syslogd UDP Port */<br />
<br />
using namespace std;<br />
<br />
#include "RegularExpression.h"<br />
#include <vector><br />
#include <string><br />
#include <sstream><br />
<br />
#include ".\OptionsDlg.h"<br />
#include ".\TokenEx.h"<br />
#include <vector><br />
#include <string><br />
#include <sstream><br />
<br />
#ifdef _DEBUG<br />
#define new DEBUG_NEW<br />
#endif<br />
<br />
<br />
<br />
IMPLEMENT_DYNCREATE(CMPVIEWERView, CView)<br />
<br />
BEGIN_MESSAGE_MAP(CMPVIEWERView, CView)<br />
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)<br />
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)<br />
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)<br />
ON_COMMAND(ID_FILE_STARTLOGGING, OnFileStartlogging)<br />
ON_COMMAND(ID_EDIT_OPTIONS, OnEditOptions)<br />
ON_UPDATE_COMMAND_UI(ID_FILE_STARTLOGGING, OnUpdateFileStartlogging)<br />
END_MESSAGE_MAP()<br />
<br />
<br />
CMPVIEWERView::CMPVIEWERView()<br />
: m_MaxLineShown(0)<br />
, m_LineSpace(0)<br />
, blockNum(0)<br />
, inboundNum(0)<br />
, m_pStatView(NULL)<br />
, systemStr(_T(""))<br />
{<br />
m_LineSpace = _ttoi(ReadConfig("linespace"));<br />
m_MaxLineShown = _ttoi(ReadConfig("maxlines"));<br />
running = FALSE;<br />
m_pStatView = NULL;<br />
systemStr.Format("MP Viewer is not running."); <br />
}<br />
<br />
CMPVIEWERView::~CMPVIEWERView()<br />
{<br />
}<br />
<br />
BOOL CMPVIEWERView::PreCreateWindow(CREATESTRUCT& cs)<br />
{<br />
return CView::PreCreateWindow(cs);<br />
}<br />
<br />
<br />
void CMPVIEWERView::OnDraw(CDC* pDC)<br />
{<br />
CMPVIEWERDoc* pDoc = GetDocument();<br />
ASSERT_VALID(pDoc);<br />
if (!pDoc)<br />
return;<br />
plot();<br />
}<br />
<br />
<br />
<br />
BOOL CMPVIEWERView::OnPreparePrinting(CPrintInfo* pInfo)<br />
{<br />
return DoPreparePrinting(pInfo);<br />
}<br />
<br />
void CMPVIEWERView::OnBeginPrinting(CDC* , CPrintInfo* )<br />
{<br />
}<br />
<br />
void CMPVIEWERView::OnEndPrinting(CDC* , CPrintInfo* )<br />
{<br />
}<br />
<br />
<br />
#ifdef _DEBUG<br />
void CMPVIEWERView::AssertValid() const<br />
{<br />
CView::AssertValid();<br />
}<br />
<br />
void CMPVIEWERView::Dump(CDumpContext& dc) const<br />
{<br />
CView::Dump(dc);<br />
}<br />
<br />
CMPVIEWERDoc* CMPVIEWERView::GetDocument() const
{<br />
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMPVIEWERDoc)));<br />
return (CMPVIEWERDoc*)m_pDocument;<br />
}<br />
#endif //_DEBUG<br />
<br />
<br />
void CMPVIEWERView::OnInitialUpdate(void)<br />
{<br />
CView::OnInitialUpdate();<br />
<br />
<br />
}<br />
<br />
UINT CMPVIEWERView::run(LPVOID p) <br />
{<br />
CMPVIEWERView * me = (CMPVIEWERView *) p;<br />
me->run();<br />
return 0;<br />
}<br />
<br />
void CMPVIEWERView::run()<br />
{<br />
SOCKET sockfd;<br />
int n;<br />
SOCKADDR_IN servaddr, cliaddr;<br />
char mesg[1024];<br />
int sin_size = sizeof(struct sockaddr_in);<br />
<br />
sockfd = socket(AF_INET, SOCK_DGRAM, 0);<br />
<br />
servaddr.sin_family = AF_INET;<br />
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);<br />
servaddr.sin_port = htons(SERVER_PORT);<br />
memset(&(servaddr.sin_zero), 0, 8);<br />
if(bind(sockfd, (LPSOCKADDR) &servaddr, sizeof(servaddr))==0) {<br />
SendStartLoggingMsg();<br />
systemStr.Format(_T("%s"), COleDateTime::GetCurrentTime().Format(_T("MP Viewer started running since %I: %M: %S %p, %m/%d/%Y")));<br />
<br />
m_pStatView->lblStart = CTime::GetCurrentTime();<br />
m_pStatView->running = TRUE;<br />
<br />
<br />
plot();
<br />
}<br />
else {<br />
MessageBox("Bind operation failed");<br />
}<br />
<br />
CString block_str = "<[0-9]+>([a-zA-Z]+\\s+\\d+ \\d+:\\d+:\\d+) .* ruleset=check_relay, arg1=(.*), arg2=(.*), relay=.*, reject=550 5\\.7\\.1 Rejected: This system is protected by Mail Prove Service, \\d+\\.\\d+\\.\\d+\\.\\d+ is blacklisted\\. Please go to www\\.mailprove\\.com to unblock\\.";<br />
<br />
CString inbound_str = "<[0-9]+>([a-zA-Z]+\\s+\\d+ \\d+:\\d+:\\d+) .*: .*: from=<(.*)>, size=(\\d+), class=.*, nrcpts=.*, msgid=<.*>, proto=.*, daemon=.*, relay=(.*) \\[(.*)\\]";<br />
while (running)<br />
{<br />
n = recvfrom(sockfd, mesg, 1024, 0,(LPSOCKADDR) &cliaddr, &sin_size);<br />
mesg[n] = '\0'; <br />
CFile file("messagelog.txt", CFile::modeWrite);
file.SeekToEnd();<br />
file.Write(mesg, n+1);<br />
file.Write("\r\n", 2);<br />
file.Close();<br />
<br />
RegularExpression reo_block;<br />
__hook(&RegularExpression::OnGrepping, &reo_block, &CMPVIEWERView::CallbackGrepBlock);<br />
reo_block.Expression = block_str;<br />
reo_block.StringToMatch = mesg;<br />
reo_block.Grep();<br />
<br />
RegularExpression reo_inbound;<br />
__hook(&RegularExpression::OnGrepping, &reo_inbound, &CMPVIEWERView::CallbackGrepInbound);<br />
reo_inbound.Expression = inbound_str;<br />
reo_inbound.StringToMatch = mesg;<br />
reo_inbound.Grep();<br />
}<br />
shutdown(sockfd, SD_BOTH);<br />
if (closesocket(sockfd) == 0) {<br />
AfxMessageBox("Closed socket successfully",MB_OK);<br />
systemStr.Format(_T("%s"), COleDateTime::GetCurrentTime().Format(_T("MP Viewer stopped at %I: %M: %S %p, %m/%d/%Y")));<br />
<br />
m_pStatView->lblStart = CTime::GetCurrentTime();<br />
m_pStatView->running = FALSE;<br />
<br />
plot();
} else {<br />
AfxMessageBox("Failed to close socket", MB_OK);<br />
}<br />
<br />
}<br />
void CMPVIEWERView::plot(void)<br />
{<br />
<br />
CDC * pDC;<br />
pDC = GetDC();<br />
<br />
CRect rect;<br />
GetClientRect(&rect);<br />
<br />
CBrush NewBrush(RGB(255,255,255)); CBrush * pBrush = pDC->SelectObject(&NewBrush);<br />
<br />
CRect urect=rect;
pDC->Rectangle(urect);<br />
pDC->SelectObject(pBrush);<br />
<br />
CPen pen( PS_SOLID, 0, RGB(255,0,255));<br />
CPen* pPenOld = pDC->SelectObject(&pen);<br />
int nMap = pDC->SetMapMode(MM_HIENGLISH);
<br />
int x1 = 500;<br />
int x2 = 3000;<br />
int y1 = -4000;<br />
int y2 = -1000;<br />
<br />
int red,green,blue = 0;<br />
<br />
<br />
CString colorCode;<br />
CString ip;<br />
for (int i=0; i<ipColorArray.GetSize(); i++) <br />
{<br />
CString ipColor = ipColorArray[i];<br />
ip = ipColorArray[i];<br />
ip.Delete(ipColor.GetLength()-1, 1);<br />
<br />
colorCode = ipColor.Right(1);
y2-=m_LineSpace;<br />
<br />
if (colorCode.Compare("g") == 0) {<br />
red = 0; green = 255; blue = 0;<br />
} else if (colorCode.Compare("r") == 0) {<br />
red = 255; green = 0; blue = 0;<br />
} else {<br />
red = 255; green = 255; blue = 255;<br />
}<br />
<br />
CPen pen( PS_SOLID, 0, RGB(red, green, blue));<br />
pPenOld = pDC->SelectObject(&pen);<br />
pDC->SetTextColor(RGB(red, green, blue));<br />
pDC->MoveTo(x1, y1);<br />
pDC->LineTo(x2, y2);<br />
pDC->TextOut(x2, y2, ip);<br />
pDC->TextOut(x2, y2, ip); <br />
}<br />
<br />
<br />
<br />
}<br />
<br />
void CMPVIEWERView::CallbackGrepBlock(RegularExpression* cre, const REMatchInfo & Matches, unsigned LineIndex, unsigned StartOfLine, bool & bcontinue)<br />
{<br />
std::string whatmatched1(Matches[1].string);<br />
std::ostringstream sout1;<br />
sout1 << whatmatched1;<br />
std::string ws1(sout1.str());<br />
CString dateTime(ws1.c_str());<br />
<br />
std::string whatmatched2(Matches[2].string);<br />
std::ostringstream sout2;<br />
sout2 << whatmatched2;<br />
std::string ws2(sout2.str());<br />
CString relay(ws2.c_str());<br />
<br />
std::string whatmatched3(Matches[3].string);<br />
std::ostringstream sout3;<br />
sout3 << whatmatched3;<br />
std::string ws3(sout3.str());<br />
CString ip(ws3.c_str());<br />
<br />
m_pStatView->AddBlockRecord(dateTime, relay, ip);<br />
m_pStatView->AddBlockListRecord(dateTime, relay, ip); <br />
<br />
while (ipColorArray.GetSize() >= m_MaxLineShown) {
ipColorArray.RemoveAt(0, 1);<br />
}<br />
ipColorArray.Add(ip+"r");
<br />
blockNum++;
<br />
plot();<br />
<br />
CString log_msg = "Blocked " + ip + "\r\n";<br />
int length = log_msg.GetLength();<br />
LPCTSTR str = log_msg;<br />
<br />
CFile file("simplelog.txt", CFile::modeWrite); <br />
file.SeekToEnd();<br />
file.Write(str, length);<br />
file.Close();<br />
<br />
}<br />
<br />
void CMPVIEWERView::CallbackGrepInbound(RegularExpression* cre, const REMatchInfo & Matches, unsigned LineIndex, unsigned StartOfLine, bool & bcontinue)<br />
{<br />
std::string whatmatched1(Matches[1].string);<br />
std::ostringstream sout1;<br />
sout1 << whatmatched1;<br />
std::string ws1(sout1.str());<br />
CString dateTime(ws1.c_str());<br />
<br />
std::string whatmatched2(Matches[2].string);<br />
std::ostringstream sout2;<br />
sout2 << whatmatched2;<br />
std::string ws2(sout2.str());<br />
CString email(ws2.c_str());<br />
<br />
std::string whatmatched3(Matches[3].string);<br />
std::ostringstream sout3;<br />
sout3 << whatmatched3;<br />
std::string ws3(sout3.str());<br />
CString size(ws3.c_str());<br />
<br />
std::string whatmatched4(Matches[4].string);<br />
std::ostringstream sout4;<br />
sout4 << whatmatched4;<br />
std::string ws4(sout4.str());<br />
CString relay(ws4.c_str());<br />
<br />
std::string whatmatched5(Matches[5].string);<br />
std::ostringstream sout5;<br />
sout5 << whatmatched5;<br />
std::string ws5(sout5.str());<br />
CString ip(ws5.c_str());<br />
m_pStatView->AddInboundRecord(dateTime, email, size, relay, ip);<br />
m_pStatView->AddInboundListRecord(dateTime, email, size, relay, ip); <br />
<br />
while (ipColorArray.GetSize() >= m_MaxLineShown) {
ipColorArray.RemoveAt(0, 1);<br />
}<br />
ipColorArray.Add(ip+"g");
inboundNum++;
<br />
plot();<br />
<br />
CString log_msg = "Inbound " + ip + "\r\n";<br />
int length = log_msg.GetLength();<br />
<br />
LPCTSTR str = log_msg;<br />
<br />
CFile file("simplelog.txt", CFile::modeWrite);
file.SeekToEnd();<br />
file.Write(str, length);<br />
<br />
file.Close();<br />
}<br />
<br />
<br />
void CMPVIEWERView::OnEditOptions()<br />
{<br />
COptionsDlg dlg;<br />
if (dlg.DoModal() == IDOK) {<br />
m_MaxLineShown = dlg.maxLineShown;<br />
m_LineSpace = dlg.lineSpace;<br />
}<br />
CString value;<br />
value.Format("%i", m_MaxLineShown); <br />
WriteConfig(_T("maxlines"), _T(value));<br />
value.Format("%i", m_LineSpace); <br />
WriteConfig(_T("linespace"), _T(value));<br />
}<br />
<br />
<br />
void CMPVIEWERView::OnFileStartlogging()<br />
{<br />
<br />
running = !running;<br />
if (running) {<br />
AfxBeginThread(run, this);<br />
} else {
MessageBox("Running is FALSE, Send End Connection Message to Server");<br />
<br />
SOCKET sockfd; <br />
SOCKADDR_IN servaddr;<br />
int sin_size = sizeof(struct sockaddr_in);<br />
<br />
CString endStr;<br />
endStr.Format(_T("%s"), COleDateTime::GetCurrentTime().Format(_T("Stop logging at %I: %M: %S %p, %m/%d/%Y")));<br />
<br />
LPTSTR sendstr = new TCHAR[endStr.GetLength()+1];<br />
_tcscpy(sendstr, endStr);<br />
<br />
<br />
<br />
servaddr.sin_family = AF_INET;<br />
servaddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");<br />
servaddr.sin_port = htons(514);<br />
<br />
sockfd = socket(AF_INET, SOCK_DGRAM, 0);<br />
<br />
sendto(sockfd, sendstr, strlen(sendstr), 0, (LPSOCKADDR) &servaddr, sin_size);<br />
<br />
}<br />
}<br />
<br />
<br />
void CMPVIEWERView::OnUpdateFileStartlogging(CCmdUI *pCmdUI)<br />
{<br />
if (running == TRUE) {<br />
pCmdUI->SetText("Stop Logging");<br />
} else {<br />
pCmdUI->SetText("Start Logging");<br />
}<br />
}<br />
<br />
CString CMPVIEWERView::ReadConfig(CString option)<br />
{<br />
CFile file("config.txt", CFile::modeRead);<br />
<br />
ULONGLONG nLen = file.GetLength();<br />
char* pBuffer = new char[ nLen + 1 ];<br />
file.Read( pBuffer, nLen );<br />
pBuffer[ nLen ] = 0;<br />
CString strTemp = pBuffer;<br />
delete [] pBuffer;<br />
file.Close();<br />
<br />
CTokenEx tok;<br />
CStringArray lines;<br />
tok.Split(strTemp, "\n", lines);<br />
<br />
<br />
for (int i=0; i<lines.GetSize(); i++) {<br />
lines[i].Trim();<br />
if (lines[i].Find(option, 0) == 0) {
lines[i].Delete(0, option.GetLength());<br />
return lines[i].Trim();<br />
}<br />
}<br />
<br />
return "";<br />
}<br />
<br />
void CMPVIEWERView::WriteConfig(CString option, CString value)<br />
{<br />
<br />
CFile file_r("config.txt", CFile::modeRead);<br />
<br />
ULONGLONG nLen = file_r.GetLength();<br />
char* pBuffer = new char[ nLen + 1 ];<br />
file_r.Read( pBuffer, nLen );<br />
pBuffer[ nLen ] = 0;<br />
CString strTemp = pBuffer;<br />
delete [] pBuffer;<br />
file_r.Close();<br />
<br />
CTokenEx tok;<br />
CStringArray lines;<br />
tok.Split(strTemp, "\n", lines);<br />
<br />
CFile file_w("config.txt", CFile::modeWrite);<br />
<br />
for (int i=0; i<lines.GetSize(); i++) {<br />
<br />
lines[i].Trim();<br />
lines[i] += "\r\n";<br />
if (lines[i].Find(option, 0) != 0) {
int nLen = lines[i].GetLength(); <br />
file_w.Write( lines[i], nLen );<br />
<br />
} else {<br />
CString strToWrite;<br />
strToWrite = option + " " + value + "\r\n";<br />
int strToWrite_length = strToWrite.GetLength(); <br />
file_w.Write( strToWrite, strToWrite_length );<br />
<br />
}<br />
}<br />
<br />
file_w.Close();<br />
<br />
}<br />
void CMPVIEWERView::SendStartLoggingMsg(void)<br />
{<br />
SOCKET sockfd; <br />
SOCKADDR_IN servaddr;<br />
int sin_size = sizeof(struct sockaddr_in);<br />
<br />
CString startStr;<br />
startStr.Format(_T("%s"), COleDateTime::GetCurrentTime().Format(_T("Start logging at %I: %M: %S %p, %m/%d/%Y")));<br />
<br />
LPTSTR sendstr = new TCHAR[startStr.GetLength()+1];<br />
_tcscpy(sendstr, startStr);<br />
<br />
<br />
<br />
servaddr.sin_family = AF_INET;<br />
servaddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");<br />
servaddr.sin_port = htons(514);<br />
<br />
sockfd = socket(AF_INET, SOCK_DGRAM, 0);<br />
<br />
sendto(sockfd, sendstr, strlen(sendstr), 0, (LPSOCKADDR) &servaddr, sin_size);<br />
}<br />
<br />
void CMPVIEWERView::dumpcall(void)<br />
{<br />
MessageBox("CMPVIEWERView's dumpcall"); <br />
}<br />
<br />
void CMPVIEWERView::RemoveALine(void)<br />
{<br />
if (ipColorArray.GetSize() > 0) {<br />
ipColorArray.RemoveAt(0, 1);
plot();<br />
}<br />
}<br />
<br />
void CMPVIEWERView::DrawBitmap( CDC *pDC, HBITMAP hBitmap, HPALETTE hPal, int xDest, int yDest )<br />
{<br />
BITMAP bm;<br />
::GetObject( hBitmap, sizeof( bm ), &bm );<br />
CPoint size( bm.bmWidth, bm.bmHeight );<br />
pDC->DPtoLP(&size);<br />
<br />
CPoint org(0,0);<br />
pDC->DPtoLP(&org);<br />
<br />
CDC memDC;<br />
memDC.CreateCompatibleDC( pDC );<br />
memDC.SetMapMode( pDC->GetMapMode() );<br />
<br />
HBITMAP hBmOld = (HBITMAP)::SelectObject( memDC.m_hDC, hBitmap );<br />
<br />
<br />
if( hPal && pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)<br />
{<br />
SelectPalette( pDC->GetSafeHdc(), hPal, FALSE );<br />
pDC->RealizePalette();<br />
}<br />
pDC->BitBlt(xDest, yDest, size.x, size.y, &memDC, org.x, org.y, SRCCOPY);<br />
<br />
::SelectObject( memDC.m_hDC, hBmOld );<br />
}
Help! I need somebody help!
Would you please help me?
|
|
|
|
|
Hi:
I want to add a record when program is running in thread,but it doesnot work well and it only gives me an error message and then exit.I dont know how to deal with, please give me some suggestion, thx.
profile:win2000 + vc + acess
Happy Gemini
|
|
|
|
|
Do you mean that this happens ONLY when you run secondary working threads ?
can you post the code that caues the error ?
|
|
|
|
|
fun1()
{
CreateThread(NULL, 0, &myThread, NULL, NULL, &lpThreadId);
}
/// \brief <保存序列采集得到的buffer数据到文件>
unsigned long __stdcall myThread(void *wParam)
{
//new a db record and error.
}
Happy Gemini
|
|
|
|
|
I find the context below in msdn:
"DAO itself is not multithreaded, so you can’t use the MFC DAO classes in multiple threads. Confine your DAO code to a single thread of execution."
I thank maybe it is where error is.
Happy Gemini
|
|
|
|
|
How to get the database table's struct, include it's size of fields.
I use ado2 provided by the site, but I find the size of data type, 'bit', is not correct. In SQL server, its size is 1, but what I get by ado class is 2?why?
I want to do a ETL tool, How to handle the variant data type for transforming.
|
|
|
|
|
Hi!
in the a function of a dialog i've got below code:
It's a part of seeking local computer names, when I click a button.
If i click the button, a dialog box is created and the new one shows up.
But no one can be showed in a list control view of the dialog box on Windows 98.
It hasn't nothing in the list control...
but It can be shown the list on Windows 2000 or XP.
Is the problem here?
Should i put everything in a codes?
Thanks!
noname_function ()
{
// WNetOpenEnum parameters
DWORD dwScope = RESOURCE_CONTEXT;
NETRESOURCE *NetResource = NULL;
HANDLE hEnum;
// WNetOpenEnum for Windows 98
unsigned long strWNetMSG = WNetOpenEnum(dwScope, RESOURCETYPE_ANY, NULL, NULL, &hEnum);
// WSADATA wsaData;
WSAStartup(MAKEWORD(1, 1),&wsaData);
//
if (hEnum)
{
// paremeters for WNetEnumResource
DWORD dwCount = 0xFFFFFFFF;
DWORD dwBufferSize = 16384;
LPVOID lpBuffer = new char[16384];
// continues a network-resource enumeration
unsigned long strWNetResourceMSG = WNetEnumResource(hEnum, &dwCount, lpBuffer, dwBufferSize);
NetResource = (NETRESOURCE*)lpBuffer;
// Earase items in List control
if(m_ListSearchPc.GetItemCount() != 0)
m_ListSearchPc.DeleteAllItems();
m_dwCountTotalPc = 0;
for(unsigned int i = 0; i < dwCount; i++, NetResource++)
{
if (NetResource->dwUsage == RESOURCEUSAGE_CONTAINER && NetResource->dwType == RESOURCETYPE_ANY)
{
if (NetResource->lpRemoteName)
{
CString strFullName = NetResource->lpRemoteName;
// delete \\
if (strFullName.Left(2).Compare("\\\\") == 0)
strFullName = strFullName.Right(strFullName.GetLength() - 2);
// Insert a Local network pc name to List control
if(strFullName.IsEmpty())
continue;
// 1. number
CString pcNo;
pcNo.Format("%d", m_dwCountTotalPc + 1);
m_ListSearchPc.InsertItem(m_dwCountTotalPc, pcNo);
// 2. PC name
strFullName.MakeLower();
m_ListSearchPc.SetItemText(m_dwCountTotalPc, 1, (LPCTSTR)strFullName);
m_dwCountTotalPc++;
////////////////// -->> Nothing in the ListCtl
}
}
}
delete lpBuffer;
WNetCloseEnum(hEnum);
}
WSACleanup();
}
|
|
|
|
|
Hi all,
re-posting because of no reply
I am using the RegisterHotKey() function in a dll.
RegisterHotKey(hWnd,GlobalAddAtom(buff),MOD_ATL|MOD_CONTROL|MOD_SHIFT, vkKey) ;
where vkKey is some virtual key. and buff is some char string generated using system time.
and when I try to capture this event in WM_HOTKEY, none of the combination of vkKey is working , also when i press vkKey without any combination the event is not fired.
My goal is to get notification from when vkkey is key pressed with and without combination.
Thanks in Advance.
Abhishake
|
|
|
|
|
Your code defines a single hotkey that will produce the WM_HOTKEY message when the key is pressed simultaneously with Alt, Control and Shift all held down.
You probably need to call RegisterHotKey six times: once for every combination of Alt, Control or Shift held down.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
I want that my software is not available to the user, unless the user pays for an unlock code which unleashes all the power of the software. One simple e-mail with the unlock code will be enough to deliver my full software to any part of the world.
How to do it with VC6++?
thanx.
http://www.51wit.com
|
|
|
|
|
I would assume that you would have to implement some sort of registration into your software. You would create the key that you email off to a user who then plugs it into your software. Verification and validation of that key would be part of your software.
But how would stop someone from passing that key on to another non-registered user?
One way would be to ship a dongle with your software. Hardware component you plug into a parallel port (for example), which your software reads and validates.
Another would be to create a key, based on the computer name. Then implementing code in your app that verifies whether the computer the software is running on is the same as the computer for which the key was generated.
|
|
|
|
|
to Jubjub:
I want to use hard disk serial code to create a key, but I don't how to implrment code in my app? And how to generate a key? And how to know that if software is registerd?
Do you have sample or demo?
thanx.
http://www.51wit.com
|
|
|
|
|
Hi toowit,
no I'm sorry I don't have a sample or demo, as I don't use this for any software that I wrote. I've only ever seen it used in companies that I have worked for.
Well, you'd have to come up with an algorithm to create this code based on harddisk serial code (although what happens when a client upgrade their harddisk???). I would then encrypt that based on a cryptographic key known by you and you only. You can then send that to the user via email.
The user cut-n-pastes this serial number into your application, where your application goes and gets the harddisk serial code, decrypts the serial number you sent and compares them. If they match, you can store the encrypted serial number in some location (eg registry, config file, xml file, database.. etc), for retrieval everytime you start the program.
I don't know of any code that you can just plug into your apps to get it to do this stuff. But there are a lot of article on CP, so there may be something for you. The advantage of writing this stuff yourself (ie the algorithm) is that it makes it that much harder to crack.
Jubjub
|
|
|
|
|
To Jubjub:
Great appreciation to you!
Can you tell me a lot of links or reference about this?
http://www.51wit.com
|
|
|
|
|
I don't expect you will find much code out there that you can use. It is very hard (as in phd's get it wrong all the time) to create something like this that isn't easy to break. So nobody shares their code as sometimes that is the only thing protecting them.
Read Applied Cryptography, if you read between the lines it will at least prevent you from making stupid mistakes.
Depending on how much effort you feel this is worth, you can get more and more complex. However coimplexity doesn't mean that your system is any better. Remember, the bad guys can disassemble code.
The company I work for uses the keys to allow us to ship a demo, and depending on what you buy we enable more features. However it is understood that any cracker who couldn't break our scheme isn't worth the name. We are just keeping the honest people honest.
One warning: don't make this too intrusive. I know people who buy legitimate copies of software, put it on a shelf. Then they go to the pirates and get an illegal copy that they actually run, just because the illegal copy isn't so intrusive. Harddrive keys work, but they are annoying, and belive it or not, not every system has a harddrive. (though you can likely ignore those few systems without one)
Hardware dongles are worse, some comptuers don't have USB ports. They often interfer subtilly with printers on the printer port. (or worse a non-printer device) And you have just thrown away the (small) market for people who use Wine to run your program under linux, (I'm assuming you target windows) not something you should do if you can help it. Last, the libraries to use dongles are not always bug free, in some cases your program is much less reliable just because of all the problems the dongles cause. That said, there is a time and place for a hardware dongle, if you are one use them, just beware of the downside.
|
|
|
|
|
how could I disable the function when I click escape, dialog auto close.
just like overwrite OnOk() function?
but it seems there's no OnEscape()
|
|
|
|
|
The function you are looking for is OnCancel . Add a button with the ID IDCANCEL if you don't already have one, double click it to create a handler (in MSVC++ 6.0). Remove the call to the base class OnCancel and - finally - remove the button if you don't need it (although of course not the handler )
|
|
|
|
|
hmmm, if I overwrite OnCancel function, Esc key terminating the application is disabled, but I also can't terminate the application by click the top right cross button. What I want is just disable the key meanwhile the cross button still works.
|
|
|
|
|
Then you might want to kill the keypress as early as possible, adding the virtual function PreTranslateMessage :
BOOL CSomeDlg::PreTranslateMessage(MSG* pMsg)
{
BOOL result = FALSE:
if( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE )
result = TRUE;
else
result = CDialog::PreTranslateMessage(pMsg);
return result;
}
|
|
|
|
|
yes, this is what I want, thanks
|
|
|
|
|