a ListBox issue

B

batvanio

Hi

I have a COM DLL which has a method that adds an item into a client -
provided listbox given the listbox handle (using Win32 SendMessage) -
Something like (pseudocode)

void AddItem (HWND clientHandle)
{
char sText[] = "blahblahblah";
SendMessage(clientHandle, LB_ADDSTRING, 0,(LPARAM) sText);
int iCur = SendMessage(clientHandle, LB_GETCOUNT, 0,0);
SendMessage(clientHandle, LB_SETCURSEL , iCur-1, (LPARAM) 0);
......
}

I have a C# client that has a list box on it. When I use AddItem, the
item is actually added in the listbox (I can see it). However, the
IistBox.Items.Count does not change (it is still 0) and if I try to use
something like

listbox.SelectedIndex = 0

or access the Items somehow, I get ArgumentOutOfRangeException
(because Items collection still shows no elements).

I tried different settings but with no success.

Any ideas?

Thanks.
Ivan
 
D

Dave Sexton

Hi Ivan,

If you can modify the COM dll then define an unmanaged interface that has a method called AddItem and create a managed
implementation to pass into the unmanaged AddItem method. The interface method implementation could add the item using managed code
so you don't run into your problem.

If you can't modify the COM dll then you might be out of luck seeing that the managed ListBox control apparently was not designed
for that type of usage.
 
B

batvanio

Thanks Dave,

I do have the capability to modify the com dll but so far it is a VC++
6.0 project... So the idea is to havea managed implementation of
AddItem within the COM dll? I guess I need to port it to VC 2005... I
will try this...

Thanks again,

Ivan

Dave said:
Hi Ivan,

If you can modify the COM dll then define an unmanaged interface that has a method called AddItem and create a managed
implementation to pass into the unmanaged AddItem method. The interface method implementation could add the item using managed code
so you don't run into your problem.

If you can't modify the COM dll then you might be out of luck seeing that the managed ListBox control apparently was not designed
for that type of usage.

--
Dave Sexton

Hi

I have a COM DLL which has a method that adds an item into a client -
provided listbox given the listbox handle (using Win32 SendMessage) -
Something like (pseudocode)

void AddItem (HWND clientHandle)
{
char sText[] = "blahblahblah";
SendMessage(clientHandle, LB_ADDSTRING, 0,(LPARAM) sText);
int iCur = SendMessage(clientHandle, LB_GETCOUNT, 0,0);
SendMessage(clientHandle, LB_SETCURSEL , iCur-1, (LPARAM) 0);
.....
}

I have a C# client that has a list box on it. When I use AddItem, the
item is actually added in the listbox (I can see it). However, the
IistBox.Items.Count does not change (it is still 0) and if I try to use
something like

listbox.SelectedIndex = 0

or access the Items somehow, I get ArgumentOutOfRangeException
(because Items collection still shows no elements).

I tried different settings but with no success.

Any ideas?

Thanks.
Ivan
 
D

Dave Sexton

Hi Ivan,

I meant to pass into your AddItem method the managed implementation (from your C# project) of an unmanaged interface (defined in
your VC++ project) instead of the control's handle. The interface could then expose a managed implementation of an AddItem method
that your unmanaged method could just call and pass the appropriate arguments. Make sense?

--
Dave Sexton

Thanks Dave,

I do have the capability to modify the com dll but so far it is a VC++
6.0 project... So the idea is to havea managed implementation of
AddItem within the COM dll? I guess I need to port it to VC 2005... I
will try this...

Thanks again,

Ivan

Dave said:
Hi Ivan,

If you can modify the COM dll then define an unmanaged interface that has a method called AddItem and create a managed
implementation to pass into the unmanaged AddItem method. The interface method implementation could add the item using managed
code
so you don't run into your problem.

If you can't modify the COM dll then you might be out of luck seeing that the managed ListBox control apparently was not designed
for that type of usage.

--
Dave Sexton

Hi

I have a COM DLL which has a method that adds an item into a client -
provided listbox given the listbox handle (using Win32 SendMessage) -
Something like (pseudocode)

void AddItem (HWND clientHandle)
{
char sText[] = "blahblahblah";
SendMessage(clientHandle, LB_ADDSTRING, 0,(LPARAM) sText);
int iCur = SendMessage(clientHandle, LB_GETCOUNT, 0,0);
SendMessage(clientHandle, LB_SETCURSEL , iCur-1, (LPARAM) 0);
.....
}

I have a C# client that has a list box on it. When I use AddItem, the
item is actually added in the listbox (I can see it). However, the
IistBox.Items.Count does not change (it is still 0) and if I try to use
something like

listbox.SelectedIndex = 0

or access the Items somehow, I get ArgumentOutOfRangeException
(because Items collection still shows no elements).

I tried different settings but with no success.

Any ideas?

Thanks.
Ivan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top