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.

DLL Talk / Arguments passed by value and by reference

Author
Message
N3wton
10
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 16th Oct 2009 18:47 Edited at: 16th Oct 2009 18:48
Basically I have a dll...
and for the command _GetMousePos my function looks like

void _GetMousePos(int& x, int& y);

but how would I use the params in DBpro?

as in c++ i can just use;

int Mx, My;
_GetMousePos(Mx, My);
cout << Mx << ", " << My << endl;

Thanks
Yours
N3wton

Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 17th Oct 2009 01:06
You can't. DBPro commands can only return one value, even if that value is going into a parameter. (like the 'read' command)

N3wton
10
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 17th Oct 2009 01:14
Not even using memblocks and pointers

ohwel

Thanks

Yours
N3wton

Rudolpho
13
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 17th Oct 2009 11:34 Edited at: 17th Oct 2009 11:36
Well, of course you can use the memory commands to "simulate" it (it's the real deal, of course, but the syntax will be more messy, hence the quotation marks).
I'd really reccommend IanM's memory plugin, as it allows for peeking / poking other types than longwords as well.
You can't just get a reference to a variable's memory location though; you'll have to use raw pointers, which is obviously a downside.



Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 17th Oct 2009 15:30
What you should do in these situations is this:



That way you can effectively return multiple values (just store the values in global variables in C++, which can then be accessed by the GetMousePosX/Y commands)

Rudolpho
13
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 17th Oct 2009 17:10
Didn't see it was about a plugin
Then Diggsey's approach is the way to go; look at any DBP plugin and you'll find that that's how they do it.

Mistrel
Retired Moderator
13
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 18th Oct 2009 15:47
You can pass a pointer from DBP to a plugin. But this is very inefficient because of the process of allocating and deallocating memory every time.

The best solution is to just use two functions.

N3wton
10
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 18th Oct 2009 15:51
Cheers for your replys,

Unfotunatlly I only have the dll and not the source code

ohwel lol

Thanks again
Yours
N3wton

Rudolpho
13
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 18th Oct 2009 16:29
Ah, but then I'm fairly sure that the memory pointers will work.
Just make a memory area of 4 bytes (for a single integer) and pass the pointer to the function. This would most likely put the return value in your created memory area.

Something like this:


Again, for anything but longwords, I'd reccommend using IanM's extended memory handling library.

N3wton
10
Years of Service
User Offline
Joined: 3rd Jun 2009
Location: Leeds, UK
Posted: 18th Oct 2009 19:06
Thanks Rudolpho,

From looking at your code i've managed to get it to work

Thankyou everyone

Yours
N3wton

Login to post a reply

Server time is: 2019-10-19 07:58:31
Your offset time is: 2019-10-19 07:58:31