I use a PB DLL to provide a function not easily done with Visual Foxpro. I am trying to write a PB COM object to provide the same function. However, the COM object causes an error in VFP when I try to use it. The function in a DLL works fine. Maybe it is because I need to use ASCIIZ strings in the normal DLL for VFP. Perhaps someone can provide me a idea of how to make the function work in a COM object?
Here is the DLL, which works fine:
Here is the COM object, which does not work.
Afer compliling the COM DLL I register it using ResSvr32. I check that it is registered using PBROW.EXE.
In VFP I use the following commands to use a COM object:
oStr = CreatObject("Str_Find") && This creates the object and works
nPos = oStr.FindStr(1, "Find String Main Subject","Subject") && As soon as I type oStr. the COM object / VFP reports an error and VFP closes.
Any ideas or pointer will be appreciated. We use COm objects with VFP all the time with not problem. We are very happy that PB will not provide us the capability to create COM objects.
Thanks,
John
Here is the DLL, which works fine:
Code:
#COMPILE DLL "Str_Functions.DLL" #REGISTER ALL #INCLUDE "WIN32API.INC" GLOBAL ghInstance AS DWORD FUNCTION LIBMAIN (BYVAL hInstance AS LONG, BYVAL fwdReason AS LONG, BYVAL lpvReserved AS LONG) AS LONG FUNCTION = 1 'success! END FUNCTION FUNCTION Find_String ALIAS "FindString" (MainString AS ASCIIZ, MatchString AS ASCIIZ, BYVAL Start AS LONG, BYVAL OptCase AS LONG) EXPORT AS LONG #REGISTER ALL l1& = LEN(MainString) l2& = LEN(MatchString) IF l1& = 0 OR l2& = 0 THEN Find_String& = y& EXIT FUNCTION END IF IF start > l1& THEN Find_String& = y& EXIT FUNCTION END IF IF OptCase& = 1 THEN Mainstring = LCASE$(MainString) MatchString = LCASE$(MatchString) END IF y& = INSTR(start, MainString, MatchString) Find_String& = y& END FUNCTION
Code:
#COMPILE DLL "STR_FUNCTIONS_COM3.DLL" #DIM ALL #COM NAME "STRFUNCTIONS",1.1 #COM GUID GUID$("{15E1E28D-44B1-497D-9793-5CD9F2B58EDC}") #COM TLIB ON $MyClassGUID = GUID$("{27E25675-7BC8-4B40-B594-FD315BC3E00A}") $MyFirstInterface = GUID$("{AB9BD731-6B72-490E-8B2F-9ABA05C617A1}") CLASS Str_Find $MyClassGUID AS COM INTERFACE mStr_Find $MyFirstInterface INHERIT IDISPATCH METHOD FindStr <1> (STARTNUM AS LONG, MSTRING AS STRING, FSTRING AS STRING, OPTCASE AS LONG) AS LONG IF OPTCASE = 1 THEN MSTRING = UCASE$(MSTRING) FSTRING = UCASE$(FSTRING) END IF METHOD = INSTR(STARTNUM, MSTRING, FSTRING) END METHOD END INTERFACE END CLASS
In VFP I use the following commands to use a COM object:
oStr = CreatObject("Str_Find") && This creates the object and works
nPos = oStr.FindStr(1, "Find String Main Subject","Subject") && As soon as I type oStr. the COM object / VFP reports an error and VFP closes.
Any ideas or pointer will be appreciated. We use COm objects with VFP all the time with not problem. We are very happy that PB will not provide us the capability to create COM objects.
Thanks,
John
Comment