PRB: SET PROCEDURE TO causes unknown error with FoxPro DLL (306079)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 5.0
  • Microsoft Visual FoxPro for Windows 5.0a
  • Microsoft Visual FoxPro for Windows 6.0
  • Microsoft Visual FoxPro for Windows 7.0
  • Microsoft Visual FoxPro 8.0
  • Microsoft Visual FoxPro 9.0 Professional Edition

This article was previously published under Q306079

SYMPTOMS

If a COM dynamic-link library (DLL) which uses SET PROCEDURE TO is instantiated more than once, the Init method of the second instance may fail with one of the following messages:
OLE error code 0x80004005: Unspecified error.
OLE error code 0x80020009: Exception occurred.

CAUSE

To instantiate an OLEPUBLIC class, Visual FoxPro must be able to find all the code for the class. There is an internal SET PROCEDURE/SET CLASSLIB to detect all the related code; if you try to change this setting, an error occurs.

RESOLUTION

Use SET PROCEDURE TO with the ADDITIVE keyword.

STATUS

This is by design.

MORE INFORMATION

Steps to Reproduce Behavior

To see this behavior, run the following code. Uncomment the ADDITIVE clause for the code to work.
CLOSE ALL
SET SAFETY OFF
ERASE testLib.*
ERASE comTest.*

SET TEXTMERGE TO testLib.prg NOSHOW
TEXT 
   *!* Dummy function library
ENDTEXT

SET TEXTMERGE TO comTest.prg NOSHOW
TEXT 
   DEFINE CLASS comTest AS Custom OLEPUBLIC
      FUNCTION SetProc
         SET PROCEDURE TO testlib &&ADDITIVE
      ENDFUNC
   ENDDEFINE
ENDTEXT

BUILD PROJECT comtest FROM comtest.prg
BUILD DLL comtest FROM comtest

loComTest1 = CREATEOBJECT("ComTest.ComTest")
loComTest1.SetProc()
loComTest2 = CREATEOBJECT("ComTest.ComTest")  && This line will give error.
				

Modification Type:MajorLast Reviewed:11/28/2005
Keywords:kbCodeSnippet kbpending kbprb KB306079