Results 1 to 11 of 11

Thread: How to build tlb by midl.exe ?vc++ vs2017

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,541

    How to build tlb by midl.exe ?vc++ vs2017

    MIDL2270 duplicate UUID.Same as : IDispatch[Interface 'IDispatch2'] j
    uuid(00020400-0000-0000-C000-100000000046),
    so i change to 100000000046
    -------------------------
    MIDL2003 redefinition : IDispatch

    so i change to IDispatch
    but can't bind to vb object
    -------------------------

    Code:
    Dim idisp As oleexp.IDispatch
    dim idisp2 vbActiveScript5.IDispatch2
    
       Set idisp   = form1 it's right
    
       Set idisp2  = form1 it's err

    Code:
    [
    	odl,
    	uuid(00000000-0000-0000-C000-000000000116),
    ]
    interface IUnknown2 {
    
    	LONG QueryInterface(
    		[in, out] UUID *riid,
    		[in, out] void *ppvObject);
    
    	LONG AddRef();
    	LONG Release();
    }
    
    
    [
    	odl,
    	uuid(00020400-0000-0000-C000-100000000046),
    ]
    interface IDispatch2 : IUnknown2 {
    
    	HRESULT GetTypeInfoCount(
    		[out, retval] int* pctinfo);
    
    	HRESULT GetTypeInfo(
    		[in, defaultvalue(0)] int itinfo,
    		[in, defaultvalue(0)] long lcid,
    		[out, retval] LONG **pptinfo);
    
    	LONG GetIDsOfNames(
    		[in] UUID* riid,
    		[in] LPWSTR *rgszNames,
    		[in] int cNames,
    		[in] long lcid,
    		[out] long *rgdispid);
    
    	LONG Invoke(
    		[in] long dispidMember,
    		[in] UUID* riid,
    		[in] long lcid,
    		[in] short wFlags,
    		[in] DISPPARAMS *pdispparams,
    		[in] long pvarResult,
    		[out] EXCEPINFO *pexcepinfo,
    		[out] int *puArgErr);
    };

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,541

    Re: How to build tlb by midl.exe ?vc++ vs2017

    Code:
    Function GetJsonStr() As String
     Dim idisp2 As vbActiveScript5.IDispatch2
     'oleexp.IDispatch
        Dim numArgs As Integer
        
        IScript.GetScriptDispatch "", idisp2
        
    GetJsonStr = CallByName(idisp2, "eval", VbMethod, "JSON.stringify(JsonObj)")
    End Function
    Code:
            HRESULT GetScriptDispatch(
                    [in]  LPSTR pstrItemName,
                    [out] IDispatch2 **ppdisp
            );
    maybe here IDispatch also need to change IDispatch2

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,541

    Re: How to build tlb by midl.exe ?vc++ vs2017

    This code is complicated, is there any way to do it directly?

    Code:
    Function Run(funcName As String, ParamArray args())
     
        Dim idisp As vbActiveScript5.IDispatch2 'oleexp.IDispatch
        Dim numArgs As Integer
        
        IScript.GetScriptDispatch "", idisp
        
        On Error Resume Next
        numArgs = UBound(args)
        
        If numArgs = -1 Then
            Run = CallByName(idisp, funcName, VbMethod)
        Else
            Select Case numArgs
                Case 0: Run = CallByName(idisp, funcName, VbMethod, args(0))
                Case 1: Run = CallByName(idisp, funcName, VbMethod, args(0), args(1))
                Case 2: Run = CallByName(idisp, funcName, VbMethod, args(0), args(1), args(2))
                Case 3: Run = CallByName(idisp, funcName, VbMethod, args(0), args(1), args(2), args(3))
                Case 4: Run = CallByName(idisp, funcName, VbMethod, args(0), args(1), args(2), args(3), args(4))
                Case 5: Run = CallByName(idisp, funcName, VbMethod, args(0), args(1), args(2), args(3), args(4), args(5))
                Case 6: Run = CallByName(idisp, funcName, VbMethod, args(0), args(1), args(2), args(3), args(4), args(5), args(6))
                Case 7: Run = CallByName(idisp, funcName, VbMethod, args(0), args(1), args(2), args(3), args(4), args(5), args(6), args(7))
                Case Else:
                        MsgBox "Run only supports a max of 7 Args to call function.", vbInformation
            End Select
        End If
        
    End Function

  4. #4
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,667

    Re: How to build tlb by midl.exe ?vc++ vs2017

    The GUID is what matters. Once you changed that, you had an entirely different interface that is no longer interchangeable with IDispatch.

    Problems like this are why oleexp is compiled with the ancient MKTYPLIB instead of midl. You will find the midl "redefinition" prohibition impossible to work around, something I spent dozens of hours of my life trying in vain to get around. midl force-includes the oaidl.idl file... if you substitute an empty one, it fails, if you put a few things in it, ok, but now virtually nothing is defined. You're left with only the most primitive types... no long, no VARIANT. So you might think you just need to redefine those too. Well you'll think you're making progress, only to be left with bizarre errors, and when you finally solve those, you arrive at the end: midl will tell you it can't create the typelib. It can offer no error number, no line where a problem occurs, only a couple vague guesses you know are wrong.

    So if you want to redefine types or interfaces contained in oaidl.idl, midl is the wrong tool.

    MKTYPLIB lacks a lot of the features of midl, so when importing interfaces they require a ton of extra modifications. It's also so old you can target 16-bit, but not 64-bit. Hence the creation of tbShellLib for 64bit twinBASIC. The ability to define interfaces/coclasses in VB-like language, right in your project, is by far my favorite new feature.
    Last edited by fafalone; May 26th, 2023 at 05:09 AM.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,541

    Re: How to build tlb by midl.exe ?vc++ vs2017

    IActiveScript HOW TO SUPPORT VBSCRIPT? I TRY ,BUT IT'S ONLY TEST FOR JS
    / Start inproc script engine, VBSCRIPT.DLL
    HRVERIFY(CoCreateInstance(CLSID_VBScript

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,541

    Re: How to build tlb by midl.exe ?vc++ vs2017

    it's can use for vbscript ,but can't set this for support json:

    IProperty.SetProperty SCRIPTPROP_INVOKEVERSIONING, ByVal 0&, Version

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,541

    Re: How to build tlb by midl.exe ?vc++ vs2017

    THE TLB CAN'T USE for x64 vba?
    maybe need to change vartype in idl?
    hope you make a x64 tlb for vba .

    Code:
    Private Sub IActiveScriptSite_GetItemInfo(ByVal pstrName As String, ByVal dwReturnMask As vbActiveScript6.tagSCRIPTINFO, ppiunkItem As Long, ppti As Long)
    
    Private Function IActiveScriptSite_GetLCID() As Long
    Private Sub IActiveScriptSite_OnScriptTerminate(pvarResult As Variant, pexcepinfo As vbActiveScript6.EXCEPINFO)
    
    End Sub
    
    Private Sub IActiveScriptSite_OnStateChange(ByVal ssScriptState As vbActiveScript6.tagSCRIPTSTATE)
    
    End Sub

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,541

    Re: How to build tlb by midl.exe ?vc++ vs2017

    Quote Originally Posted by fafalone View Post
    MKTYPLIB lacks a lot of the features of midl, so when importing interfaces they require a ton of extra modifications. It's also so old you can target 16-bit, but not 64-bit. Hence the creation of tbShellLib for 64bit twinBASIC. The ability to define interfaces/coclasses in VB-like language, right in your project, is by far my favorite new feature.
    In fact, I will only a little bit of fur VC++, let me make up an IDL to TLB has been vomiting blood.
    I installed a simplified version of VC++, has been prompted to lack a variety of IDL files, a complex past is not good, behind the setting of the computer environment variables, finally good.
    But this problem of repeated definitions is completely unsolvable, as is the error of no prompt message.
    Using VS2017 is OK, but repeated definition still can't solve.
    Maybe I simply created JS9 and let the 64-bit VBA also use SCRIPT objects. I guess I can change the TLB data type to 64-bit, and it is still possible to succeed. LONG is going to be LONGLONG (longptr in excel)

  9. #9
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,667

    Re: How to build tlb by midl.exe ?vc++ vs2017

    IActiveScript has very unusual differences between x86 and x64. It's not a matter of simply changing data types, you need entirely different GUIDs in some cases... refer to tbShellLib:

    Code:
    #If Win64 Then
    [ InterfaceId ("C7EF7658-E1EE-480E-97EA-D52CB4D76D17") ]
    #Else
    [ InterfaceId ("BB1A2AE2-A4F9-11cf-8F20-00805F2CD064") ]
    #End If
    [ OleAutomation (False) ]
    Interface IActiveScriptParse Extends IUnknown
        Sub InitNew()
        Sub AddScriptlet(ByVal pstrDefaultName As LongPtr, ByVal pstrCode As LongPtr, ByVal pstrItemName As LongPtr, ByVal pstrSubItemName As LongPtr, ByVal pstrEventName As LongPtr, ByVal pstrDelimiter As LongPtr, _
                            ByVal dwSourceContextCookie As LongPtr, ByVal ulStartingLineNumber As Long, ByVal dwFlags As AS_AddScr_Flags, pbstrName As String, pexcepinfo As EXCEPINFO)
        Sub ParseScriptText(ByVal pstrCode As LongPtr, ByVal pstrItemName As LongPtr, ByVal punkContext As IUnknown, ByVal pstrDelimiter As LongPtr, ByVal dwSourceContextCookie As LongPtr, _
                                ByVal ulStartingLineNumber As Long, ByVal dwFlags As AS_AddScr_Flags, pbstrName As String, pexcepinfo As EXCEPINFO)
    End Interface

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,541

    Re: How to build tlb by midl.exe ?vc++ vs2017

    IActiveScript and IActiveScriptProperty,you can make a tlb for x64,i can test it,thank you

  11. #11
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,667

    Re: How to build tlb by midl.exe ?vc++ vs2017

    tB plans to support exporting TLBs in the future; when that feature is available, I'll export tbShellLib as a TLB for 64bit VBA.

    But until then, if you want to do 64bit development, use twinBASIC. Create a new project, then follow these steps to add tbShellLib as a reference, then you'll be able to test IActiveScript and related interfaces.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width