C
creative22
Hello guys!
I have a MFC program called “Tester†in which a function (Secondfunction) of
a dll is called;
I use VC++ 2008 and have two part in my project(First part: my dll project
named
†DlgInDLL†which includes dll source (dll1.cpp) Second part: my Tester
“MFC type projectâ€)
First, in “Tester†I push “Secondfunction†button and then the corresponding
function in dll, will be called;
Inside “Secondfunction†function, I call a dialog procedure named
“SecondDlgProcâ€;
I send a structure including a string buffer and it’s size, through final
argument of “DialogBoxParam†and in the procedure, parse this string into 3
substrings and add to a “ComboBox†control belonging to dll’s dialog named
“Select Reader†and then select one of these substrings and send it to the
“Secondfunctionâ€,….
Once I push “Secondfunction†button in “Testerâ€, I see good result and
“Select Reader†is appeared and I select one the substrings and works fine!
But, when I press “Secondfunction†button again(In run time!), substrings
won’t be added to “ComboBoxâ€!!!
I put my code( Dialog procedure + Secondfunction) below,
I debug my program and in Second call of “Secondfunctionâ€, I see the string
buffer is parsed correctly, but I don’t know why won’t substrings be added to
ComboBox in Second time?!!
Because the debugger doesn’t give clear information in this case to me!!
I, myself, think the problem is from this line, but I don’t know why:
SendMessage (hwndComboBox, CB_INSERTSTRING, p, (LPARAM) Reader1) ;
The codes:
BOOL CALLBACK SecondDlgProc(HWND hwndDlg,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
HWND hwndComboBox ;
hwndComboBox = GetDlgItem(hwndDlg, IDC_COMBO1);
TCHAR* Reader=new TCHAR[30];
static TCHAR * pReaderName;
int nPtr=0;
//counter
int n=0,i=0;
int a=0,iIndex;
static int iLength;
static buff* pad=new buff ;
switch (message)
{
case WM_INITDIALOG:
pad = (buff *) lParam ;
SendMessage (hwndComboBox, LB_RESETCONTENT, 0, 0) ;// clear contents of
the combobox;
while(pad->m_ReaderBuff[nPtr] != '\0')
{
Reader[0] = '\0';
while(pad->m_ReaderBuff[nPtr] != '\0')
{
Reader[nPtr-n]=pad->m_ReaderBuff[nPtr];
nPtr++;
i++;
} // while do
nPtr++;
n=++nPtr;
TCHAR* Reader1;
Reader1=new TCHAR[i+1];
for(int k=0;k<i;k++)
Reader1[k]=Reader[k];
Reader1='\0';
i=0;
static int p=0;
SendMessage (hwndComboBox, CB_INSERTSTRING, p, (LPARAM) Reader1) ;
delete[]Reader1;
p++;
}// while do
case WM_COMMAND:
if (LOWORD (wParam) == IDC_COMBO1 && HIWORD (wParam) == LBN_SELCHANGE)
{
// Get current selection.
iIndex = SendMessage (hwndComboBox, CB_GETCURSEL, 0, 0) ;
iLength = SendMessage (hwndComboBox, CB_GETLBTEXTLEN, iIndex, 0) + 1 ;
pReaderName =new TCHAR[iLength];
SendMessage (hwndComboBox, CB_GETLBTEXT, iIndex, (LPARAM) pReaderName)
;
}
if(LOWORD (wParam) == IDOK)
{
pad->m_ReaderBuff=new TCHAR[pad->size];
pad->m_ReaderBuff[0]='\0';
while(pReaderName[a]!='\0')
{
pad->m_ReaderBuff[a] = pReaderName[a] ;
a++;
}
pad->m_ReaderBuff[a]='\0';
pad->size=iLength;
delete[] pReaderName;
EndDialog (hwndDlg, TRUE) ;
return TRUE ;
}
if(LOWORD (wParam) == IDCANCEL)
{
EndDialog (hwndDlg, FALSE) ;
return TRUE ;
}
break;
}
return FALSE;
}
EXPORT void WINAPI SecondFunction(){
buff* param=new buff;
param->size=46;
param->m_ReaderBuff=L"ACS READER 0 \0 ACS READER 1 \0 ACS READER 2 \0 \0";
TCHAR szBuffer[100];
if(DialogBoxParam (g_hModule, MAKEINTRESOURCE(IDD_DIALOG2),
NULL, SecondDlgProc, (LPARAM) param))
{
TCHAR* reader=new TCHAR[param->size];
for(int i=0;i<param->size;i++)
reader=param->m_ReaderBuff;
wsprintf (szBuffer, TEXT ("The value of reader is %s."), reader) ;
MessageBox(NULL,szBuffer,L"Note",MB_OKCANCEL);
delete[]reader;
delete param;
MessageBox(NULL,L"The Second Function Succeeded.",NULL,0);
}
else
MessageBox(NULL,L"The Second Function Failed.",NULL,0);
}
I also have Uploaded my project in a host server and it’s link address is
here7.36 MB)
http://www.ziddu.com/download/5307424/DlgInDLL.rar.html
Could I ask you tell me what the problem is with this code?
Any help would be greatly appreciated,
I need so help, Please help me!!
Creative22
I have a MFC program called “Tester†in which a function (Secondfunction) of
a dll is called;
I use VC++ 2008 and have two part in my project(First part: my dll project
named
†DlgInDLL†which includes dll source (dll1.cpp) Second part: my Tester
“MFC type projectâ€)
First, in “Tester†I push “Secondfunction†button and then the corresponding
function in dll, will be called;
Inside “Secondfunction†function, I call a dialog procedure named
“SecondDlgProcâ€;
I send a structure including a string buffer and it’s size, through final
argument of “DialogBoxParam†and in the procedure, parse this string into 3
substrings and add to a “ComboBox†control belonging to dll’s dialog named
“Select Reader†and then select one of these substrings and send it to the
“Secondfunctionâ€,….
Once I push “Secondfunction†button in “Testerâ€, I see good result and
“Select Reader†is appeared and I select one the substrings and works fine!
But, when I press “Secondfunction†button again(In run time!), substrings
won’t be added to “ComboBoxâ€!!!
I put my code( Dialog procedure + Secondfunction) below,
I debug my program and in Second call of “Secondfunctionâ€, I see the string
buffer is parsed correctly, but I don’t know why won’t substrings be added to
ComboBox in Second time?!!
Because the debugger doesn’t give clear information in this case to me!!
I, myself, think the problem is from this line, but I don’t know why:
SendMessage (hwndComboBox, CB_INSERTSTRING, p, (LPARAM) Reader1) ;
The codes:
BOOL CALLBACK SecondDlgProc(HWND hwndDlg,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
HWND hwndComboBox ;
hwndComboBox = GetDlgItem(hwndDlg, IDC_COMBO1);
TCHAR* Reader=new TCHAR[30];
static TCHAR * pReaderName;
int nPtr=0;
//counter
int n=0,i=0;
int a=0,iIndex;
static int iLength;
static buff* pad=new buff ;
switch (message)
{
case WM_INITDIALOG:
pad = (buff *) lParam ;
SendMessage (hwndComboBox, LB_RESETCONTENT, 0, 0) ;// clear contents of
the combobox;
while(pad->m_ReaderBuff[nPtr] != '\0')
{
Reader[0] = '\0';
while(pad->m_ReaderBuff[nPtr] != '\0')
{
Reader[nPtr-n]=pad->m_ReaderBuff[nPtr];
nPtr++;
i++;
} // while do
nPtr++;
n=++nPtr;
TCHAR* Reader1;
Reader1=new TCHAR[i+1];
for(int k=0;k<i;k++)
Reader1[k]=Reader[k];
Reader1='\0';
i=0;
static int p=0;
SendMessage (hwndComboBox, CB_INSERTSTRING, p, (LPARAM) Reader1) ;
delete[]Reader1;
p++;
}// while do
case WM_COMMAND:
if (LOWORD (wParam) == IDC_COMBO1 && HIWORD (wParam) == LBN_SELCHANGE)
{
// Get current selection.
iIndex = SendMessage (hwndComboBox, CB_GETCURSEL, 0, 0) ;
iLength = SendMessage (hwndComboBox, CB_GETLBTEXTLEN, iIndex, 0) + 1 ;
pReaderName =new TCHAR[iLength];
SendMessage (hwndComboBox, CB_GETLBTEXT, iIndex, (LPARAM) pReaderName)
;
}
if(LOWORD (wParam) == IDOK)
{
pad->m_ReaderBuff=new TCHAR[pad->size];
pad->m_ReaderBuff[0]='\0';
while(pReaderName[a]!='\0')
{
pad->m_ReaderBuff[a] = pReaderName[a] ;
a++;
}
pad->m_ReaderBuff[a]='\0';
pad->size=iLength;
delete[] pReaderName;
EndDialog (hwndDlg, TRUE) ;
return TRUE ;
}
if(LOWORD (wParam) == IDCANCEL)
{
EndDialog (hwndDlg, FALSE) ;
return TRUE ;
}
break;
}
return FALSE;
}
EXPORT void WINAPI SecondFunction(){
buff* param=new buff;
param->size=46;
param->m_ReaderBuff=L"ACS READER 0 \0 ACS READER 1 \0 ACS READER 2 \0 \0";
TCHAR szBuffer[100];
if(DialogBoxParam (g_hModule, MAKEINTRESOURCE(IDD_DIALOG2),
NULL, SecondDlgProc, (LPARAM) param))
{
TCHAR* reader=new TCHAR[param->size];
for(int i=0;i<param->size;i++)
reader=param->m_ReaderBuff;
wsprintf (szBuffer, TEXT ("The value of reader is %s."), reader) ;
MessageBox(NULL,szBuffer,L"Note",MB_OKCANCEL);
delete[]reader;
delete param;
MessageBox(NULL,L"The Second Function Succeeded.",NULL,0);
}
else
MessageBox(NULL,L"The Second Function Failed.",NULL,0);
}
I also have Uploaded my project in a host server and it’s link address is
here7.36 MB)
http://www.ziddu.com/download/5307424/DlgInDLL.rar.html
Could I ask you tell me what the problem is with this code?
Any help would be greatly appreciated,
I need so help, Please help me!!
Creative22