// JP opened flex table

Click to See Complete Forum and Search --> : [RESOLVED] Accessing the Interface list box from Dll


Suresh.hc
February 13th, 2007, 07:07 AM
Hello All,


I have a win 32 application connected to dll file.

In the Win 32 Interface I am accessing the Dll file, I am passing some folder name to dll which lists some file names , now I want to add those file name to List Box present in the interface.

Can anyone please help me with me with this, I have attached the Demo project which has interface and a dll file which contains the function.

Thanking you,
Suresh HC.

Suresh.hc
February 14th, 2007, 12:46 AM
Hello Guys , anyone please Help me …..plz give some solution ….
I am not able to find any notes or any examples to do this ….

alex_gusev
February 14th, 2007, 06:23 AM
you have 2 possibilities:

1) pass hwnd of the listbox to ListFiles() function and add all in there
2) use some buffer to be filled in ListFiles() and then all entrie will be added to the listbox in main app

Suresh.hc
February 14th, 2007, 06:29 AM
Thank you Alex for the response.

For me option 1 looks good, can u please tell me how I have to pass the hwnd and how I have to receive in dll.
Please give an example …. It will be very helpful. like Declaring hwnd in ListFiles function in dll etc …

alex_gusev
February 14th, 2007, 06:35 AM
well, I have build MFC test for that in stead of Win32 app, but regardless to it you may change your interface parameters in ListFiles(), i.e. define it as


DECLARE_INTERFACE_(IMyMath,IUnknown)
{
STDMETHOD_(void,ListFiles) (char *dir, HWND hwndListBox) PURE;
};


and when you call ListFiles(), you can pass a handle of ListBox window, getting it via GetDlgItem() call. Just save a handle of your dialog when you create it to use it later.

In ListFile() you might use it as


if ( ::IsWindow(hwndListBox) )
{
::SendMessage(hwndListBox, LB_ADDSTRING, 0, (LPARAM)name);
}

Suresh.hc
February 14th, 2007, 07:00 AM
Hi Alex,
I did changes as u said , no errors but I am not getting any out put. Please tell what changes I have to make.

In Dll

// Use IMyMath interface

HWND HLB = GetDlgItem(hwnd,IDC_LIST);
pMath->ListFiles(szDir,HLB);


interface declaration

DECLARE_INTERFACE_(IMyMath,IUnknown)
{
STDMETHOD_(void,ListFiles) (char *dir, HWND HLB) PURE;
};


ListFiles() function

STDMETHODIMP_ (void)
CMyMath::XMyMathObj::ListFiles (char *dir,HWND HLB)
//void CMyAsis::ListFiles (char *dir) {
{

struct _finddata_t file_s;
long File_handle;
char name[MAX_LEN];

_chdir(dir);

if( (File_handle = _findfirst( "*", &file_s )) == -1L ) {
printf( "No files in current directory!\n" );
}
else if (file_s.attrib & _A_NORMAL){
sprintf (name, "%s",dir);
printf("\n%s",name);

if ( ::IsWindow(HLB) )
{
::SendMessage(HLB, LB_ADDSTRING, 0, (LPARAM)name);
}

alex_gusev
February 14th, 2007, 07:41 AM
that's my ListFiles() function:


STDMETHODIMP_ (void)
CMyMath::XMyMathObj::ListFiles (char *dir,HWND hwndListBox)
//void CMyAsis::ListFiles (char *dir) {
{
struct _finddata_t file_s;
long File_handle;
char name[MAX_LEN];

_chdir(dir);

if( (File_handle = _findfirst( "*", &file_s )) == -1L ) {
printf( "No files in current directory!\n" );
}
else if (file_s.attrib & _A_NORMAL){
sprintf (name, "%s",dir);
printf("\n%s",name);
}
else {
do {
if (strcmp (file_s.name, ".") == 0 || strcmp (file_s.name, "..") == 0)
continue;
if (strlen (dir) + strlen (file_s.name) + 2 > sizeof (name)) {
fprintf (stderr, "Dir name too long\n");
return;
}

if (file_s.attrib & _A_SUBDIR) {
sprintf (name, "%s/%s",dir, file_s.name);
printf("\n%s",name);
if ( ::IsWindow(hwndListBox) )
{
::SendMessage(hwndListBox, LB_ADDSTRING, 0, (LPARAM)name);
}
ListFiles(name,hwndListBox);
}
else
{
sprintf (name, "%s/%s",dir ,file_s.name);
printf("\n%s",name);
if ( ::IsWindow(hwndListBox) )
{
::SendMessage(hwndListBox, LB_ADDSTRING, 0, (LPARAM)name);
}
}
} while (_findnext (File_handle, &file_s) == 0);
}
}


it looks like you simply haven't added a code for ListBox AddString to all your blocks

Suresh.hc
February 14th, 2007, 08:11 AM
Cool Its working Thank you Alex very much.

//JP added flex table