AutoHotkey Community

It is currently May 26th, 2012, 11:57 pm

All times are UTC [ DST ]




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 21 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: September 17th, 2009, 6:52 am 
Начиная с версии .NET 2.0 достаточно указать в экспортируемых методах директиву
.export [<ordinal>] as <export_name>
или
.export [<ordinal>]
все остальное компилятор сделает сам. Не правда ли легко?
К тому же, это позволяет без изменений компилировать исходный текст как под x32, так и под x64.

Вот первоисточник
http://qinjunit.googlepages.com/NET.2.0.IL.Assembler.pdf

The good news is that version 2.0 of the IL assembler does not require these directives at
all, as long as the v-table and VTFixup table are used for unmanaged exports only. Just specify
the .export directives in the methods you want to export to the unmanaged world, and the
flags, the v-table, and its fixups will be generated automatically by the compiler, with the slot
size adjusted for the target platform:

.assembly extern mscorlib { auto }
.assembly YDD { }
.module YDD.dll
.method public static void Yabba()
{
.export [1]
ldstr "Yabba"
call void [mscorlib]System.Console::WriteLine(string)
ret
}
.method public static void Dabba()
{
.export [2]
ldstr "Dabba"
call void [mscorlib]System.Console::WriteLine(string)
ret
}
.method public static void Doo()
{
.export [3]
ldstr "Doo!"
call void [mscorlib]System.Console::WriteLine(string)
ret
}[url][/url]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2009, 12:57 am 
Offline

Joined: June 24th, 2009, 1:37 am
Posts: 23
I tried this process starting from the example and everything worked fine.

However, as soon as I invoke a method from a custom referenced (additional) DLL, the DllCall() fails, returning ErrorLevel 0xe0434f4d, LastError 2.

Do I need to do something special to utilize additionally referenced DLLs (not directly accessed by AHK)?

AHK:
Code:
MsgBox % DllCall("aQueryWrapper.dll\echo", "Str", "lol this really works", "Cdecl Str")
MsgBox % ErrorLevel " / " A_LastError
MsgBox % DllCall("aQueryWrapper.dll\query", "Str", "192.168.1.198:27015", "Cdecl Str")
MsgBox % ErrorLevel " / " A_LastError


Call chains:
aQuery.ahk DllCall() -> aQueryWrapper.dll\echo()
aQuery.ahk DllCall() -> aQueryWrapper.dll\query() -> aQueryLib.QueryGameServer()

The call to echo() is verbatim copied from the sample code in the first post. The call to query() uses an identical type signature as echo().

The call to echo() works perfectly (ErrorLevel=0). As soon as I hit the call in query() to the additional referenced DLL I get the failure. If I remove everything from the function that references this DLL, it executes fine.

The weird thing is I have written a C# console test app, and calling query() from there, with the exact same arguments, works fine there. In fact I went so far as to hardcode default arguments into the beginning of query(), thus ignoring passed arguments entirely. The console app continues to work and DllCall() continues to fail.


Last edited by joelpt on September 21st, 2009, 1:11 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2009, 12:58 am 
Offline

Joined: June 24th, 2009, 1:37 am
Posts: 23
Also, the download links in the original post are turning up empty pages for me (many of Titan's scripts are).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2009, 8:48 am 
@joelpt
OK. Have you already send him a "C'mon boy, don't do that to me! :x" - PM ??


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2009, 9:16 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Have you tried manually loading the dll so DllCall doesn't automatically try to unload it? It's occasionally necessary for native dlls; I think individual .NET assemblies can't be unloaded anyway, so it probably won't help in this case.
Code:
DllCall("LoadLibrary", "str", "aQueryWrapper.dll")

If you don't have any luck with that, you might like to try .NET Framework Interop.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2009, 8:40 pm 
Offline

Joined: June 24th, 2009, 1:37 am
Posts: 23
Lexikos wrote:
If you don't have any luck with that, you might like to try .NET Framework Interop.

That did the trick, thanks. In fact that turned out to be better suited to my needs (lots of calls into DLL code on a fast timer).


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 21 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Bing [Bot], Google Feedfetcher and 54 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