Click here to Skip to main content
15,894,405 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Exporting entry points in a dll with classes Pin
David Crow14-Mar-08 3:02
David Crow14-Mar-08 3:02 
Generalpath via property sheet Pin
john563214-Mar-08 2:46
john563214-Mar-08 2:46 
QuestionChrash at UpdateData(FALSE) Pin
merh14-Mar-08 2:45
merh14-Mar-08 2:45 
GeneralRe: Chrash at UpdateData(FALSE) Pin
Cedric Moonen14-Mar-08 3:03
Cedric Moonen14-Mar-08 3:03 
QuestionRe: Chrash at UpdateData(FALSE) Pin
merh14-Mar-08 3:14
merh14-Mar-08 3:14 
GeneralRe: Chrash at UpdateData(FALSE) Pin
jhwurmbach14-Mar-08 3:51
jhwurmbach14-Mar-08 3:51 
AnswerRe: Chrash at UpdateData(FALSE) Pin
bert_r14-Mar-08 3:20
bert_r14-Mar-08 3:20 
QuestionRe: Chrash at UpdateData(FALSE) Pin
merh14-Mar-08 4:15
merh14-Mar-08 4:15 
First of all thanks a lot.
It dosent work. I have the following interface

you mentioned that I could use pDlg->PostMessage(WMU_SETVALUE1, (WPARAM)i,(LPARAM)b);
where is comming pDlg? I have got error at CWnd * pDlg = (pDlg*)lpParam; and pDlg->PostMessage(WMU_SETVALUE1, (WPARAM)i,(LPARAM)b);

I have copied all files maybe you can see my problem better
Thanks
M.h


// ThreadDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Thread.h"
#include "ThreadDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#ifndef GLOGAL
#define GLOBAL

int Globalvariable;

#endif


class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CThreadDlg dialog

CThreadDlg::CThreadDlg(CWnd* pParent /*=NULL*/)
: CDialog(CThreadDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CThreadDlg)
m_Value1 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CThreadDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CThreadDlg)
DDX_Text(pDX, IDC_VALUE1, m_Value1);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CThreadDlg, CDialog)
//{{AFX_MSG_MAP(CThreadDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_MESSAGE(WMU_SETVALUE1,OnSetValue1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CThreadDlg message handlers

BOOL CThreadDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
Thread1 *pThread = new Thread1(this);


return TRUE; // return TRUE unless you set the focus to a control
}

LRESULT CSurveyUpdateDlg::OnSetValue1(WPARAM wParam, LPARAM lParam)
{ setValueAlt1((int)wParam, (int)lParam);
}


void CThreadDlg::setValueAlt1(int inValue1, int invalue2)
{
m_Value1.Format("%.3d", inValue1);
UpdateData(FALSE);
}

void CThreadDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}


void CThreadDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
void CThreadDlg::setValueAlt1(int inValue1, int invalue2)
{
CThreadDlg::PostMessage(WMU_SETVALUE1, (WPARAM)inValue1,(LPARAM)invalue2);
/*m_Value1.Format("%.3d", inValue1);
UpdateData(FALSE);*/
}



// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CThreadDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}



ThreadDlg.h
// ThreadDlg.h : header file
//

#if !defined(AFX_THREADDLG_H__5BBFDBD6_3EF8_4FD2_8DAD_0C3E22DD797B__INCLUDED_)
#define AFX_THREADDLG_H__5BBFDBD6_3EF8_4FD2_8DAD_0C3E22DD797B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ISetValue.h"
#include "Thread1.h"

#define WMU_SETVALUE1 (WM_USER+1)


/////////////////////////////////////////////////////////////////////////////
// CThreadDlg dialog

