AutoHotkey Community

It is currently May 27th, 2012, 1:00 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: September 9th, 2005, 5:50 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
I try to interface AHK to a C library, compiled to a DLL with Visual Studio .Net. In the DLL all the function names start with double underscore, which is ugly, but at least they are found. The problem is that AHK's DllCall thinks that the functions need no parameters (they do) and give the ErrorLevel Axx, with the number of bytes passed to the function. I'd like AHK to execute that function call anyway, since I know that the parameters are correct. Or is there a way around?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2005, 6:05 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
If the functions in the DLL aren't declared as "__stdcall", you probably need to pass "CDecl" as DllCall's last parameter.

If that doesn't help, you might try experimenting with different settings for how the functions in the DLL are defined and compiled. In case it helps, when working on DLLCall I created a simple DLL for testing purposes. Here is a simplified version of its code:
Code:
#include "stdafx.h"

extern "C" __declspec(dllexport) char * __stdcall StrCopy(char *buf, char *in)
{
   return strcpy(buf, in);
}


BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    return TRUE;
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2005, 6:43 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Chris, I did not compile that DLL, but downloaded. Is there a way to figure out in general if the functions in there are declared as "__stdcall" or not? In this case, your suggestion about "CDecl" as DllCall's last parameter works. THANKS! Could you add some clarifications to the help file? Reading it I had the impression that I only need it if the functions return something. In my case they don't. (At call the double underscore prefix of the function names cannot be avoided, right?)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2005, 2:01 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Laszlo wrote:
Is there a way to figure out in general if the functions in there are declared as "__stdcall" or not?
I suspect there is, but I don't know how (I don't have much knowledge of DLL file structure).

Quote:
I had the impression that I only need [Cdecl] if the functions return something. In my case they don't.
I'm not sure how to reword the Cdecl section to clarify it. Here is what it says now:
Quote:
The word Cdecl is normally omitted because most functions use the standard calling convention rather than the "C" calling convention (functions such as wsprintf that accept a varying number of arguments are exceptions to this).


Quote:
...the double underscore prefix of the function names cannot be avoided, right?
I think that's true because it's involves how the DLL stores the function names internally, which in turn is related to how the DLL was originally compiled and linked.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2005, 4:01 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Something like the following could be added to the help (in the beginning of the explanation of the last parameter of the DllCall):

The word Cdecl in the last parameter string specifies that the called function in the DLL was not declared as "__stdcall", that is, C calling syntax is to be used. An indication of the need for Cdecl is when your DllCall returns an error message An, as if it did not need any parameters.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2005, 4:23 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I think "__stdcall" is just how it's written in C syntax; other languages might have different syntax to do the same thing.

In any case, I'll mention your discovery of the ErrorLevel clue in two places, and try to clarify it in other ways. Thanks for the specifics.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], sejhayqnn and 39 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group