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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP7 dll error handling question 1

Status
Not open for further replies.

wawalter

Programmer
Aug 2, 2001
125
0
0
US
Hello,

I have created a DLL in VFP7 that I call from a C# application. Normally it works fine. The problem I'm having is when there is an error in the DLL, the message returned to C# is meaningless.

Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))

I set up an "on error" handler that calls a procedure that writes out the actual error to a text file from the VFP dll, but then the C# program continues on without knowing there was an error.

How do I return something that indicates there was an error in the VFP DLL (like a -1).

Thanks for your help.

Code:
ON ERROR do errorproc with ERROR(), PROGRAM(), LINENO(), MESSAGE(), MESSAGE(1)

do some stuff

SELECT * from tablethatdoesnotexist ** cause error

RETURN countofrecords


PROCEDURE ERRORPROC 
	LPARAMETERS nError, cMethod, nLine, cMessage, cMessage1
	LOCAL LnErrorHandle
	LnErrorHandle=FCREATE('c:\error.txt')
	IF LnErrorHandle>0
		=FPUTS(LnErrorHandle,'Error Number:'+TRANSFORM(nError))
		=FPUTS(LnErrorHandle,'Name of Method:'+cMethod)
		=FPUTS(LnErrorHandle,'Line number:'+TRANSFORM(nLine))
		=FPUTS(LnErrorHandle,'Message:'+cMessage)
		=FPUTS(LnErrorHandle,'Message(1):'+cMessage1)
	ENDIF
	=FCLOSE(LnErrorHandle)
	countofrecords = -1
ENDPROC
 
See COMReturnError() in the help file.

(Although it may not have existed yet in VFP7. If that's the case, now is a good time to upgrade.)
 
Thanks, it does exist in VFP 7, so I'll give it a try.

I also found that adding err.raise after I write to the error log will raise the error to the C# program in a generic form, but at least the error is logged and my C# program knows there is an error.

Thanks again,

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top