Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / DLL parameters changed?

Author
Message
Niijel
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location:
Posted: 13th Sep 2002 03:20
I have a small test dll that contains 2 functions the first multiplies the input integer by 2 and returns an integer result. The second multiplies the input integer by 3 and returns an integer result.

I use this with a small DB program which displays the results of the 2 functions.

It works unchanged in both DB and DBpro
EXCEPT!!
The dbpro output is two huge numbers both incorrect!
Has the format of an integer changed?
The dll uses DWORD for these parameters.
Any help much appreciated...
Niijel
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location:
Posted: 13th Sep 2002 04:09
DONT PANIC.

I found the problem (in my dll)

I was returning a variable type int
this was what i had in the dll...

DARKDLL DWORD dubl(int f)
{
int ans;
ans = f * 2;
return ans;

}

it should have been...


DARKDLL DWORD dubl(int f)
{
int ans;
ans = f * 2;
return *((DWORD*)&ans);

}

be careful - the first worked ok in DB but returns an incorrect value in DBpro (else my dll source control is really messed up)the second works fine in both.

Niijel
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location:
Posted: 13th Sep 2002 12:38
anyone out there want to explain (in easy words) what
*((DWORD*)&ans);
actually does?

MrTAToad
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 13th Sep 2002 14:54
Its along the lines of returning the address of ans (as a DWORD), which, if your just returning the result is a little over-the-top.

In addition, ans may not exist when the function exits, resulting in a invalid memory location (and probably a crash later on).

Yes, I really am THAT good...
Niijel
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location:
Posted: 13th Sep 2002 20:29
yes anything along the lines of:-

y = *&x seems a bit pointless to me...

I notice the example dll that comes with the DBv1 extras wasnt included with DBpro, I found it very useful and feel it should be. Or how about a definitive description of the interface in the docs?

Login to post a reply

Server time is: 2024-04-19 04:23:31
Your offset time is: 2024-04-19 04:23:31