Valhalla Legends Forums Archive | C/C++ Programming | stupid question about dlls....

AuthorMessageTime
BreW
im trying to make just ANY dll right now that works
[code]
//in the dlltest.h file
#ifndef DLLTEST_H_
#define DLLTEST_H_
__declspec(dllexport) int asdfness(int asdf);
#endif

//in the dlltest.cpp file
#include "dlltest.h"

__declspec(dllexport)
int asdfness(int asdf) {
int lolz = 0;
lolz = asdf + 3000;
return lolz;
}
[/code]
and it keeps saying entry point not found. and i looked at about 100 different sites and they all said the same exact thing. soooo... anyone see anything wrong with this code? i'm a big noobie so i bet it's a syntax error or something
June 2, 2007, 12:03 AM
l2k-Shadow
are you calling it from VB? if so do this:

[code]

extern "C" {

__declspec(dllexport)
int asdfness(int asdf) {
int lolz = 0;
lolz = asdf + 3000;
return lolz;
}
}
[/code]

extern C will compile it as a C function without adding extra crap to your export name, also you don't need the header file.
June 2, 2007, 12:30 AM
BreW
just tried that. it now gives me an error "bad dll calling convention"... grr
June 2, 2007, 1:23 AM
l2k-Shadow
[quote author=brew link=topic=16751.msg169610#msg169610 date=1180747390]
just tried that. it now gives me an error "bad dll calling convention"... grr
[/quote]

yeah VB sucks, it works if you compile the prog though.
June 2, 2007, 1:45 AM
BreW
just tried. it worked (thank god) but it gave me the unexpected result. "1697" when it was supposed to be "3005"
June 2, 2007, 2:32 AM
l2k-Shadow
mind uploading your calling program, and your dll?
June 2, 2007, 2:34 AM
BreW
sure. http://zenixstudios.com/f.php?f=xjskjkpo

[code]
Private Declare Function asdfness Lib "dlltest" (asdf As Integer) As Integer
Private Sub Form_Load()
Dim asdf As Integer
asdf = 5
asdf = asdfness(asdf)
MsgBox asdf
End Sub

extern "C" {
int __declspec(dllexport) asdfness(int asdf) {
int lolz = 0;
lolz = asdf + 3000;
return lolz;
}
}

[/code]
June 2, 2007, 2:37 AM
l2k-Shadow
aha your call is the problem gotta ByVal asdf
June 2, 2007, 3:20 AM
BreW
Crashes now. Really bad, too. It freezes for like 6-7 seconds before i get the error message
Perhaps i should change the arguments in the dll?
June 2, 2007, 3:20 AM
l2k-Shadow
did you change the arguments?
June 2, 2007, 3:41 AM
BreW
yes. in my call.
doesn't matter now, i was able to get char * arguments working properly (i'm suprised) :-D
muwhahahahaha
June 2, 2007, 3:55 AM
UserLoser
has to be __stdcall for vb to work w/ it.
June 2, 2007, 7:07 AM
BreW
oh? it works without _stdcall when compiled though. might be something with the pcode when you test in the ide.

