dcsimg
Results 1 to 15 of 15

Thread: GetOBject for my own DLL

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843

    GetOBject for my own DLL

    Helo everybody.. we have all seen the getObject function work on apps like excel and word. Now.. I want to use it for my own DLL. So far I created the DLL ActiveX. Then in another project I create an instance of that DLL. Then in a third project I use the getObject function to grab a reference of that DLL created in the second project... but it tells me it cannot create the activex....

    what am I missing?
    Thanks
    "The difference between mad and genius is the success"

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    hold on a few minutes..let me dig up the code.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    thanks!
    "The difference between mad and genius is the success"

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    put this code in every class that you need to use GetObject on in your dll and change VegaCOMM.clsSocket to yourprojectname.classname

    That should do it.

    Code:
    ' Declares needed to register object in the ROT
    Private Const ACTIVEOBJECT_STRONG = 0
    Private Const ACTIVEOBJECT_WEAK = 1
    Private Declare Function CLSIDFromProgID Lib "ole32.dll" (ByVal ProgID As Long, rclsid As GUIDs) As Long
    Private Declare Function CoDisconnectObject Lib "ole32.dll" (ByVal pUnk As IUnknown, pvReserved As Long) As Long
    Private Declare Function RegisterActiveObject Lib "oleaut32.dll" (ByVal pUnk As IUnknown, rclsid As GUIDs, ByVal dwFlags As Long, pdwRegister As Long) As Long
    Private Declare Function RevokeActiveObject Lib "oleaut32.dll" (ByVal dwRegister As Long, ByVal pvReserved As Long) As Long
    
    Private OLEInstance As Long
    
    Private Sub Class_Initialize()
    Dim typGUID As GUIDs
    Dim lp As Long
    
    OLEInstance = 0
    ' This code is responsible for creating the entry in the rot
    lp = CLSIDFromProgID(StrPtr("VegaCOMM.clsSocket"), typGUID)
    If lp = 0 Then
        lp = RegisterActiveObject(Me, typGUID, ACTIVEOBJECT_WEAK, OLEInstance)
    End If
    
    End Sub
    
    
    Private Sub Class_Terminate()
    ' Once we are done with the main program, lets clean up the rot
    ' by removing the entry for our ActiveX Server
    
    If OLEInstance <> 0 Then
        RevokeActiveObject OLEInstance, 0
    End If
    
    CoDisconnectObject Me, 0
    
    End Sub
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    It sends me an error in the third line saying the data type hasent been defined....
    do you knwo why?
    I am looking for it...
    "The difference between mad and genius is the success"

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    oopss sorry forgot one part

    Code:
    Private Type GUIDs
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(0 To 7) As Byte
    End Type
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    Thanks... it runs with no error.. but I still cant get the reference....
    would it be too much to ask if you have an example?

    Thanks
    "The difference between mad and genius is the success"

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    wait.. I am such an idiot.. I havent replaces my class name...
    ooppps
    "The difference between mad and genius is the success"

  9. #9
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    well there is really no example. beause all you have to do is

    Dim myobj As Object
    Set myobj = GetObject(,"yourproject.classname")
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  10. #10
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Originally posted by Andreex
    wait.. I am such an idiot.. I havent replaces my class name...
    ooppps
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    it works better than bread and butter!!!

    nice work man!
    "The difference between mad and genius is the success"

  12. #12
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    coolness..you are lucky. It took me 7 months to find that code.

    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  13. #13
    New Member
    Join Date
    Nov 2019
    Posts
    1

    Re: GetOBject for my own DLL

    I know this post is really old, but I'm trying to implement this in VB.net. Several of the items are no longer supported in VB.net. Has anyone done something similar in VB.net??

  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,620

    Re: GetOBject for my own DLL

    you would probably be better to post a new thread in the .net forum,, with a link to this old thread
    a moderator will probably do this for you
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  15. #15
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,297

    Re: GetOBject for my own DLL

    Actually, I think what would be best here is just to start the thread yourself and add a link to this thread if you feel it is appropriate. The question asked lacks enough information without this thread for it to stand on its own, so just moving it would result in a thread that required people to read this thread just to understand what was being asked. Further, this thread is so old that things have likely changed in the intervening 17 years.

    So, start a new thread on the topic, it would be the best way to get an answer.

    Also, I guess I should add that I'm not quite clear what it is that you want to implement. This thread could be read as talking about a plugin system, which would have a different, though straightforward implementation in .NET. On the other hand, the specifics of the question might have a different implementation.
    My usual boring signature: Nothing

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width