|
-
Oct 31st, 2000, 05:47 PM
#1
Thread Starter
Addicted Member
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
-
Oct 31st, 2000, 05:54 PM
#2
Frenzied Member
API Functions reside in Standard DLL files which can not be made in VB. They can be made in C++.
-
Nov 1st, 2000, 03:44 AM
#3
Thread Starter
Addicted Member
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
-
Nov 1st, 2000, 03:47 PM
#4
As far as I know, I don't think you need to register the DLL.
-
Nov 1st, 2000, 04:40 PM
#5
Frenzied Member
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
-
Nov 1st, 2000, 04:50 PM
#6
Monday Morning Lunatic
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
-
Nov 2nd, 2000, 03:07 AM
#7
Thread Starter
Addicted Member
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
-
Nov 2nd, 2000, 04:36 AM
#8
Monday Morning Lunatic
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
-
Nov 2nd, 2000, 06:33 AM
#9
Frenzied Member
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.
-
Nov 2nd, 2000, 07:49 AM
#10
Hyperactive Member
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
-
Nov 3rd, 2000, 03:51 PM
#11
Member
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 ?
-
Nov 3rd, 2000, 03:55 PM
#12
Monday Morning Lunatic
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
-
Nov 4th, 2000, 03:14 PM
#13
Hyperactive Member
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
-
Nov 4th, 2000, 03:51 PM
#14
Monday Morning Lunatic
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
-
Nov 5th, 2000, 05:21 AM
#15
Hyperactive Member
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
-
Nov 6th, 2000, 04:12 AM
#16
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|