PDA

Click to See Complete Forum and Search --> : Not using But Creating an API Call


jeroenh
Oct 31st, 2000, 04:47 PM
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?:confused:

Vlatko
Oct 31st, 2000, 04:54 PM
API Functions reside in Standard DLL files which can not be made in VB. They can be made in C++.

jeroenh
Nov 1st, 2000, 02:44 AM
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.

Nov 1st, 2000, 02:47 PM
As far as I know, I don't think you need to register the DLL.

Vlatko
Nov 1st, 2000, 03:40 PM
No the DLL doesn't have to be registered in Windows.Just use it from VB:

Declare Function fname Lib dllname(byval arg1 as long,...) as Long or SmthElse

parksie
Nov 1st, 2000, 03:50 PM
To use a function in a DLL, you need to have a definition similar to this:

long __stdcall exportedfunc(long param) {
...
}

It's that __stdcall that's important. Second, link with a .def file which will look like:

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).

jeroenh
Nov 2nd, 2000, 02:07 AM
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?

parksie
Nov 2nd, 2000, 03:36 AM
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.

Vlatko
Nov 2nd, 2000, 05:33 AM
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.

WP
Nov 2nd, 2000, 06:49 AM
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:


'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

Silicon Valley
Nov 3rd, 2000, 02:51 PM
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 ?

parksie
Nov 3rd, 2000, 02:55 PM
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:

extern "C" __stdcall function() {
...
}

The extern "C" tells the compiler to turn off its name mangling whilst processing that function.

KENNNY
Nov 4th, 2000, 02:14 PM
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 :(

parksie
Nov 4th, 2000, 02:51 PM
Here's a bit of an example:

test.cpp

extern "C" long __stdcall exportedfunction(long x) {
return x * x;
}


test.def

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.

KENNNY
Nov 5th, 2000, 04:21 AM
thanks, i use vc++ so it should be fine :)
i was mising the "extern C" before - it was mangling the names wrong

jeroenh
Nov 6th, 2000, 03:12 AM
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.