Results 1 to 16 of 16

Thread: Not using But Creating an API Call

  1. #1

    Thread Starter
    Addicted Member jeroenh's Avatar
    Join Date
    Aug 2000
    Location
    Rotterdam, Holland
    Posts
    201

    Angry

    I would like to know if it is possible to create, within VB6, to create a API call that others can use. And if so how can I make this possible?

    Do I still have to register it like an AxtiveX.EXE or can I make a standart EXE from it?
    Catch you later,

    Jeroen Hoekemeijer
    Code:
    If 1 = 2 Then MajorError

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    API Functions reside in Standard DLL files which can not be made in VB. They can be made in C++.
    I am become death, the destroyer of worlds.
    mail:vlatkovr@hotmail.com

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    Addicted Member jeroenh's Avatar
    Join Date
    Aug 2000
    Location
    Rotterdam, Holland
    Posts
    201

    Unhappy Might be an other way?

    Ok, so I have to make these files in C++. Question number 2.

    When I make my DLL in C++ with a API Call, then do I have to register the file in Windows in any way to use this API call.

    Background information:
    I am building a program that uses several DLL files. These files should only be accessed by my prorgam and nobody else. That's why I want to hide them for other users, but still be able to use them myself for later versions or other versions of the userinterface. Maybe somebody has an other idea on how to hide the DLL from the refrences, or make functions within the DLL hidden.
    Catch you later,

    Jeroen Hoekemeijer
    Code:
    If 1 = 2 Then MajorError

  4. #4
    Guest
    As far as I know, I don't think you need to register the DLL.

  5. #5
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    No the DLL doesn't have to be registered in Windows.Just use it from VB:
    Code:
    Declare Function fname Lib dllname(byval arg1 as long,...) as Long or SmthElse
    I am become death, the destroyer of worlds.
    mail:vlatkovr@hotmail.com

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    To use a function in a DLL, you need to have a definition similar to this:
    Code:
    long __stdcall exportedfunc(long param) {
        ...
    }
    It's that __stdcall that's important. Second, link with a .def file which will look like:
    Code:
    LIBRARY "file.dll"
    
    EXPORTS
        exportedfunc
    I don't know if there's any way to 'hide' functions in the DLL. You could play around with really weird function names, but the easiest is probably to have some kind of data validation (pass a number through an algorithm and compare).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    Addicted Member jeroenh's Avatar
    Join Date
    Aug 2000
    Location
    Rotterdam, Holland
    Posts
    201
    I'm still trying a few of all of your answers, but the one given by Parksie must be mend for an other language than VB. I get nothing but errors.

    The option given by Vlatko has the most chance of succeding.
    I's just want to know if I also need to pass along a parameter for the class the funtion is in.

    The message I keep getting is: "Can't fin DLL entrypoint for <FunctionName>". I've used 3 classes in this file, could that be a problem?
    Catch you later,

    Jeroen Hoekemeijer
    Code:
    If 1 = 2 Then MajorError

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Mine was for C++.

    For VB, you can't build a normal DLL. If you want to export classes, then just make an ActiveX DLL - in which case you'll need to register it just like an OCX. Then, go to Project->References and use it.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    jeroenh i told you how to call the DLL from VB. Parksie's post is an information how to make the DLL file in C++.
    You could use the __declspec(dllexport) to export the DLL functions.

    I am become death, the destroyer of worlds.
    mail:vlatkovr@hotmail.com

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  10. #10
    Hyperactive Member WP's Avatar
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    278

    Cool Use a Class

    OR...

    You can make an ActivexDLL (VB), create a couple of public functions or subs in a class, compile it, make an StandardEXE, and use it like this:

    Code:
    'Your ActivexDLL:
    'Make a class, named Class1
    'in class1 type:
    Public Sub MyFunction(param as string)
       ...
    End Sub
    'compile it as a dll, named mydll.dll
    
    'Your standardEXE:
    'In your References, check mydll
    Dim Somevariable As Class1
    Private Sub form_load
       Call Somevariable.MyFunction("kidding!")
       ...
    End Sub
    PS: its not necessary to compile your dll, if your are able to start VB twice, you can set your dllproject on RUN while programming in the other project(if you do so, you will have to specify something else in your references)

    Maybe this is something easier then c++

    WP



    Visual Basic 6.0 EE SP5 / .Net
    Windows XP

  11. #11
    Member
    Join Date
    Oct 2000
    Posts
    39

    Just Curious

    Sorry to switch the topic, but I was just curious,


    I know you can right your own api calls in C++,
    So does this mean you can also write them in C or is there a difference ?

  12. #12
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You can write them in C (a lot of the Win32 API is in C). Actually, it's harder to write one in C++ because by nature/convention, an API uses C-style name mangling.
    Technically, a C++ function exported as an API should be:
    Code:
    extern "C" __stdcall function() {
        ...
    }
    The extern "C" tells the compiler to turn off its name mangling whilst processing that function.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  13. #13
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    355
    parksie, i've had *great* trouble exporting funcs from a C++ DLL so they can be called in VB - could u tell me how *you* do it? cos there's so many ways, and none seem to work
    buzzwords are the language of fools

  14. #14
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Here's a bit of an example:

    test.cpp
    Code:
    extern "C" long __stdcall exportedfunction(long x) {
        return x * x;
    }
    test.def
    Code:
    LIBRARY "test.dll"
    
    EXPORTS
        exportedfunction
    To use these in VC++, just add them both to a Win32 DLL project (NOT MFC!!!), and it will sort it out for you. For other compilers, compile test.cpp as normal, and check out the linker documentation for passing a .def file to it.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  15. #15
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    355
    thanks, i use vc++ so it should be fine
    i was mising the "extern C" before - it was mangling the names wrong
    buzzwords are the language of fools

  16. #16

    Thread Starter
    Addicted Member jeroenh's Avatar
    Join Date
    Aug 2000
    Location
    Rotterdam, Holland
    Posts
    201
    I would like you all for you r input. I've made the DLL in C++ now and it works, so I'm very happy. Ican now do everything I want with it, and nobody else can use them. This is what I was looking for. Till the next time.
    Catch you later,

    Jeroen Hoekemeijer
    Code:
    If 1 = 2 Then MajorError

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