mailro Posted September 11, 2011 Posted September 11, 2011 (edited) Hi,I am trying to import the functions from a 32bit dll so I can call them from Autoit.Calling them directly is working but after some calls the answers are coming slower than a turtle.Does anyone know how to import the exported functions of this dll? Lets say of the following one: double AvgEntryPrice(string instrument, string account) Calling it the following way:$result = DllCall("NtDirect.dll", "double", "AvgEntryPrice", "str", "ES 09-11", "str", "Sim102") msgbox(0,"",$result[1] & " " & $result[2] & " " & $result[0]) will give you the result, but after about 50 calls the dll replies too slow. I looked around and I found out that this is an export function of the dll and you have somehow to import it in your autoit script and call it directly from there. Any sample code would be appreciatedThanks Edited September 11, 2011 by mailro
smashly Posted September 11, 2011 Posted September 11, 2011 (edited) Hi,Don't know if it'll help but you may want to use DllOpen then DllCall it as many times as needed then use DllClose.Just using DllCall() without opening the dll, then DllCall is opening and closing the Dll every call.I also think that there is more to this dll then just calling the function.I gather the Dll needs to be initialized in some way.As I receive a msgbox from the dll "Failed to initialize Ninja Trader DLL NtDirect.dll (0x80040154)"Even though the AutoIt DllCall itself doesn't error.Global $hDll, $aResult $hDll = DllOpen("NtDirect.dll") If $hDll <> -1 Then For $i = 1 To 50 $aResult = DllCall($hDll, "double", "AvgEntryPrice", "str", "ES 09-11", "str", "Sim102") If Not @error Then ConsoleWrite("DllCall: " & $i & " = " & $aResult[1] & " " & $aResult[2] & " " & $aResult[0] & @LF) Else Msgbox(0,"DllCall: " & $i, "DllCall Failed @error: " & @error) ExitLoop EndIf Next Else Msgbox(0, "DllOpen", "DllOpen failed") EndIf DllClose($hDll) Edit: the "Failed to initialize Ninja Trader DLL NtDirect.dll (0x80040154)" is because I don't have Ninja Trader installed on my pc and it is required to make the call.Or that's the impression I get from reading http://www.ninjatrader.com/support/forum/showthread.php?t=33947 Edited September 11, 2011 by smashly
mailro Posted September 11, 2011 Author Posted September 11, 2011 Thanks for the sample code but it is not doing the trick. It doesn't hang the application. Although the plugin reports that it did with no error. The same problem I was facing too appears not all commands are being proceed. The direct calling is not the way for this dllAs I said you have somehow to import these values as described belowhttp://msdn.microsoft.com/en-us/library/26thfadc%28v=VS.80%29.aspxbased on the example belowhttp://www.ninjatrader.com/support/helpGuides/nt7/index.htmlThanksanyway.
smashly Posted September 12, 2011 Posted September 12, 2011 Hi,I don't think I can be any help then as I have no idea on what your trying to accomplish apart from automating web based trading.From what I can see, it sounds more like a timing issue as to why not all commands are being processed.Other things that come to mind is the account calling and passing the same account name for subsequent function calls using the same acount name leads to invalid data return.That's the impression I get from the reading about initialization.Example: • Default account = Sim101• A function call is made with "" empty string as the account name argument• Sim101 account is automatically used• Subsequent function calls must use empty string if you want to reference the Sim101 account• If you call a function and pass in the argument "Sim101", invalid information will be returnedhttp://www.ninjatrader.com/support/helpGuides/nt7/initialization.htmBut as I don't understand the software your using then I have to say you'll need to muddle through it on your own or wait until someone with a better understanding of what your after comes along.Cheers
Moderators SmOke_N Posted September 12, 2011 Moderators Posted September 12, 2011 Is this a .NET Dll ? If so, you'll need to approach things completely different, creating an object, and utilizing the methods and properties correctly. Without a direct link to the API list, and its inner workings, it's quite difficult to help you much further... Anything more is just speculation. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
mailro Posted September 12, 2011 Author Posted September 12, 2011 Hi,I don't think I can be any help then as I have no idea on what your trying to accomplish apart from automating web based trading.From what I can see, it sounds more like a timing issue as to why not all commands are being processed. Other things that come to mind is the account calling and passing the same account name for subsequent function calls using the same acount name leads to invalid data return.That's the impression I get from the reading about initialization.http://www.ninjatrader.com/support/helpGuides/nt7/initialization.htmBut as I don't understand the software your using then I have to say you'll need to muddle through it on your own or wait until someone with a better understanding of what your after comes along. Cheers I tried that. at your code after the first call not to send again the account value, but it didn't work.You have initialize them the way the article describes and I can't find any resourcesThe DllCallbackRegister example in the autoit help is the one belowhttp://msdn.microsoft.com/en-us/library/843s5s5x%28v=VS.90%29.aspx For the other-case I described earlier can't find any examples
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now