Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in DLL but not in PRG

Status
Not open for further replies.

bsutton55

Programmer
Feb 4, 2014
12
GB
I am getting an error when calling code in a dll - the same line of code works fine outside the dll i.e. if I put it in a prg and call the prg instead of the dll.

My calling program passes a form object as a parameter to the dll (or prg). The form object has an array property. I want the dll (or prg) to cycle through some code depending upon the number of rows in the array. The dll has several functions. The problem line of code within the function is the 2nd line in the following block of code (i.e. the FOR statement)

When I call the function in the dll I am getting - Function argument value, type, or count is invalid (Error 11) on the FOR statement line. Running the same code by calling a prg works OK.

IF !EMPTY(toForm.aMyArray[1,1])
FOR i = 1 TO ALEN(toForm.aMyArray,1)​
do_code​
ENDFOR​
do_code​
ENDIF

What is odd is that the first line of code runs OK and the DLL does not error - so I believe it is accepting the form object and the forms array property.

Is there any particular reason that a line of code should run differently in a DLL as opposed to a PRG?

Thanks
Barry Sutton
 
VFP DLLs can not have ANY user interface.
Forms are :)



Borislav Borissov
VFP9 SP2, SQL Server
 
What is the error and error message you get from your DLL? Use COMRETURNERROR from DLL code to make the error available in your main EXE

DLLs are "in process COM Servers", meaning they use the same process as the EXE using them, but they still use their own Runtime, especially multi-threaded DLLs.

Bye, Olaf.
 
Waht Boris says is also true and may be the central issue, nevertheless you can pass around objects betweeen EXE and DLL and can work on them, too. A DLL just can't do any code needing user interaction, something visual, eg a Messagebox() call fails in a DLL with Error 2031.

Even if you don't do anything visual in the DLL and only want to operate on the Form reference this most probably causes errors.

Bye, Olaf.
 
Barry,

I don't know if this is relevant, but I've always avoided passing custom array properties (toForm.aMyArray, in this case) to any of VFP's built-in array-handling functions (those that take an array name as a parameter, such as ALEN() and ASORT()). In the past, this was considered problematical. The usual advice was to copy the contents of the array property to an ordinary array, and to pass that as the parameter instead.

I'm sorry I can't give any more information about this. It could be tht it only applied in older versions of VFP. In any case, it wouldn't explain why your code worked in a PRG but not a DLL. But I thought I'd throw it into the conversation, just in case you felt like experimenting with it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike
Thanks - that has it sorted. I copied the form array to a standalone array and passed this as a parameter to the DLL, remembering to include EXTERNAL ARRAY command in the calling program - and it worked fine.

All
Whilst I new that DLLs could not have an interface I did not realise this might extend to referring to a form object even if it the form was not being made visible in the DLL. I can't say I am entirely convinced by this as the first line:
!EMPTY(toForm.aMyArray[1,1])
does not error in the DLL.

It seems that Mike's idea re the ALEN() function not handling the form.array might be correct - although why it works in a prg and not a dll is a bit odd.

Either way, the problem is sorted and life can move on to the next challenge!

Thanks to all for their input.

Barry
 
Barry,

I'm slightly surprised that my idea worked - mainly because of the difference in behaviour in the PRG vs the DLL. But I'm glad that it did.

Good to see you here again after all this time, by the way.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I don't know exactly, but using the VFP9t.dll part of the runtime, it hasn't got class definitions for forms or anything else visual, it's a limited runtime with the advantage of being multithreaded. As you pass in toForm, even just for acting on toForm.myArray, that might be the cause of failing, while passing in the array copy does not.

To verify, you might to to copy the array as a property of another object, eg a custom object.

oParamobject = CreateObject("custom")
ACOPY(Form.myArray,oParamobject.myArray,1,ALEN(Form.myArray,0),1)

Of course passing just an array is removing the unknonwn form class, too.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top