class CThreadDlg : public CDialog, ISetValue
{
// Construction
public:
CThreadDlg(CWnd* pParent = NULL); // standard constructor
void setValueAlt1(int inValue1, int invalue2);
void setValueAlt2(int inValue1, int invalue2);

afx_msg void OnTimer(UINT nIDEvent);
CTime tmeSet;
HANDLE hEvent1 ;


// Dialog Data
//{{AFX_DATA(CThreadDlg)
enum { IDD = IDD_THREAD_DIALOG };
CString m_Value1;
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CThreadDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
HICON m_hIcon;

// Generated message map functions
//{{AFX_MSG(CThreadDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg LRESULT OnSetValue1(WPARAM wParam, LPARAM lParam);

//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_THREADDLG_H__5BBFDBD6_3EF8_4FD2_8DAD_0C3E22DD797B__INCLUDED_)

IsetValue.h

#ifndef _test_
#define _test_
//#include <afx.h>

class ISetValue {
public:

//Backend sends the value to GUI
virtual void setValueAlt1(int value1, int value2) = 0; // set value

};

#endif

//////////////////////////////////////////////////
//
// CPaApp.cpp: implementation of the CPaApp class.
//
//

#include "stdafx.h"
#include "Thread1.h"
#include <stdio.h>
//#include "CPaPort.h"







//////////////////////////////////////////////////////////////////////
// Other Member Functions
//////////////////////////////////////////////////////////////////////

#include <windows.h>
#include <conio.h>


static int TestNum = 0;
int PaAppTestNum = 0;


DWORD WINAPI ThreadFunc( LPVOID lpParam )
{
CWnd * pDlg = (pDlg*)lpParam;
int a=44;
int b = 45;
for (int i=40; i<100; i++)
{
pDlg->PostMessage(WMU_SETVALUE1, (WPARAM)i,(LPARAM)b);
Sleep(10);
}
return 0;

}


Thread1.CPP

// set port address
Thread1::Thread1(CDialog *pISetValue)
{


DWORD dwThreadId;
HANDLE hThread;

LPVOID param = pISetValue;
m_pISetValue = pISetValue;


//pISetValue->setValueAlt1(44, 99);
//return;

hThread = CreateThread(
NULL, // no security attributes
0, // use default stack size
ThreadFunc, // thread function
param, // argument to thread function
0, // use default creation flags
&dwThreadId); // returns the thread identifier

}

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000



#include "ISetValue.h"


Thread.h

class Thread1
{

protected:

public:
//Thread1(ISetValue *pISetValue);
Thread1(CDialog *pISetValue);

virtual ~Thread1(){};


private:
//ISetValue * m_pISetValue;
//ISetValue *pISetValue;
ISetValue* m_pISetValue;
ISetValue *pISetValue;
};
AnswerRe: Chrash at UpdateData(FALSE) Pin
bert_r14-Mar-08 4:54
bert_r14-Mar-08 4:54 
GeneralRe: Chrash at UpdateData(FALSE) Pin
merh14-Mar-08 5:03
merh14-Mar-08 5:03 
GeneralRe: Crash at UpdateData(FALSE) Pin
bert_r14-Mar-08 5:19
bert_r14-Mar-08 5:19 
GeneralRe: Crash at UpdateData(FALSE) Pin
merh14-Mar-08 5:40
merh14-Mar-08 5:40 
GeneralRe: Chrash at UpdateData(FALSE) Pin
David Crow14-Mar-08 5:41
David Crow14-Mar-08 5:41 
GeneralRe: Chrash at UpdateData(FALSE) Pin
merh14-Mar-08 5:51
merh14-Mar-08 5:51 
GeneralRe: Chrash at UpdateData(FALSE) Pin
merh14-Mar-08 6:15
merh14-Mar-08 6:15 
GeneralRe: Chrash at UpdateData(FALSE) Pin
David Crow14-Mar-08 6:16
David Crow14-Mar-08 6:16 
Questioncan anybody tell me how i can call a vb activex dll from c++ Pin
philiptabraham14-Mar-08 1:29
philiptabraham14-Mar-08 1:29 
AnswerRe: can anybody tell me how i can call a vb activex dll from c++ Pin
ritz123414-Mar-08 1:39
ritz123414-Mar-08 1:39 
AnswerRe: can anybody tell me how i can call a vb activex dll from c++ Pin
Nathan Holt at EMOM14-Mar-08 6:22
Nathan Holt at EMOM14-Mar-08 6:22 
AnswerRe: can anybody tell me how i can call a vb activex dll from c++ Pin
CPallini14-Mar-08 11:02
mveCPallini14-Mar-08 11:02 
QuestionProblem in using Fromhandle Function Pin
ashtwin14-Mar-08 0:44
ashtwin14-Mar-08 0:44 
AnswerRe: Problem in using Fromhandle Function [modified] Pin
Rajkumar R14-Mar-08 2:19
Rajkumar R14-Mar-08 2:19 
GeneralRe: Problem in using Fromhandle Function Pin
ashtwin16-Mar-08 19:47
ashtwin16-Mar-08 19:47 
GeneralRe: Problem in using Fromhandle Function Pin
Rajkumar R16-Mar-08 20:49
Rajkumar R16-Mar-08 20:49 
QuestionRe: Problem in using Fromhandle Function Pin
ashtwin16-Mar-08 21:03
ashtwin16-Mar-08 21:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.