Results 1 to 2 of 2

Thread: VB.NEt dll and vbscript

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    113

    VB.NEt dll and vbscript

    I created a new dll class using vb.net 2010.

    It has two functions:

    Code:
    Option Explicit On
    Imports System
    
    Public Class MYDLL
       Private Declare Function FxFindWindow Lib "user32" Alias "FindWindowA" _
        (ByVal szClassName As String, ByVal szWindow As String) As Long
    
        Private Declare Function FxSendMessage Lib "user32" Alias "SendMessageA" _
           (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam _
           As Long, ByVal lParam As Long) As Long
    
        Private Const WM_CLOSE = &H10
    
        Public Function FindWindow(ByVal CaptionString As String) As Long
            FindWindow = FxFindWindow(vbNullString, CaptionString)
        End Function
    
        Public Function KillWindow(ByVal winHandle As Long) As Long
            KillWindow = FxSendMessage(winHandle, WM_CLOSE, 0, 0)
        End Function
    
    End Class
    I want to use the functions from a vbscript (vb) file from a program, so i execute the vb file to find a window. But I cant get it to work:

    The dll is called MYDLL.DLL

    Code:
    Dim DataBin 
    Set obj = CreateObject("MYDLL.MYDLL")
    DataBin = obj.FindWindow("txt - Notepad.exe")
    Dim filesys, filetxt, getname, path
    Set filesys = CreateObject("Scripting.FileSystemObject")
    Set filetxt = filesys.CreateTextFile("C:\output.txt", True)
    filetxt.WriteLine(DataBin)
    filetxt.Close
    but it says:
    ActiveX component cant create object 'MYDLL.MYDLL'

    So how do I fix this up?

    (Yes Im new to vbscript)

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: VB.NEt dll and vbscript

    If it's a .NET DLL then it's a .NET Assembly... not an ActiveX DLL ... if you want to call your .NET Assembly from something other than .NET (and yes, that's what you're trying to do) then you need to make is COM Callable... register it... then you can use it. Do do this, you'll need to go into the Project Properties, select Advanced Options (it's a button down at the bottom of the Compile tab, may need to scroll to get to it) and turn on the check mark for "Make COM Callable" (or something like that... it's at the bottom of the screen)... then re-compile the DLL. I think (but I'm not sure) that compiling will automatically register it with the system, if not, you'll need to do a regsvr32 on it... jsut like you would any other ActiveX component. Once that's done, you should then be able to create objects with it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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