**edit
using _stdcall makes it not work at all... now it says entry point not found. :-(
June 2, 2007, 2:24 PM
UserLoser
Don't know how you have it working, must be a coincedence or something because the only calling convention that VB understands is __stdcall.
June 2, 2007, 5:21 PM
l2k-Shadow
He is doing this:
[code]
Declare Function "test" lib "testdll" () As Long
[/code]

in C++:
[code]
extern "C"
{
__declspec(dllexport) int test()
{
return 5;
}
}
[/code]
exports function "test"

however,
[code]
__declspec(dllexport) int __stdcall test()
{
return 5;
}
[/code]
exports function "_test@16"

hence trying to call test, when the name compiled is _test@16 would return entry point not found.
June 2, 2007, 5:30 PM
UserLoser
Ugh, add a definition file.

http://www.digitalmars.com/ctg/ctgDefFiles.html#exports
June 2, 2007, 5:40 PM
l2k-Shadow
[quote author=UserLoser link=topic=16751.msg169630#msg169630 date=1180806010]
Ugh, add a definition file.

http://www.digitalmars.com/ctg/ctgDefFiles.html#exports
[/quote]

right, but that's something he obviously doesn't have.
June 2, 2007, 7:34 PM
BreW
I've tried using a definition file at least 3 times before, and they just plain don't work. Am I doing something wrong? And I know the linker is recognizing them. I've gotten some errors with it apparently interfering with the __stdcall
June 2, 2007, 8:22 PM
Myndfyr
[quote author=UserLoser link=topic=16751.msg169630#msg169630 date=1180806010]
Ugh, add a definition file.

http://www.digitalmars.com/ctg/ctgDefFiles.html#exports
[/quote]

According to Microsoft, a .def file shouldn't be necessary if you use __declspec(dllexport).
June 3, 2007, 10:44 PM
xp
[quote author=brew link=topic=16751.msg169615#msg169615 date=1180751833]
sure. http://zenixstudios.com/f.php?f=xjskjkpo

[code]
Private Declare Function asdfness Lib "dlltest" (asdf As Integer) As Integer
Private Sub Form_Load()
Dim asdf As Integer
asdf = 5
asdf = asdfness(asdf)
MsgBox asdf
End Sub

extern "C" {
int __declspec(dllexport) asdfness(int asdf) {
int lolz = 0;
lolz = asdf + 3000;
return lolz;
}
}

[/code]
[/quote]

Coincidentally, the Visual Basic Integer and the C int type are two very different things.
June 4, 2007, 2:28 AM
l2k-Shadow
yes, int in C is a 32bit integer, it's a 16bit integer in VB.
June 4, 2007, 3:07 AM
Myndfyr
[quote author=l2k-Shadow link=topic=16751.msg169695#msg169695 date=1180926468]
yes, int in C is a 32bit integer, it's a 16bit integer in VB.
[/quote]

C does not define a standard size for int.  Most compilers implement as a 32-bit value.  However, some may implement it as 16.
June 4, 2007, 4:01 AM
BreW
Then what's a long (by default) ?
I'm using Visual C++....
June 7, 2007, 2:24 AM
l2k-Shadow
[quote author=brew link=topic=16751.msg169844#msg169844 date=1181183085]
Then what's a long (by default) ?
I'm using Visual C++....
[/quote]

check using sizeof()

[code]
#include <iostream.h>

void main()
{
    cout << "Int: " << sizeof(int) << "\n" << "Long: " << sizeof(long) << "\n";
}
[/code]
June 7, 2007, 3:34 AM
BreW
what the hell! so in VC++ an integer and a long are the same size.. what is the difference between the two? also what does VC++ use for a big endian 2 byte data type?
June 7, 2007, 1:26 PM
l2k-Shadow
have to write a converting function if you're on a little endian system.
June 7, 2007, 3:24 PM
Myndfyr
[quote author=brew link=topic=16751.msg169856#msg169856 date=1181222805]
what the hell! so in VC++ an integer and a long are the same size.. what is the difference between the two? also what does VC++ use for a big endian 2 byte data type?
[/quote]

Since VC++ only targets Windows and Windows runs on little-endian systems only, VC++ does not use a big-endian 2-byte type.

Standard 2-byte type is short int.

These are the numeric types and macros defined in by the Windows platform SDK:

char = CHAR = signed 8-bit
unsigned char = BYTE = unsigned 8-bit
short int = SHORT = signed 16-bit
unsigned short int = WORD = unsigned 16-bit
long int = LONG = signed 32-bit
unsigned long int = DWORD = unsigned 32-bit
long long int = LONGLONG = __int64 = signed 64-bit
unsigned long long int = ULONGLONG = __uint64 = unsigned 64-bit
June 7, 2007, 10:42 PM
BreW
For a 64 bit data type couldn't you also just use a double?
June 8, 2007, 12:10 PM
l2k-Shadow
[quote author=brew link=topic=16751.msg169898#msg169898 date=1181304656]
For a 64 bit data type couldn't you also just use a double?
[/quote]

yes but double is a floating point number.
June 8, 2007, 2:55 PM
BreW
it could still store up to 2^64 in whole numbers with no decimals, right? Theoretically?
June 8, 2007, 5:11 PM
l2k-Shadow
[quote author=brew link=topic=16751.msg169907#msg169907 date=1181322667]
it could still store up to 2^64 in whole numbers with no decimals, right? Theoretically?
[/quote]

no
June 8, 2007, 6:01 PM
Myndfyr
[quote author=brew link=topic=16751.msg169907#msg169907 date=1181322667]
it could still store up to 2^64 in whole numbers with no decimals, right? Theoretically?
[/quote]
Using a double invokes the floating point coprocessor.  That means that the floating point unit is going to use a mantissa and floating point section.  So no.
June 8, 2007, 8:42 PM

Search