Problem in correct performance of calling a dialog in a DLL(Window

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




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[i]='\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[i]=param->m_ReaderBuff[i];
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
here:(7.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

.



Relevant Pages

  • Problem in correct performance of calling a dialog in a DLL(Window
    ... I use VC++ 2008 and have two part in my project(First part: my dll project ... “Select Reader” and then select one of these substrings and send it to the ... int nPtr=0; ... static buff* pad=new buff; ...
    (microsoft.public.vc.language)
  • Problem in performance of calling a dialog in DLL(Windows programm
    ... I use VC++ 2008 and have two part in my project(First part: my dll project ... “Select Reader” and then select one of these substrings and send it to the ... int nPtr=0; ... static buff* pad=new buff; ...
    (microsoft.public.vc.mfc)
  • Re: Problem in correct performance of calling a dialog in a DLL(Window
    ... I use VC++ 2008 and have two part in my project(First part: my dll project ... “Select Reader” and then select one of these substrings and send it to the ... LPARAM lParam) ... int nPtr=0; ...
    (microsoft.public.dotnet.languages.vc)
  • Re: am having a problem with pinvoke and StringBuilder[ ]
    ... If you don't have the source of the DLL then you are in a world of pain, that means you wont be able to use the interop marshaler, you need to "custom" marshal. ... public static extern int EnumerateBoards(ref int numBoards, ... Since the String class is immutable, I have used StringBuilder in my code ...
    (microsoft.public.dotnet.framework.clr)
  • Re: am having a problem with pinvoke and StringBuilder[ ]
    ... DLL: Hello from TestLib.dll ... Since the String class is immutable, I have used StringBuilder in my code ... public static extern int EnumerateBoards(ref int numBoards, ...
    (microsoft.public.dotnet.framework.clr)