You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
Thomas,
Let me see if I can work one up. I can easily use a COM that already exists, but creating a COM from scratch that seems to be where I am taking a hit
It is probably the VB background I have and trying to not make it worse for the "Non-Programmers" I know will follow, but I am trying.
I have been able to get Native PB Com methods called from JSCRIPT, VBSCRIPT and Visual Basic with out any problems. Do you have sample code which reproduces the error?
' ****************************************************************************************
' Maps a single member to a corresponding DispID, which can be used on subsequent calls to
' IDispatch_Invoke.
' ****************************************************************************************
DECLARE FUNCTION Proto_IDispatch_GetIDOfName (BYVAL pthis AS DWORD PTR, BYREF riid AS GUID, BYREF rgszNames AS STRING, BYVAL cNames AS DWORD, BYVAL lcid AS DWORD, BYREF rgdispid AS LONG) AS LONG
' ****************************************************************************************
FUNCTION IDispatch_GetIDOfName (BYVAL pthis AS DWORD PTR, BYREF strName AS STRING, BYREF rgdispid AS LONG) AS LONG
LOCAL HRESULT AS LONG, riid AS GUID
IF pthis = %NULL THEN FUNCTION = %E_POINTER : EXIT FUNCTION
CALL DWORD @@pthis[5] USING Proto_IDispatch_GetIDOfName (pthis, riid, strName, 1, 0, rgdispid) TO HRESULT
FUNCTION = HRESULT
END FUNCTION
' ****************************************************************************************
' ****************************************************************************************
' Provides access to properties and methods exposed by an object.
' Note: if the call to Invoke returns %DISP_E_EXCEPTION (&H80020009), the EXCEPINFO
' structure is filled with error information. Three of his members are pointers to
' unicode strings that you can read with the TB_ExcepInfoErrorDescription,
' TB_ExcepInfoErrorSource and TB_ExcepInfoErrorHelpFile functions, and that you must free
' with SysFreeString: SysFreeString pexcepinfo.bstrDescription,
' SysFreeString pexcepinfo.bstrSource, SysFreeString pexcepinfo.bstrHelpFile.
' ****************************************************************************************
FUNCTION IDispatch_Invoke (BYVAL pthis AS DWORD PTR, BYVAL dispidMember AS LONG, BYREF riid AS GUID, _
BYVAL lcid AS DWORD, BYVAL wFlags AS WORD, BYREF pdispparams AS DISPPARAMS, BYREF pvarResult AS VARIANT, _
BYREF pexcepinfo AS EXCEPINFO, BYREF puArgErr AS DWORD) AS LONG
LOCAL HRESULT AS LONG
IF pthis = %NULL THEN FUNCTION = %E_POINTER : EXIT FUNCTION
CALL DWORD @@pthis[6] USING IDispatch_Invoke (pthis, dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr) TO HRESULT
FUNCTION = HRESULT
END FUNCTION
' ****************************************************************************************
Jose Roca has a CallByName function... oh where is that again...
searching
ah here it is...
Code:
FUNCTION TB_CallByName ( _
BYVAL pthis AS DWORD, _ ' *IDispatch
BYVAL vNameOrId AS VARIANT, _ ' Name or identifier
BYVAL callType AS LONG, _ ' Call type
BYREF vParams() AS VARIANT, _ ' Array of variants
BYREF vResult AS VARIANT, _ ' Variant result
BYREF pex AS EXCEPINFO _ ' EXCEPINFO structure
) EXPORT AS LONG ' Error code
DIM dw_puArgErr AS DWORD, DISPID_PROPERTYPUT AS LONG, IID_NULL AS GUID
DIM vArgs(0) AS VARIANT, udt_DispParams AS DISPPARAMS
DIM hr AS LONG, strName AS STRING, DispID AS LONG
DIM nParams AS LONG, i AS LONG, idx AS LONG
' Check for null pointer
IF pthis = 0 THEN FUNCTION = %E_POINTER : EXIT FUNCTION
' Get the DispID
IF VARIANTVT(vNameOrId) = %VT_BSTR THEN
strName = UCODE$(VARIANT$(vNameOrId))
hr = IDispatch_GetIDOfName(pthis, strName, DispID)
IF hr THEN
FUNCTION = hr
EXIT FUNCTION
END IF
ELSE
DispID = VARIANT#(vNameOrId)
END IF
' Copy the array in reversed order
IF VARPTR(vParams()) THEN
nParams = UBOUND(vParams) - LBOUND (vParams) + 1
IF nParams > 0 THEN
REDIM vArgs(nParams - 1)
idx = nParams - 1
FOR i = LBOUND(vParams) TO UBOUND(vParams)
IF VARIANTVT(vParams(i)) = %VT_EMPTY THEN
vArgs(idx) = ERROR %DISP_E_PARAMNOTFOUND
ELSE
vArgs(idx) = vParams(i)
END IF
DECR idx
IF idx < 0 THEN EXIT FOR
NEXT
END IF
END IF
IF CallType = 4 OR CallType = 8 THEN ' %DISPATCH_PROPERTYPUT and %DISPATCH_PROPERTYPUTREF
DISPID_PROPERTYPUT = -3
udt_DispParams.CountNamed = 1
udt_DispParams.NamedDispId = VARPTR(DISPID_PROPERTYPUT)
END IF
udt_DispParams.CountArgs = nParams
IF nParams > 0 THEN udt_DispParams.VariantArgs = VARPTR(vArgs(0))
FUNCTION = IDispatch_Invoke(pthis, DispID, IID_NULL, 0, CallType, udt_DispParams, vResult, pex, dw_puArgErr)
END FUNCTION
Steve,
I am using createobject, and have the dll registered and the typelibrary embeded.
I have learned I can call the method with "CallByName" in VB to solve the late binding, but "CallByName" appears to be a VB only function, so I need to find what the windows api behind the function is.
I am working on this, and how to expose events from the PB dll to the other language, but boyyyyyyyy is it taking a lot of trial and error to get this far
I am having problems with a PB dll I am writing for use in other programming languages. I just can not seem to expose a method to the other languages except to do early binding in the other languages.
Is there a way to do late binding in other languages (VB to be more specific) so that I can call the objects method?
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: