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:
Printable View
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:
API Functions reside in Standard DLL files which can not be made in VB. They can be made in C++.
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.
As far as I know, I don't think you need to register the DLL.
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
To use a function in a DLL, you need to have a definition similar to this:
It's that __stdcall that's important. Second, link with a .def file which will look like:Code:long __stdcall exportedfunc(long param) {
...
}
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).Code:LIBRARY "file.dll"
EXPORTS
exportedfunc
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?
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.
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.
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:
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)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
Maybe this is something easier then c++ :)
WP
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 ?
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:
The extern "C" tells the compiler to turn off its name mangling whilst processing that function.Code:extern "C" __stdcall function() {
...
}
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 :(
Here's a bit of an example:
test.cpp
test.defCode:extern "C" long __stdcall exportedfunction(long x) {
return x * x;
}
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.Code:LIBRARY "test.dll"
EXPORTS
exportedfunction
thanks, i use vc++ so it should be fine :)
i was mising the "extern C" before - it was mangling the names wrong
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.