Results 1 to 10 of 10

Thread: Creating a DLL and accessing its functions, Help!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Canada
    Posts
    70
    I have created a dll with one public function and numerous
    private functions.
    (The public function's name is the same as the dll but
    different from the project name.)

    To test it I created an application, referenced the dll and
    then called the dll's public function. When I try and
    compile the executable I receive an error:
    "Sub or Function not defined".

    The application and dll are in the same directory, why
    can't it find the function?



    A big "Thank You" to anyone who can help me with this!




  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    I'm not sure what your saying but to access your dll function :

    yourdll.yourfunction

    it's that simple!!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Canada
    Posts
    70
    Thanks, your answer got me over one hurdle and on to another:

    My Dll is named CreateCallSum.dll, the project is named
    CreateCallSum and the public function is called CreateRpt

    My application calls it with:
    blnStatus = CreateCallSum.CreateRpt

    It doesn't seem to have a problem with the CreateCallSum.
    part but now I get a "Method or Data member not defined"
    error at the CreateRpt part.

    Suggestion?

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    What is the name of the class?
    Lets say the class is named MyClass, then you can use the following code (providing you added a reference to the dll)

    Dim x as CreateCallSum.MyClass
    Set x = CreateObject("CreateCallSum.MyClass")
    blnStatus = x.CreateRpt

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Canada
    Posts
    70
    I'm not creating an object.
    I created a dll with 1 public function.
    I pass variables into it; it forms an sql statement,
    queries the database and passes back a formatted string
    with the data found.

    For instance:
    I have GetValue.dll with the following function:

    Public function MyDLLFunction(byValintOne as integer, _
    byRef strTwo as string) as boolean

    if intOne = then
    strTwo = "Value 1"
    else
    strTwo = "Value2"
    end if
    Myfunction = true
    end function

    -------
    In my application I reference GetValue.dll and call it in
    my code:
    Private strValue as string

    Private Sub btnTest_Clicked
    dim blnStatus as boolean

    blnStatus = MyDLLFunction(1, strValue)

    End Sub
    -------


    How should I call this function?
    I would like to call this function like I would the Format function.

    Thanks


  6. #6
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    I assume you created the dll with visual basic. Unless you set the Instancing property of the class that contains the function to GlobalMultiUse, you need to create an object before you can use the function.
    If you set the Instancing property to 6 - GlobalMultiUse you can call the function like you wanted, it acts like an intrinsic vb function. In fact vb creates the object for you, you don't need to do it yourselve.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Canada
    Posts
    70
    I used your suggestion and changed the Instancing property
    to 6 - GlobalMultiUse.
    I then declared the function
    Private Declare Function MyDLLFunction Lib "GetValue" (byVal intOne as integer, byRef strTwo as string) as boolean

    I can now compile my application without errors but when
    I try to run it I receive this error:
    453 -> Can't find DLL Entry point MyDLLFunction in GetValue

    The help file says the problem is that MyDLLFunction cannot
    be found in the DLL so I delete the dll and recompiled.
    But it didn't solve the problem.

    I am absolutely frustrated.

    In C I would simply add the dll into the make file. In VB6 I just do not have a clue.





  8. #8
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    You must NOT declare a function that is in a COM dll. You must add a reference to the dll (project --> references).
    Only functions from standard C dll's are declared.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Canada
    Posts
    70
    Alrighty then,
    I took the Declare statement out and now find error 429:
    ActiveX component can't create object.

    I then checked the help and it told the dll had to be registered. So I registered it. Checked the registry to make
    sure it pointing to the right directory. I'm not creating
    an object so the other 'possible reasons' are mute and
    still a recieve Error 429.

    This should be so simply yet nothing works.

  10. #10
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Check you're references again. If you don't have set binary compatibility on you're dll project, you generate new clsid's every time you compile your dll. This means that every time you compile your dll, you have to set the reference again to your new dll, otherwise the project using the dll is still poining to the old dll, which doesn't exist anymore (at least the registry settings are overwritten). You should not have to register the dll manually, since this is done when you compiled it.

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