10-21-2009 10:01 PM - edited 10-21-2009 10:04 PM
Hello Everyone,
I have created a DLL in VB, it includes a very simple function as follows:
Public Function mathadd(ByVal a As Integer, ByVal b As Integer) As Integer
mathadd = a + b
End Function
I want to call it in cvi ,so I made its instrument driver through ActiveX controller winzard in CVI,Then the function turn into
the prototype in panel function :
HRESULT dll__Class1mathadd (CAObjHandle Object_Handle,
ERRORINFO *Error_Info, short A,
short B, short *Arg3);
my first question is :Why its Parameter Type changed in CVI,and it has no short Parameter Type in CVI ,can i use short int instead of short?
second question :what is the function of the third Parameter short *Arg3 ?I don't understand it..
the last is : I call it in CVI as follows#include <cvirte.h>
#include <userint.h>
#include "s.h"
#include "dll.h"
static int panelHandle;
static CAObjHandle objectHandle;
short A;
short B;
short *C;
short D;
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "s.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int CVICALLBACK ADD (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal(panelHandle,PANEL_NUM1,&A);
GetCtrlVal(panelHandle,PANEL_NUM2,&B);
D= dll__Class1mathadd (objectHandle, NULL, A, B, C);
SetCtrlVal(panelHandle,PANEL_SUM,&C);
break;
}
return 0;
}
int CVICALLBACK Quit (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
},
when it runned ,the error as follows appeared:
Function CA_GetInterfaceFromObjHandle:(return value==-2147024890[0x80070006] The handle is invalid.
Who can help me to solve it ?
10-22-2009 02:29 AM
first question: the parameter type is not changed. a VB6 "Integer" is 16 bits wide, so it maps to a "short int" in C. using only "short" should work just fine, it should be understood by the compiler as "short int".
second question: ActiveX controls and their technological parents, COM and OLE objects, use the return value of a function to signal errors, so the return value is not available. instead, the return value is passed by reference in the last argument. the value set in the line "mathadd = a + b" will be written at the address specified in the "Arg3" parameter.
this leads us to your code. you should write:
short A, B, C;
HRESULT D;
[...]
D = dll__Class1mathadd (objectHandle, NULL, A, B, &C);
now D contains the status of the function call: did it succeed ? was there an error with the ActiveX control ? etc.
and C contains the result of the function.
(for your very last question, i don't know the answer...)
10-22-2009 03:47 AM
Thanks for your answer.
I will try and give the answer later.
Thanks a lot!
10-22-2009 09:23 PM
Hello dummy_decoy ,
I have try according to the method you suggested, The result was fail. The message is that the function handle is invalid, it seems like the interface between the two prucedure is not existed.
Through Searching information about this question, I known that the DLL created in VB is not a standard DLL, It does not export any symbol,so when we call it in CVI ,int can't find the handle.
This is just my opinion,I don't known whether it righr or wrong...