AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DLLCall & Visual Basic.NET

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Dave-X



Joined: 24 Oct 2009
Posts: 17

PostPosted: Sat Oct 24, 2009 6:11 pm    Post subject: DLLCall & Visual Basic.NET Reply with quote

I wrote a very simple DLL in Visual Basic.NET with one single function to return the string it receives to all uppercase.

The VB.Net DLL code is:

Code:
Public Class Engine
    Function Test(ByVal Text As String) As String
        Return Text.ToUpper
    End Function
End Class


Now when I tried to DllCall the function from AHK as follows.

Code:
String_Test := DllCall("Engine.dll\Test", str, "test")
Msgbox %String_Test%


I also tried.

Code:
String_Test := DllCall("Engine.dll\Engine.Test", str, "test")


Each time I get a -4, "The specified function could not be found inside the DLL"

Can anyone help explain? Thanks!
Back to top
View user's profile Send private message
txquestor



Joined: 22 Aug 2009
Posts: 294

PostPosted: Sat Oct 24, 2009 6:52 pm    Post subject: Reply with quote

Read this:
Quote:

Finally, when passing a string-variable to a function that will not change the length of the string, performance is improved by passing the variable by address (e.g. &MyVar) rather than as a "str" (especially when the string is very long). The following example converts a string to uppercase: DllCall("CharUpper", uint, &MyVar)


Code:

String_Test := DllCall("Engine.dll\Test",  uint, &String_Test)
Msgbox %String_Test%


Good Luck, Surprised
_________________

"Man's quest for knowledge is an expanding series whose limit is infinity"
Back to top
View user's profile Send private message
Dave-X



Joined: 24 Oct 2009
Posts: 17

PostPosted: Sat Oct 24, 2009 7:01 pm    Post subject: Reply with quote

Same results. It still fails to even find the function in the DLL, it's as if it's not there. So it's not actually executing any code. Either my syntax is wrong, I'm writing the DLL wrong. Maybe it's the VB.Net language or the fact it's x64?

I'm not sure what's wrong or what I'm doing wrong.
Back to top
View user's profile Send private message
txquestor



Joined: 22 Aug 2009
Posts: 294

PostPosted: Sat Oct 24, 2009 7:06 pm    Post subject: Reply with quote

Did you make a 32 bit DLL Question

Search the forum for using/creating Dll's
I remember someone wrote a mini help tutorial.
_________________

"Man's quest for knowledge is an expanding series whose limit is infinity"
Back to top
View user's profile Send private message
Dave-X



Joined: 24 Oct 2009
Posts: 17

PostPosted: Sat Oct 24, 2009 8:33 pm    Post subject: Reply with quote

No, it's x64 running on x64. Also, I managed to get a -2 error now, using the &String, which is "The return type or one of the specified arg types is invalid. This error can also be caused by passing an expression that evaluates to a number to a string (str) argument."

I recompiled a second version as x86 which did not change any results. Neutral
Back to top
View user's profile Send private message
txquestor



Joined: 22 Aug 2009
Posts: 294

PostPosted: Sat Oct 24, 2009 9:09 pm    Post subject: Reply with quote

Here is one of the links.
http://www.autohotkey.com/forum/topic20273.html
http://www.autohotkey.com/forum/topic20765-15.html
http://www.codeproject.com/KB/COM/com_in_c1.aspx#DLL

Quote:
DLLcall also can address a memory location in the Dll instead of
the function name - have you tried this?

http://www.autohotkey.com/forum/viewtopic.php?t=45405

Dll Info
http://www.autohotkey.com/docs/commands/DllCall.htm
http://www.autohotkey.com/forum/topic3687.html
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=517&lngWId=10
_________________

"Man's quest for knowledge is an expanding series whose limit is infinity"
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Sun Oct 25, 2009 8:26 am    Post subject: Reply with quote

AutoHotkey is currently only 32-bit, so it can only load 32-bit DLL files. I'm not sure how that applies to .NET assemblies though since they work a little differently. In any case, DllCall will only work with unmanaged functions/entry-points. Try CLR.ahk instead.
Quote:
Also, I managed to get a -2 error now, using the &String, which is "The return type or one of the specified arg types is invalid.
If DllCall detects a syntax error or invalid type parameter, it will set ErrorLevel to -2 and not even try to load the DLL.
Back to top
View user's profile Send private message Visit poster's website
Scratch



Joined: 22 Jan 2009
Posts: 72

PostPosted: Sun Oct 25, 2009 4:52 pm    Post subject: Workaround Reply with quote

http://www.autohotkey.com/forum/viewtopic.php?t=21674&highlight=vbs+script

Not quiet DLLish, but independent of 32/64 bit i think...
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group