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 :)
Printable View
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 :)
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:
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.Code:long __stdcall TestFunction(long lInput) {
return lInput + 5;
}
Next, you need to add a .DEF file. This can just be a source file again, but call it "testdll.def". Add the following:
This tells the linker what functions to export from the DLL for usage by other programs.Code:LIBRARY "testdll.dll"
EXPORTS
TestFunction
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
thanks man!
the .def file where do I put it ?
-source
-header
-ressource
or it doesn't matter it juste for the form ?
It needs to be in the project somewhere. It doesn't really go under any of those categories so put it in the root.
ok thx
ok and why when I write this :
they give to me these error ?Code:double __stdcall Barre( double Now, double Max)
double Barre;
if ((Max != 0) && (Now <= Max) {
Barre = Now / Max;
return Barre;
}
else
{
return 0;
}
}
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 ?
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;
}
}
I'm getting errors when I try this:
Errors:Code:#include <string>
using namespace std;
string __stdcall period(string t) {
t = t + '.';
return t;
}
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.
Nevermind. I named the function wrong in the .def file.
But now it crashes in VB when I try to use it.
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
Yeah, the VB native string is the BSTR.
A function that returns a string:
Note the L before the string! It is absolutely necessary and requires you to get familiar with the concept of UNICODE strings.Code:BSTR __stdcall RetString()
{
return SysAllocString(L"Hello, man!");
}
Thanks...
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
What's your VB code?
I was just stupid. Thx cornbee.
forgot to say i = testfunction(i)
:o