isidore Invité
![un ptit souci de pointeur, sous visual c++ Empty](https://2img.net/i/empty.gif) | Sujet: un ptit souci de pointeur, sous visual c++ Sam 13 Mai à 7:33 | |
| Bonjour j'ai un projet sans erreur de compil mais il ne fait pas ce que je veux parce qu'il n'a qu'une ligne que je n'arirve pas à définir correctement. je ne sias pas comment déclarer le pointeur ou le mettre en place. c'est cette fonction - Code:
-
HDDEDATA DdeClientTransaction( // aide msdn
LPBYTE pData, // là je bloque DWORD cbData, HCONV hConv, HSZ hszItem, UINT wFmt, UINT wType, DWORD dwTimeout, LPDWORD pdwResult ); j'ai une case IDC_EDIT1 avec une valeur "m_Val" de type CString. je veux envoyer une donnée pour écriture sur un serveur dans une case de valeur "Value" de type CString. dans mon programme client, j'ai mis donc le code suivant correspondant au bouton (tout à la fin) - Code:
-
Item=DdeCreateStringHandle ( pidInst, m_Item, CP_WINANSI );
DdeClientTransaction ( (LPBYTE)(LPCTSTR)ItemValue, // bloqué strlen(ItemValue)+1, hconv, Item, (UINT) CF_TEXT, (UINT) XTYP_POKE, (DWORD) 1000, NULL ); DdeFreeStringHandle(pidInst, Item);
et j'ai mis tout en haut en globale dans mon programme char ItemValue[50]="m_Val"; ==> aucune erreur de compil, dans mon projet je reçois des valeur mais ne peux en envoyer, pourriez vous me dire comment je pourrai envoyer la valeur de la case sur le serveur, cad comment faire que la valeur soit pointée par un pointeur ItemValue je me suis aidé de cette page pour faire mon programme : http://support.microsoft.com/default.aspx?scid=kb%3Bfr%3B279721 je n'utilise pas d'excel, c 2 exécutables. et c des MFC sous visual c++ voilà Je vous remercie d'avance pour votre aide.--------------------------------------------------- je laisse qd meme le code entier si nécessaire - Code:
-
// client : m_Val, m_Double, m_Triple et serveur : Value, Double, Triple // nav_clientDlg.cpp : implementation file //
#include "stdafx.h" #include "nav_client.h" #include "nav_clientDlg.h" #include <ddeml.h> // rajout
#include <time.h> #include <windows.h>
#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif
//déclaration de la fonction callback HDDEDATA CALLBACK DdeCallback( UINT uType, // transaction type UINT uFmt, // clipboard data format HCONV hconv, // handle to the conversation HSZ hsz1, // handle to a string HSZ hsz2, // handle to a string HDDEDATA hdata, // handle to a global memory object DWORD dwData1, // transaction-specific data DWORD dwData2 // transaction-specific data );
DWORD pidInst;
PFNCALLBACK pfnCallback;
HSZ Item,Topic,Service; HDDEDATA hData; HCONV hconv;
DWORD size; PSTR psz;
char ItemValue[50]="m_Val"; //////////////// m_Val?
///////////////////////////////////////////////////////////////////////////// // 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()
///////////////////////////////////////////////////////////////////////////// // CNav_clientDlg dialog
CNav_clientDlg::CNav_clientDlg(CWnd* pParent /*=NULL*/) : CDialog(CNav_clientDlg::IDD, pParent) { //{{AFX_DATA_INIT(CNav_clientDlg) m_Item = _T("Value"); m_Service = _T("DdeServ"); m_Topic = _T("Info"); m_Double = _T(""); m_Triple = _T(""); m_Val = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); }
void CNav_clientDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CNav_clientDlg) DDX_Text(pDX, IDC_EDIT4, m_Item); DDX_Text(pDX, IDC_EDIT6, m_Service); DDX_Text(pDX, IDC_EDIT5, m_Topic); DDX_Text(pDX, IDC_EDIT2, m_Double); DDX_Text(pDX, IDC_EDIT3, m_Triple); DDX_Text(pDX, IDC_EDIT1, m_Val); //}}AFX_DATA_MAP }
BEGIN_MESSAGE_MAP(CNav_clientDlg, CDialog) //{{AFX_MSG_MAP(CNav_clientDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1) ON_BN_CLICKED(IDC_BUTTON3, OnButton3) ON_BN_CLICKED(IDC_BUTTON5, OnButton5) ON_BN_CLICKED(IDC_BUTTON2, OnButton2) ON_EN_CHANGE(IDC_EDIT4, OnChangeEdit4) ON_BN_CLICKED(IDC_BUTTON6, OnButton6) //}}AFX_MSG_MAP END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////// // CNav_clientDlg message handlers
BOOL CNav_clientDlg::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 return TRUE; // return TRUE unless you set the focus to a control }
void CNav_clientDlg::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 CNav_clientDlg::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 CNav_clientDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; }
void CNav_clientDlg::OnCancel() { // TODO: Add extra cleanup here CDialog::OnCancel(); }
void CNav_clientDlg::OnChangeEdit1() { // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. // TODO: Add your control notification handler code here }
void CNav_clientDlg::OnButton3() { // TODO: Add your control notification handler code here DdeInitialize ( &pidInst, (PFNCALLBACK) pfnCallback, (DWORD) (APPCMD_CLIENTONLY | APPCLASS_STANDARD), (DWORD) 0 // ou alors (DWORD) ulRes; ici ET avec DWORD ulRes=NULL; en globale en haut du fichier // à la place du null je pouvais mettre (DWORD) 0 vu que le prog attention un dword ici );
Service=DdeCreateStringHandle ( pidInst, m_Service, CP_WINANSI );
Topic=DdeCreateStringHandle ( pidInst, m_Topic, CP_WINANSI );
Item=DdeCreateStringHandle ( pidInst, m_Item, CP_WINANSI );
hconv=DdeConnect ( pidInst, Service, Topic, NULL );
DdeFreeStringHandle(pidInst, Service); // libere handle de string DdeFreeStringHandle(pidInst, Topic); DdeFreeStringHandle(pidInst, Item);
}
void CNav_clientDlg::OnButton5() { // TODO: Add your control notification handler code here
/*hData=DdeCreateDataHandle(pidInst,(LPBYTE)(LPCTSTR)m_Val, strlen(m_Val)+1, 0, NULL, CF_TEXT, 0);*/ // request double Item=DdeCreateStringHandle ( pidInst, m_Item = _T("Double"), CP_WINANSI );
hData=DdeClientTransaction ( (LPBYTE) NULL, (DWORD) 0, hconv, Item, (UINT) CF_TEXT, (UINT) XTYP_REQUEST, (DWORD) 1000, (LPDWORD) NULL );
psz=(PSTR)LocalAlloc( LPTR, // allocation attributes size+1 // number of bytes to allocate // pour le caractère de fin de chaine ); DdeGetData( hData, // handle to DDE object (LPBYTE)psz, // pointer to destination buffer 150, // amount of data to copy 0 // offset to beginning of data ); DdeFreeStringHandle(pidInst, Item); UpdateData (true); m_Double=psz; UpdateData (false);
// request triple Item=DdeCreateStringHandle ( pidInst, m_Item = _T("Triple"), CP_WINANSI );
hData=DdeClientTransaction ( (LPBYTE) NULL, (DWORD) 0, hconv, Item, (UINT) CF_TEXT, (UINT) XTYP_REQUEST, (DWORD) 1000, (LPDWORD) NULL );
psz=(PSTR)LocalAlloc( LPTR, // allocation attributes size+1 // number of bytes to allocate // pour le caractère de fin de chaine ); DdeGetData( hData, // handle to DDE object (LPBYTE)psz, // pointer to destination buffer 150, // amount of data to copy 0 // offset to beginning of data ); DdeFreeStringHandle(pidInst, Item);
UpdateData (true); m_Triple=psz; UpdateData (false);
}
void CNav_clientDlg::OnButton2() { // TODO: Add your control notification handler code here
DdeDisconnect(hconv); DdeUninitialize(pidInst); //DdeFreeDataHandle(hData); }
void CNav_clientDlg::OnChangeEdit4() { // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. // TODO: Add your control notification handler code here }
void CNav_clientDlg::OnButton6() { // TODO: Add your control notification handler code here
Item=DdeCreateStringHandle ( pidInst, m_Item, CP_WINANSI );
DdeClientTransaction ( (LPBYTE)(LPCTSTR)ItemValue, strlen(ItemValue)+1, hconv, Item, (UINT) CF_TEXT, (UINT) XTYP_POKE, (DWORD) 1000, NULL ); DdeFreeStringHandle(pidInst, Item);
}
|
|
Invité Invité
![un ptit souci de pointeur, sous visual c++ Empty](https://2img.net/i/empty.gif) | Sujet: Re: un ptit souci de pointeur, sous visual c++ Sam 13 Mai à 16:24 | |
| j'ai trouvé qqch : char* ItemValue=(char*)LPCTSTR(m_Val);
le souci est qu'il prend uniquement une valeur prédéfinie m_Val = _T("5"); DDX_Text(pDX, IDC_EDIT1, m_Val); ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1) ==> au démarrage il y a une case préremplie avec une valeur de 5 moi je démarre le programme je met une valeur de 7 ou 8 ou 2 ou 10, c moi qui choisit et je veux l'envoyer or mon programme ne prend que la valeur prédéfinie. m_Val est de type class CString
en fait je chercher à récupérer cette valeur modifiée dans IDC_EDIT1 (une case genre Edit Box)
j'iamerai votre aide sur la mise en place des fonctions suivante qui me seront utiles je pense. hItemValue = GetDlgItem(hWnd, IDC_EDIT1); et/ou un GetWindowText(hItemValue,pDDE.ItemValue,500);
ou si vous savez comment faire pour récupérer cette valeur modifiée dans IDC_EDIT1
Merci |
|
FVIRTMAN Admin
![FVIRTMAN](https://2img.net/u/1612/42/45/74/avatars/1-95.jpg)
Nombre de messages : 78 Date d'inscription : 11/11/2005
![un ptit souci de pointeur, sous visual c++ Empty](https://2img.net/i/empty.gif) | Sujet: Re: un ptit souci de pointeur, sous visual c++ Dim 4 Juin à 14:17 | |
| Je suis désolé de ne pas avoir répondu plus tot : je n'ai pas eu le courage de lire ce long message. Content que tu aies trouvé ! ![Very Happy](https://2img.net/i/fa/i/smiles/icon_biggrin.png) | |
|