| View previous topic :: View next topic |
| Would you like to see this implemented? |
| Yes |
|
36% |
[ 4 ] |
| Yes, but in a different way (please explain) |
|
0% |
[ 0 ] |
| No, wait for #define |
|
54% |
[ 6 ] |
| No (other reason) |
|
0% |
[ 0 ] |
| Not sure |
|
9% |
[ 1 ] |
|
| Total Votes : 11 |
|
| Author |
Message |
Titan
Joined: 11 Aug 2004 Posts: 5049 Location: imaginationland
|
Posted: Thu Oct 25, 2007 10:23 pm Post subject: DllCall function declaration |
|
|
As a better alternative to #define macros I propose we have a function declaration command for DLL functions - similar to VB and extern in C#.
| Code: | DllFunction, Name, "[DllFile\]Function" [, Type1, Type2, ... TypeN, "Cdecl ReturnType"]
; e.g.
DllFunction, MyFunc, GetScrollPos, UInt, Int
var := MyFunc(xyx, 1)
if (MyFunc(abc, 0) > 1)
ExitApp |
_________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2393
|
Posted: Wed Nov 07, 2007 4:05 am Post subject: |
|
|
simple but familiar and effective  |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Wed Nov 07, 2007 9:52 am Post subject: |
|
|
I voted YES even though I do not know the concept of #define macros. The reasons I like it, is that this simplifies the call of an dll when it is called multiple times.
The only drawback I see is that it would be more difficult to find the function defition, since a normal function call and a dll function call look the same (both look like "func(a,b)"), but the definitions are "func(a,b){...}" and "DllFunc, func,...". _________________ Ciao
toralf  |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4002 Location: Pittsburgh
|
Posted: Wed Nov 07, 2007 6:34 pm Post subject: |
|
|
How is it better or simpler than | Code: | #define MyFunc(x,y,z) dllcall("path\dll","str",x,"UInt",y,"Int",z,"CDECL Int")
; ...
var := MyFunc("GetPos",10,-1) | You need special constructs for this, have to specify standard vs. C calls with something non-standard, etc. |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5049 Location: imaginationland
|
Posted: Wed Nov 07, 2007 6:46 pm Post subject: |
|
|
Concider how much longer (if ever) Chris will take to write #define compared to another command. Also many discourage preprocessor directives for reasons similar to goto. PHP, .NET and other new languages have the concept I'm suggesting which proves it's superior. _________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4002 Location: Pittsburgh
|
Posted: Wed Nov 07, 2007 6:57 pm Post subject: |
|
|
You don’t have to wait for Chris. Write your own preprocessor, based on regular expressions. It will not take a week, I guess. I did something similar in a few hours.
AHK is not meant for huge projects, independent modules... In this case macros are fine: simple and powerful. They have been used for many years, so programmers are familiar with them. |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5049 Location: imaginationland
|
Posted: Wed Nov 07, 2007 7:22 pm Post subject: |
|
|
AHK is not meant just for C programmers either. As you've probably guessed I'm using C# wrappers as a workaround, but for the mainstream version I think a command would be more pratical in terms of usability and implimentation. _________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
Andreone
Joined: 20 Jul 2007 Posts: 257 Location: Paris, France
|
Posted: Thu Nov 08, 2007 12:04 am Post subject: |
|
|
To be honest, I said no first. But, after all, why not, unless this would mean that define feature was given up.
The DllFunction declaration is simple enough for everybody. This is nice.
But the define has other capabilities (including ddl function declaration) that would not see being abandoned.
So why not implementing both?
(I know, it's easy to say for me since I'm not involved in the development ) |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Mon Nov 19, 2007 6:02 pm Post subject: |
|
|
| I voted for "wait for define" because I wouldn't want to have a feature like DllFunction that later becomes mostly redundant due to #define. However, since some frown upon #define for code purity reasons, maybe someone knows of something superior to it that's almost as flexible. |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4002 Location: Pittsburgh
|
Posted: Mon Nov 19, 2007 6:45 pm Post subject: |
|
|
There are a few problems with #define. If you know one, post it here.
1. Macros are global across #include files, but are local to large source files. This makes it hard to foresee all the possible (unintended) effects. Strict coding (naming) rules have to be followed for large projects with multiple include files.
2. Macro parameters are substituted literally:
| Code: | | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
It presents a problem with MAX(x++,0) type calling. MAX increments x once for negative x, but twice for positive. If MAX was a function, the results would be different. To solve the problem blocks are needed with local variables, like
| Code: | | #define MAX(a, b) {_a := a; _b := b; _a > _b ? _a : _b} |
but then functions were simpler.
Macros are dangerous, but very powerful. They should be recommended for advanced users, only. Inline function expansion would be sufficient for many simple applications. They speed up scripts, because function wrappers are otherwise slow (especially with long returned strings). |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Mon Nov 19, 2007 6:48 pm Post subject: |
|
|
| Thanks for the great info. |
|
| Back to top |
|
 |
|