0 Replies - 3439 Views - Last Post: 10 January 2008 - 07:36 PM Rate Topic: -----

#1 AntiBNI  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 21-July 06

Pass string form a dll to a control?

Posted 10 January 2008 - 07:36 PM

How can i pass a string and add options to a control from within a dll?

Lets say i want to add options to a combo box from a dll,how can i do it?


and another example:


send a string to be displayed in a text box.

Heres the code:

// BitDefender Update DownloadDlg.cpp : implementation file
//

#include "stdafx.h"
#include "BitDefender Update Download.h"
#include "BitDefender Update DownloadDlg.h"
#include "Urlmon.h"
#include "windows.h"
#include "afxwin.h"
#include "shellapi.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

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

/////////////////////////////////////////////////////////////////////////////
// CBitDefenderUpdateDownloadDlg dialog

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

void CBitDefenderUpdateDownloadDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBitDefenderUpdateDownloadDlg)
	DDX_Control(pDX, IDC_COMBO1, m_version);
	DDX_Control(pDX, IDC_BUTTON1, m_download);
	DDX_Text(pDX, IDC_EDIT1, m_text);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CBitDefenderUpdateDownloadDlg, CDialog)
	//{{AFX_MSG_MAP(CBitDefenderUpdateDownloadDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBitDefenderUpdateDownloadDlg message handlers

BOOL CBitDefenderUpdateDownloadDlg::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
	m_download.LoadBitmaps(IDB_Download);
	m_download.SizeToContent();
	m_version.SetCurSel(0);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CBitDefenderUpdateDownloadDlg::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();
	}
}

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

