LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Combobox control in a DLL program

Hello,

 

In my DLL code phase, I want to using a combobox control that buit in the .fp file. There is a strange present: After creating the combobox,   using the "Combo_InsertComboItem()" to insert a text, whatever it can not show the insert, i'd like to know if this fp support the dll calling?

 

 

David

0 Kudos
Message 1 of 9
(4,580 Views)

The combobox control is in the panel is a pop-panel. I do not know if it will affect the purpose.

 

David

0 Kudos
Message 2 of 9
(4,571 Views)

David:

 

Have you checked to see if Combo_InsertComboItem returns an error?  Look at the help for Combo_InsertComboItem to see the list of errors it returns.

 

Have you checked to make sure your control ID and panel ID are correct for your popup?

 

Can you post your code?

0 Kudos
Message 3 of 9
(4,554 Views)

Hi AI,

 

The code phase likes this:

 

int function()

{

       int res;

       int impImgMataPanel;

...

 

       impImgMataPanel = LoadPanelEx (0, "imagemetaoperation.uir", ADDPANEL, __CVIUserHInst);

 

       res = Combo_NewComboBox(impImgMataPanel, ADDPANEL_IMAGETYPE);

       res = Combo_InsertComboItem(impImgMataPanel, ADDPANEL_IMAGETYPE, -1, "something");

 

...

}

 

The first res equals 27, and the second res equals zero. My OS is the  Windows 7 64-bit, and the application coding also is as 64-bit. The  panel is a popup panel in a dll program.

 

 

David

 

 

0 Kudos
Message 4 of 9
(4,549 Views)

Hi AI,

 

I am sorry, that is my mistake, I've checked the code, that is due to I forget to recompile the dll. Thanks.

 

David

0 Kudos
Message 5 of 9
(4,544 Views)

Hi AI,

 

There still exists a problem. The code phase is as following:

 

int function()

{

    impImgMataPanel = LoadPanelEx (0, "imagemetaoperation.uir", ADDPANEL, __CVIUserHInst);

 

    Combo_NewComboBox(impImgMataPanel, ADDPANEL_IMAGETYPE);
    Combo_SetComboAttribute(impImgMataPanel, ADDPANEL_IMAGETYPE, ATTR_COMBO_CTRL_COLOR, MakeColor(39,67,105));
    Combo_InsertComboItem (impImgMataPanel, ADDPANEL_IMAGETYPE, -1, "something");

 

...

    InstallCtrlCallback(impImgMataPanel, ADDPANEL_IMAGETYPE, InsertItemForComboBox, NULL);

 

...

}

 

 

int CVICALLBACK InsertItemForComboBox(int panelHandle, int controlID, int event, void *callbackData, int eventData1, int eventData2)
{
    char inputStr[61] = {'\0'};
    int index, num;
    
    
    if (event == EVENT_COMMIT)
    {
        Combo_GetComboAttribute(panelHandle, controlID, ATTR_COMBO_NUM_ITEMS, &num);
        GetCtrlVal(panelHandle, controlID, inputStr);
        Combo_GetIndexFromValue(panelHandle, controlID, &index, inputStr);    
    }
    return 0;    
}

 

In the callback function , through "Combo_GetComboAttribute()", I have got the num which equals a big number, not be  what I expect it should be 1. Please advise me what is wrong for the calling. Thanks.

 

David

0 Kudos
Message 6 of 9
(4,539 Views)

David,

 

I don't know if this is the reason why it's not working, but one thing you can't do with custom controls is to change their callback using InstallCtrlCallback, after you've converted the base control into a custom control. Custom controls work by chaining their own callbacks onto the existing callback function, using the callback chaining functions of the Programmer's Toolbox. If you then change the callback function, you are removing the custom control's callback, and you'll break the functionality of the custom control, as a result.

 

If you can't set the callback before calling NewComboBox, then use ChainCtrlCallback instead of InstallCtrlCallback to set your callback. That will allow both callback functions to work.

 

Luis

Message 7 of 9
(4,531 Views)

David:

 

As LuisG says, one possibility is just to move your call to InstallCtrlCallback() to before your call to NewComboBox().

 

Here are a couple of debugging hints.

If you had looked at the return value for Combo_GetComboAttribute(), you would have seen -45, which the help for Combo_GetComboAttribute shows to be "The control type passed was not a valid type."  That error ties into LuisG's discussion on creating custom controls.  The fix for that error isn't obvious from the error description, but it should make a little more sense with LuisG's explanation.  At least you would have known that something was wrong with the call.

If you had looked at the value of num before calling Combo_GetComboAttribute(), and then single stepped past the call to Combo_GetComboAttribute(), you would have seen that the value of num didn't change.  It's not that Combo_GetComboAttribute() returned a big number, it's that num was uninitialized and its value was not updated by Combo_GetComboAttribute() because of error -45.

0 Kudos
Message 8 of 9
(4,515 Views)

Hi Luis and AI,

 

Thank you very much! That is the crux of the problem.

 

 

David

0 Kudos
Message 9 of 9
(4,511 Views)