Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: brew on June 01, 2007, 07:03 PM

Title: stupid question about dlls....
Post by: brew on June 01, 2007, 07:03 PM
im trying to make just ANY dll right now that works

//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;
}

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
Title: Re: stupid question about dlls....
Post by: l2k-Shadow on June 01, 2007, 07:30 PM
are you calling it from VB? if so do this:



extern "C" {

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


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.
Title: Re: stupid question about dlls....
Post by: brew on June 01, 2007, 08:23 PM
just tried that. it now gives me an error "bad dll calling convention"... grr
Title: Re: stupid question about dlls....
Post by: l2k-Shadow on June 01, 2007, 08:45 PM
Quote from: brew on June 01, 2007, 08:23 PM
just tried that. it now gives me an error "bad dll calling convention"... grr

yeah VB sucks, it works if you compile the prog though.
Title: Re: stupid question about dlls....
Post by: brew on June 01, 2007, 09:32 PM
just tried. it worked (thank god) but it gave me the unexpected result. "1697" when it was supposed to be "3005"
Title: Re: stupid question about dlls....
Post by: l2k-Shadow on June 01, 2007, 09:34 PM
mind uploading your calling program, and your dll?
Title: Re: stupid question about dlls....
Post by: brew on June 01, 2007, 09:37 PM
sure. http://zenixstudios.com/f.php?f=xjskjkpo


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;
}
}

Title: Re: stupid question about dlls....
Post by: l2k-Shadow on June 01, 2007, 10:20 PM
aha your call is the problem gotta ByVal asdf
Title: Re: stupid question about dlls....
Post by: brew on June 01, 2007, 10:20 PM
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?
Title: Re: stupid question about dlls....
Post by: l2k-Shadow on June 01, 2007, 10:41 PM
did you change the arguments?
Title: Re: stupid question about dlls....
Post by: brew on June 01, 2007, 10:55 PM
yes. in my call.
doesn't matter now, i was able to get char * arguments working properly (i'm suprised) :-D
muwhahahahaha
Title: Re: stupid question about dlls....
Post by: UserLoser on June 02, 2007, 02:07 AM
has to be __stdcall for vb to work w/ it.
Title: Re: stupid question about dlls....
Post by: brew on June 02, 2007, 09:24 AM
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. :-(
Title: Re: stupid question about dlls....
Post by: UserLoser on June 02, 2007, 12:21 PM
Don't know how you have it working, must be a coincedence or something because the only calling convention that VB understands is __stdcall.
Title: Re: stupid question about dlls....
Post by: l2k-Shadow on June 02, 2007, 12:30 PM
He is doing this:

Declare Function "test" lib "testdll" () As Long


in C++:

extern "C"
{
__declspec(dllexport) int test()
{
return 5;
}
}

exports function "test"

however,

__declspec(dllexport) int __stdcall test()
{
return 5;
}

exports function "_test@16"

hence trying to call test, when the name compiled is _test@16 would return entry point not found.
Title: Re: stupid question about dlls....
Post by: UserLoser on June 02, 2007, 12:40 PM
Ugh, add a definition file.

http://www.digitalmars.com/ctg/ctgDefFiles.html#exports
Title: Re: stupid question about dlls....
Post by: l2k-Shadow on June 02, 2007, 02:34 PM
Quote from: UserLoser on June 02, 2007, 12:40 PM
Ugh, add a definition file.

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

right, but that's something he obviously doesn't have.
Title: Re: stupid question about dlls....
Post by: brew on June 02, 2007, 03:22 PM
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
Title: Re: stupid question about dlls....
Post by: MyndFyre on June 03, 2007, 05:44 PM
Quote from: UserLoser on June 02, 2007, 12:40 PM
Ugh, add a definition file.

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

According to Microsoft, a .def file shouldn't be necessary if you use __declspec(dllexport).
Title: Re: stupid question about dlls....
Post by: xp on June 03, 2007, 09:28 PM
Quote from: brew on June 01, 2007, 09:37 PM
sure. http://zenixstudios.com/f.php?f=xjskjkpo


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;
}
}



Coincidentally, the Visual Basic Integer and the C int type are two very different things.
Title: Re: stupid question about dlls....
Post by: l2k-Shadow on June 03, 2007, 10:07 PM
yes, int in C is a 32bit integer, it's a 16bit integer in VB.
Title: Re: stupid question about dlls....
Post by: MyndFyre on June 03, 2007, 11:01 PM
Quote from: l2k-Shadow on June 03, 2007, 10:07 PM
yes, int in C is a 32bit integer, it's a 16bit integer in VB.

C does not define a standard size for int.  Most compilers implement as a 32-bit value.  However, some may implement it as 16.
Title: Re: stupid question about dlls....
Post by: brew on June 06, 2007, 09:24 PM
Then what's a long (by default) ?
I'm using Visual C++....
Title: Re: stupid question about dlls....
Post by: l2k-Shadow on June 06, 2007, 10:34 PM
Quote from: brew on June 06, 2007, 09:24 PM
Then what's a long (by default) ?
I'm using Visual C++....

check using sizeof()


#include <iostream.h>

void main()
{
     cout << "Int: " << sizeof(int) << "\n" << "Long: " << sizeof(long) << "\n";
}
Title: Re: stupid question about dlls....
Post by: brew on June 07, 2007, 08:26 AM
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?
Title: Re: stupid question about dlls....
Post by: l2k-Shadow on June 07, 2007, 10:24 AM
have to write a converting function if you're on a little endian system.
Title: Re: stupid question about dlls....
Post by: MyndFyre on June 07, 2007, 05:42 PM
Quote from: brew on June 07, 2007, 08:26 AM
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?

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
Title: Re: stupid question about dlls....
Post by: brew on June 08, 2007, 07:10 AM
For a 64 bit data type couldn't you also just use a double?
Title: Re: stupid question about dlls....
Post by: l2k-Shadow on June 08, 2007, 09:55 AM
Quote from: brew on June 08, 2007, 07:10 AM
For a 64 bit data type couldn't you also just use a double?

yes but double is a floating point number.
Title: Re: stupid question about dlls....
Post by: brew on June 08, 2007, 12:11 PM
it could still store up to 2^64 in whole numbers with no decimals, right? Theoretically?
Title: Re: stupid question about dlls....
Post by: l2k-Shadow on June 08, 2007, 01:01 PM
Quote from: brew on June 08, 2007, 12:11 PM
it could still store up to 2^64 in whole numbers with no decimals, right? Theoretically?

no
Title: Re: stupid question about dlls....
Post by: MyndFyre on June 08, 2007, 03:42 PM
Quote from: brew on June 08, 2007, 12:11 PM
it could still store up to 2^64 in whole numbers with no decimals, right? Theoretically?
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.