|
Thread: Dll
-
Mar 5th, 2001, 05:17 PM
#1
Thread Starter
Junior Member
Can someone be nice and explain me how to make a dll with MS Visual C++ 6 (step by step)
I know C++, Im a newbie with vb but i know how to call funtion from a alredy make dll (like mcisendstring in winmm) so be nice and explain to me
-
Mar 5th, 2001, 05:30 PM
#2
Monday Morning Lunatic
Firstly, you create a new project "Win32 DLL", not an MFC one. Call it "testdll" (for simplicity). Add a new blank source file called "testdll.cpp", and add the following code:
Code:
long __stdcall TestFunction(long lInput) {
return lInput + 5;
}
Now, the only thing that's different here is the __stdcall part. This tells it which way to call the function. This calling convention is the one used by the Windows API since it's simpler to program for.
Next, you need to add a .DEF file. This can just be a source file again, but call it "testdll.def". Add the following:
Code:
LIBRARY "testdll.dll"
EXPORTS
TestFunction
This tells the linker what functions to export from the DLL for usage by other programs.
Compile this and hopefully you should have a DLL.
The definition for this function is:
Code:
Declare Function TestFunction Lib "testdll" (ByVal lInput As Long) As Long
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
-
Mar 5th, 2001, 05:33 PM
#3
Thread Starter
Junior Member
-
Mar 5th, 2001, 06:00 PM
#4
Thread Starter
Junior Member
the .def file where do I put it ?
-source
-header
-ressource
or it doesn't matter it juste for the form ?
-
Mar 5th, 2001, 06:10 PM
#5
Monday Morning Lunatic
It needs to be in the project somewhere. It doesn't really go under any of those categories so put it in the root.
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
-
Mar 5th, 2001, 06:14 PM
#6
Thread Starter
Junior Member
-
Mar 5th, 2001, 08:15 PM
#7
Thread Starter
Junior Member
ok and why when I write this :
Code:
double __stdcall Barre( double Now, double Max)
double Barre;
if ((Max != 0) && (Now <= Max) {
Barre = Now / Max;
return Barre;
}
else
{
return 0;
}
}
they give to me these error ?
C:\Benoit\Informatique\WylerTeam\WTDll\WTDll.cpp(2) : warning C4518: 'double ' : storage-class or type specifier(s) unexpected here; ignored
C:\Benoit\Informatique\WylerTeam\WTDll\WTDll.cpp(2) : error C2146: syntax error : missing ';' before identifier 'Barre'
C:\Benoit\Informatique\WylerTeam\WTDll\WTDll.cpp(2) : fatal error C1004: unexpected end of file found
why I can't use double ?
-
Mar 5th, 2001, 11:02 PM
#8
Code:
double __stdcall Barre( double Now, double Max)
{ <--- Try adding a brcket here, see if that helps...
double Barre;
if ((Max != 0) && (Now <= Max) {
Barre = Now / Max;
return Barre;
}
else
{
return 0;
}
}
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 7th, 2002, 01:57 PM
#9
Stuck in the 80s
I'm getting errors when I try this:
Code:
#include <string>
using namespace std;
string __stdcall period(string t) {
t = t + '.';
return t;
}
Errors:
Linking...
vbshelfex.def : error LNK2001: unresolved external symbol Characters
Debug/vbshelfex.lib : fatal error LNK1120: 1 unresolved externals
LINK : fatal error LNK1141: failure during build of exports file
Error executing link.exe.
-
May 7th, 2002, 01:58 PM
#10
Stuck in the 80s
Nevermind. I named the function wrong in the .def file.
But now it crashes in VB when I try to use it.
-
May 7th, 2002, 02:16 PM
#11
Monday Morning Lunatic
VB doesn't understand C++ strings, which are actually a specific class.
To pass strings back to VB, you need to go back to string buffers (or use the COM strings which I'm sure CB or someone else will pop in with)...
http://www.parksie.net/StringDLL.zip
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
-
May 10th, 2002, 05:14 AM
#12
Yeah, the VB native string is the BSTR.
A function that returns a string:
Code:
BSTR __stdcall RetString()
{
return SysAllocString(L"Hello, man!");
}
Note the L before the string! It is absolutely necessary and requires you to get familiar with the concept of UNICODE strings.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 10th, 2002, 11:04 AM
#13
Stuck in the 80s
-
Sep 15th, 2003, 11:25 AM
#14
Member
troubles
I did the following as shown, except I named it sbuff. When I implemented this in the vb app, I could not get the value I sent to be incremented by 5. Any suggestions?
sbuff.cpp:
long __stdcall TestFunction(long lInput) {
return lInput + 5;
}
sbuff.def:
LIBRARY "sbuff.dll"
EXPORTS
TestFunction
Declare Function TestFunction Lib "sbuff" (ByVal lInput As Long) As Long
Last edited by SeaCapnJ; Sep 15th, 2003 at 11:30 AM.
-
Sep 16th, 2003, 01:49 AM
#15
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 16th, 2003, 10:05 AM
#16
Member
doh
I was just stupid. Thx cornbee.
forgot to say i = testfunction(i)
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
|