LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

call cvi dll(A very strange program breakdown)

It's a test system.
I use VC++ 6.0 & DLL(myCVIlib) generated by CVI 5.0.
When running the program,CVI dll will be called,and SendMessage to VC MainFrame.

There is a ListBox on the left of CMyView displaying the test items,a EditBox on the
right displaying test result(character strings from CVI) for each item.

The source code in VC is like below:

//=========================================================

typedef int (ITEMFUNC)(void);

ITEMFUNC* lpfnDllFunc1; // Function pointer
HINSTANCE hDLL; // Handle to DLL

hDLL = LoadLibrary("myCVIlib");
if ( hDLL == NULL )
{
AfxMessageBox("Cannot find CVI DLL");
return;
}

for (int i=0;i{
lpfnDllFunc1 = (I
TEMFUNC*)GetProcAddress(hDLL,itemFuncName[i]);

if (!lpfnDllFunc1)
{
AfxMessageBox("cannot find CVI DLL for this function!");
}
else
{
Ret = (*lpfnDllFunc1)();
}
}

//=========================================================

When running,if I don't click left mouse button,everything is OK.
if I click on the scrollbars,the program will hang(I mean this program interface won't
respond) at Ret = (*lpfnDllFunc1)(),elsewhere it's OK.

A very strange problem.I can't find out why.
Perhaps it's because it took too much time to update the ListBox/EditBox when I clicked.
So the execution of (*lpfnDllFunc1)() was interrupted?

Any help be appreciated!
0 Kudos
Message 1 of 5
(3,221 Views)
This might be a stupid question... But, where do you define "totalNum".
Is it something simple like its not initialised and therefore some huge value thats hanging your loop. (I told you it was a stupid question).

Its probably a global that you set outside 😞
(Since I can't see where you define the array itemFuncName[] either.

Sorry I can't be any other help.
0 Kudos
Message 2 of 5
(3,221 Views)
Hi,

I am sure "totalNum" & "itemFuncName[]" are initialized correctly,not global variables either. And it doesn't enter any loop. It just stopped at the point where the DLL was executing.Although the DLL may be executed halfway.
Since every DLL is a test function,and will return data back,I know how it breakdown.It breakdown inside the DLL,not in loop.
The key is:If I click other places,such as select a list box item,it still works smoothly.
That is,at the same time,test result of this item will be displayed in the editbox on the right of the view. Then the test continue.And click on the editbox,click on elsewhere of the view.......But as soon as I click on the scrollbar(ListBox's or EditBox's) menu,toolbar,the problem occurs.The DLL will stay at where it was.

I conjecture that such actions may need more CPU time to handle them, so the execution of the DLL was interrupted, and cannot continue.

In another version,the item test functions are not made into DLL,I call them directly through CVI ActiveX Automation Server,everything is OK.

Regards,
Lily
0 Kudos
Message 3 of 5
(3,221 Views)
Or I need to create a new thread for DLL calling?
0 Kudos
Message 4 of 5
(3,221 Views)
Yes!I've solved the problem.
It's only because the calling DLL can't be interrupted.
So I place it in another thread.It's OK now.The interface can receive message,and the DLL still running perfectly at the same time.
May this can help anybody facing the same problem.
0 Kudos
Message 5 of 5
(3,221 Views)