void CBitDefenderUpdateDownloadDlg::OnButton1() 
{
int CurSel = m_version.GetCurSel();	
HRESULT hr;
switch( CurSel )
	{

case 0: m_text = "Downloading Update...";
  UpdateData(FALSE);
  hr = URLDownloadToFile(NULL,"http://download.bitdefender.com/updates/bitdefender_2008/x86/weekly.exe","BitDefender Total Security 2008 32Bit Update.exe",0,NULL);

  if ( hr == S_OK)
	  m_text = "Download Completed";
  UpdateData(FALSE);
  ShellExecute(NULL,"open","BitDefender Total Security 2008 32Bit Update.exe",NULL,NULL,SW_SHOWNORMAL);

  if (hr == E_OUTOFMEMORY)
	  m_text = "Download Failed";
  UpdateData(FALSE);

  if (hr == INET_E_DOWNLOAD_FAILURE)
	  m_text = "Download Failed";
  UpdateData(FALSE);
  exit(0);
			 break;
case 1: m_text = "Downloading Update...";
  UpdateData(FALSE);
  hr = URLDownloadToFile(NULL,"http://download.bitdefender.com/updates/bitdefender_2008/x64/weekly.exe","BitDefender Total Security 2008 64Bit Update.exe",0,NULL);

  if ( hr == S_OK)
	  m_text = "Download Completed";
  UpdateData(FALSE);
  ShellExecute(NULL,"open","BitDefender Total Security 2008 64Bit Update.exe",NULL,NULL,SW_SHOWNORMAL);

  if (hr == E_OUTOFMEMORY)
	  m_text = "Download Failed";
  UpdateData(FALSE);

  if (hr == INET_E_DOWNLOAD_FAILURE)
	  m_text = "Download Failed";
  UpdateData(FALSE);
  exit(0);
			  break;
case 2: m_text = "Downloading Update...";
  UpdateData(FALSE);
  hr = URLDownloadToFile(NULL,"http://download.bitdefender.com/updates/bitdefender_2008/x86/weekly.exe","BitDefender Internet Security 2008 32Bit Update.exe",0,NULL);

  if ( hr == S_OK)
	  m_text = "Download Completed";
  UpdateData(FALSE);
  ShellExecute(NULL,"open","BitDefender Internet Security 2008 32Bit Update.exe",NULL,NULL,SW_SHOWNORMAL);

  if (hr == E_OUTOFMEMORY)
	  m_text = "Download Failed";
  UpdateData(FALSE);

  if (hr == INET_E_DOWNLOAD_FAILURE)
	  m_text = "Download Failed";
  UpdateData(FALSE);
  exit(0);
			 break;
case 3: m_text = "Downloading Update...";
  UpdateData(FALSE);
  hr = URLDownloadToFile(NULL,"http://download.bitdefender.com/updates/bitdefender_2008/x64/weekly.exe","BitDefender Internet Security 2008 64Bit Update.exe",0,NULL);

  if ( hr == S_OK)
	  m_text = "Download Completed";
  UpdateData(FALSE);
	ShellExecute(NULL,"open","BitDefender Internet Security 2008 64Bit Update.exe",NULL,NULL,SW_SHOWNORMAL);

  if (hr == E_OUTOFMEMORY)
	  m_text = "Download Failed";
  UpdateData(FALSE);

  if (hr == INET_E_DOWNLOAD_FAILURE)
	  m_text = "Download Failed";
  UpdateData(FALSE);
  exit(0);
			 break;
case 4: m_text = "Downloading Update...";
  UpdateData(FALSE);
  hr = URLDownloadToFile(NULL,"http://download.bitdefender.com/updates/bitdefender_2008/x86/weekly.exe","BitDefender Antivirus 2008 32Bit Update.exe",0,NULL);

  if ( hr == S_OK)
	  m_text = "Download Completed";
  UpdateData(FALSE);
	ShellExecute(NULL,"open","BitDefender Antivirus 2008 32Bit Update.exe",NULL,NULL,SW_SHOWNORMAL);

  if (hr == E_OUTOFMEMORY)
	  m_text = "Download Failed";
  UpdateData(FALSE);

  if (hr == INET_E_DOWNLOAD_FAILURE)
	  m_text = "Download Failed";
  UpdateData(FALSE);
  exit(0);
			 break;
case 5: m_text = "Downloading Update...";
  UpdateData(FALSE);
  hr = URLDownloadToFile(NULL,"http://download.bitdefender.com/updates/bitdefender_2008/x64/weekly.exe","BitDefender Antivirus 2008 64Bit Update.exe",0,NULL);

  if ( hr == S_OK)
	  m_text = "Download Completed";
  UpdateData(FALSE);
  ShellExecute(NULL,"open","BitDefender Antivirus 2008 64Bit Update.exe",NULL,NULL,SW_SHOWNORMAL);

  if (hr == E_OUTOFMEMORY)
	  m_text = "Download Failed";
  UpdateData(FALSE);

  if (hr == INET_E_DOWNLOAD_FAILURE)
	  m_text = "Download Failed";
  UpdateData(FALSE);
  exit(0);
			 break;
case 6: m_text = "Downloading Update...";
  UpdateData(FALSE);
  hr = URLDownloadToFile(NULL,"http://download.bitdefender.com/updates/bitdefender_v9/weekly.exe","BitDefender Internet Security v10 Update.exe",0,NULL);

  if ( hr == S_OK)
	  m_text = "Download Completed";
  UpdateData(FALSE);
  ShellExecute(NULL,"open","BitDefender Internet Security v10 Update.exe",NULL,NULL,SW_SHOWNORMAL);

  if (hr == E_OUTOFMEMORY)
	  m_text = "Download Failed";
  UpdateData(FALSE);

  if (hr == INET_E_DOWNLOAD_FAILURE)
	  m_text = "Download Failed";
  UpdateData(FALSE);
  exit(0);
			 break;
case 7: m_text = "Downloading Update...";
  UpdateData(FALSE);
  hr = URLDownloadToFile(NULL,"http://download.bitdefender.com/updates/bitdefender_v9/weekly.exe","BitDefender Antivirus Plus v10 Update.exe",0,NULL);

  if ( hr == S_OK)
	  m_text = "Download Completed";
  UpdateData(FALSE);
  ShellExecute(NULL,"open","BitDefender Antivirus Plus v10 Update.exe",NULL,NULL,SW_SHOWNORMAL);

  if (hr == E_OUTOFMEMORY)
	  m_text = "Download Failed";
  UpdateData(FALSE);

  if (hr == INET_E_DOWNLOAD_FAILURE)
	  m_text = "Download Failed";
  UpdateData(FALSE);
  exit(0);
			 break;
case 8: m_text = "Downloading Update...";
  UpdateData(FALSE);
  hr = URLDownloadToFile(NULL,"http://download.bitdefender.com/updates/bitdefender_v9/weekly.exe","BitDefender Antivirus v10 Update.exe",0,NULL);

  if ( hr == S_OK)
	  m_text = "Download Completed";
  UpdateData(FALSE);
	ShellExecute(NULL,"open","BitDefender Antivirus v10 Update.exe",NULL,NULL,SW_SHOWNORMAL);

  if (hr == E_OUTOFMEMORY)
	  m_text = "Download Failed";
  UpdateData(FALSE);

  if (hr == INET_E_DOWNLOAD_FAILURE)
	  m_text = "Download Failed";
  UpdateData(FALSE);
  exit(0);
			 break;
case 9: m_text = "Downloading Update...";
  UpdateData(FALSE);
  hr = URLDownloadToFile(NULL,"http://download.bitdefender.com/updates/bitdefender_v9/weekly.exe","BitDefender 9 Stand-Pro Plus Update.exe",0,NULL);

  if ( hr == S_OK)
	  m_text = "Download Completed";
  UpdateData(FALSE);
	  ShellExecute(NULL,"open","BitDefender 9 Stand-Pro Plus Update.exe",NULL,NULL,SW_SHOWNORMAL);

  if (hr == E_OUTOFMEMORY)
	  m_text = "Download Failed";
  UpdateData(FALSE);

  if (hr == INET_E_DOWNLOAD_FAILURE)
	  m_text = "Download Failed";
  UpdateData(FALSE);
  exit(0);
			 break;
case 10: m_text = "Downloading Update...";
  UpdateData(FALSE);
  hr = URLDownloadToFile(NULL,"http://download.bitdefender.com/updates/bitdefender_v7/weekly.exe","BitDefender 8 Stand-Pro Plus Update.exe",0,NULL);

  if ( hr == S_OK)
	  m_text = "Download Completed";
  UpdateData(FALSE);
		ShellExecute(NULL,"open","BitDefender 8 Stand-Pro Plus Update.exe",NULL,NULL,SW_SHOWNORMAL);

  if (hr == E_OUTOFMEMORY)
	  m_text = "Download Failed";
  UpdateData(FALSE);

  if (hr == INET_E_DOWNLOAD_FAILURE)
	  m_text = "Download Failed";
  UpdateData(FALSE);
  exit(0);
			 break;

}	
}


I want to be able to update the combo box options from a dll with AddString() or some other way.
and add text to a control too.



Help will be appreciated it.
Edit/Delete Message

Is This A Good Question/Topic? 0
  • +

Page 1 of 1