|
-
May 10th, 2009, 03:49 PM
#1
Thread Starter
Hyperactive Member
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!!!!! 
-
Nov 3rd, 2011, 10:03 PM
#2
New Member
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...
-
Nov 4th, 2011, 01:17 PM
#3
Re: Is this correct use of AddRef/Release/QueryInterface
What is the definition of CLSIDFromProgID that you are using?
-
Nov 4th, 2011, 03:19 PM
#4
Thread Starter
Hyperactive Member
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!!!!! 
-
Nov 4th, 2011, 06:04 PM
#5
New Member
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.
-
Nov 4th, 2011, 06:05 PM
#6
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|