Results 1 to 6 of 6

Thread: Is this correct use of AddRef/Release/QueryInterface

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    389

    Is this correct use of AddRef/Release/QueryInterface

    Code:
    Private Sub UserControl_Initialize()
        Dim sUnk As vbActiveScript3.IUnknown, pUnk As vbActiveScript3.IUnknown
        Dim clsidVBS As vbActiveScript3.UUID
        Dim uuidActScr As vbActiveScript3.UUID, uuidActScrParse As vbActiveScript3.UUID
    
        CLSIDFromProgID "VBScript", clsidVBS                    'Get CLSID VBScript/JScript
        
        CLSIDFromString IID_IActiveScript, uuidActScr           'Get CLSID IActiveScript
        CLSIDFromString IID_IActiveScriptParse, uuidActScrParse 'Get CLSID IActiveScriptParse
        
        hRes = CoInitialize(Empty)                              'Initialize COM Interfaces (This is not required)
    
        hRes = CoCreateInstance(clsidVBS, Nothing, CLSCTX_INPROC_SERVER, uuidActScr, sUnk)  'Inproc the interfaces
    
        sUnk.AddRef
        
        Set iScript = sUnk
        
        hRes = iScript.SetScriptSite(Me)
        
        hRes = sUnk.QueryInterface(uuidActScrParse, pUnk)
        
        pUnk.AddRef
        
        Set iParse = pUnk
        
        hRes = iParse.InitNew
    
        pUnk.Release
        sUnk.Release
        
        Set pUnk = Nothing
        Set sUnk = Nothing
    End Sub
    This works just fine, but I am wondering if this is "incorrect"...

    I don't want any posts saying, "Why are you doing this in VB?!?!?"... Simply answer, because I can :P
    Last edited by vbman213; May 10th, 2009 at 03:53 PM.
    Visual Basic Rules!!!!!

  2. #2
    New Member
    Join Date
    Oct 2011
    Posts
    3

    Re: Is this correct use of AddRef/Release/QueryInterface

    I keep getting an error I can't figure out..
    Code:
    Dim hRes As Long
    Dim oUnk As vbActiveScript3.IUnknown
    Dim clsidVBS As vbActiveScript3.UUID
    Dim uuidActScr As vbActiveScript3.UUID
        
    'Create instance of the language engine
    CLSIDFromProgID "VBScript", clsidVBS
    CLSIDFromString IID_IActiveScript, uuidActScr
        
    'Start inproc script engine, VBSCRIPT.DLL
    hRes = CoCreateInstance(clsidVBS, Nothing, CLSCTX_INPROC_SERVER, uuidActScr, oUnk)
    I get a ByRef Argument type mismatch on this line with the 'clsidVBS' highlighted.
    CLSIDFromProgID "VBScript", clsidVBS

    I have the type library properly referenced as well..

    Anyone got any ideas?

    Thanks in advance...

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Is this correct use of AddRef/Release/QueryInterface

    What is the definition of CLSIDFromProgID that you are using?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    389

    Re: Is this correct use of AddRef/Release/QueryInterface

    Wow, way to revive a thread!

    Anyways: The TypeLibrary that I was using was HEAVILY modified to work with VB6. It was a pretty massive hack... I ended up having to use an TypeLibrary exporter and IDL to recompile a VB6 "friendly" version that would expose all the necessary COM fancy stuff that was needed.

    Sorry, I do not have my code. But I will say that I was 100% successful in recreating the MsScript.OCX control as a UserControl. Therefore, my code was not dependent on an OCX!
    Visual Basic Rules!!!!!

  5. #5
    New Member
    Join Date
    Oct 2011
    Posts
    3

    Re: Is this correct use of AddRef/Release/QueryInterface

    haha Thanks LaVolpe and vbman213.
    Yes vbman213 you are correct in that is does run without problems with the demo you provided. It also runs on new projects without problems as well. I didn't go into detail in my initial post because as you noted the thread is somewha dead and I didn't actually expect anyone to respond. I am quite happy that both of you did. Its like a who's who of Vb programming in here!

    Anyways, to go into more detail, I only get this issue when I add the CActiveScript class to an existing project I am working on. So my thoughts were that somewhere in one of the classes or controls there is a different definition of the CLSIDFromProgID somewhere. However, it does not appear anywhere in the project! ???

    There is no declare anywhere for it, in my project, or in vbman213 project. Yet, the project that was supplied by vbman213 still runs fine without issues at all. In fact its quite slick!

    So does that mean it's somehow wrapped in the tlb? Please excuse my ignorance, but I have not much expeience with TLB's

    I am going to try and declare it myself in my code and see what happens.

    Edit:
    I just tried and declaring the function made no difference. I still get a byref argument mismatch on the CLSID UDT..
    I mean this makes no sense.. It gets its type from the TLB even, and I can see it working in other projects. HAHA It works everywhere except where I need it to work..
    Last edited by OldSchoolVBGuy; Nov 4th, 2011 at 06:29 PM.

  6. #6
    New Member
    Join Date
    Oct 2011
    Posts
    3

    Re: Is this correct use of AddRef/Release/QueryInterface

    Also vbman213, I don't have a control, I have a class..

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