Jump to content

Calling a function method in a dll


Recommended Posts

There is an API for hardware, which is implemented through Lusbapi.dll

In the C ++ reference it looks like this:
1) if (GetDllVersion() != 2) { printf("error 1"); }
2) pModule = static_cast<ILE440 *>(CreateInstance("e440"));
if (pModule == NULL) { printf("error 2"); }
3) if (!pModule->GetModuleName()) { printf("error 3"); }

For AutoIt I rewrote:
$hDLL = DllOpen('Lusbapi.dll')
1) $aRes = DllCall($hDLL, 'LRESULT', 'GetDllVersion')
if $aRes[0] <> 2 then Exit
2) $tDeviceName = DllStructCreate("char DeviceName[9]")
DllStructSetData($tDeviceName, "DeviceName", 'e440')
$aRes = DllCall($hDLL, 'PTR', 'CreateLInstance', 'STRUCT*', $tDeviceName)
$pModule = $aRes[0]
if $pModule == Null then Exit
3) At this step, the error
$aRes = DllCall($hDLL, 'PTR', 'GetModuleName')

The function GetModuleName was not found (since this is a method from the CreateLInstance function), I could not implement a call to the method

Link to post
Share on other sites

Hello.  this should work.

 

Local $sDeviceName="e440"
Local $aCall = DllCall($hDLL, 'dword', 'CreateLInstance', 'str', $sDeviceName)

Saludos

Link to post
Share on other sites

So part of your include lusbapi.h has some struct constructs where the pointer reference is to the function

extern "C" DWORD WINAPI GetDllVersion(void);
extern "C" LPVOID WINAPI CreateLInstance(PCHAR const DeviceName);

enum { USB11_LUSBAPI, USB20_LUSBAPI, INVALID_USB_SPEED_LUSBAPI };
enum { NO_MODULE_MODIFICATION_LUSBAPI = -1 };
const WORD MAX_VIRTUAL_SLOTS_QUANTITY_LUSBAPI = 127;


// ==========================================================================
// *************************** L-Card USB BASE ******************************
// ==========================================================================
struct ILUSBBASE
{
	virtual BOOL WINAPI OpenLDevice(WORD VirtualSlot) = 0;
	virtual BOOL WINAPI CloseLDevice(void) = 0;
	virtual BOOL WINAPI ReleaseLInstance(void) = 0;
	virtual HANDLE WINAPI GetModuleHandle(void) = 0;
	virtual BOOL WINAPI GetModuleName(PCHAR const ModuleName) = 0;
	virtual BOOL WINAPI GetUsbSpeed(BYTE* const UsbSpeed) = 0;
	virtual BOOL WINAPI LowPowerMode(BOOL LowPowerFlag) = 0;
	virtual BOOL WINAPI GetLastErrorInfo(LAST_ERROR_INFO_LUSBAPI* const LastErrorInfo) = 0;
};

struct ILE140 : public ILUSBBASE
{
	virtual BOOL WINAPI GET_ADC_PARS(ADC_PARS_E140* const AdcPars) = 0;
	virtual BOOL WINAPI SET_ADC_PARS(ADC_PARS_E140* const AdcPars) = 0;
	virtual BOOL WINAPI START_ADC(void) = 0;
...

 

For that to work you probably need

 

Link to post
Share on other sites

You need to do something like this.

 

Local $tFunctions = DllStructCreate("ptr[" $iNumberOfFunctions "]", $pModule)
DllCallAddress("none", DllStructGetData($tFunctions,1, 4)) ;GetModuleHandle

Saludos
 

 

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ScrapeYourself
      I didn't like the search time of Simple Native Image Search, and being on windows 10 64bit, I couldn't get ImageSearchDll.dll to work properly.
      So I started researching image search routines and found this excellent post and set of replies find-a-bitmap-within-another-bitmap.

      I really liked the pattern that the Simple Native Image Search used, the clipboard usage and the method of searching. Although I think it could be improved by using some short circuit techniques to return sooner, like consecutive matched > 65% return | matched total > 85% return) , and I wanted the function to manage the click on the found image as well.
      So I just did a bit more research and a few trips to MSDN and stackoverflow, these two snippets allow me to replicate KyleJustKnows code, and click.  Another feature is that it also saves the image it captures to disk, so that if the image is not found you can check what was captured, and alternatively cut out a new search image to use.
      private void PrintScreen() { keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0); keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0); } public Bitmap CaptureScreenPrtSc() { PrintScreen(); if (Clipboard.ContainsImage()) { using (Image img = Clipboard.GetImage()) { img.Save("ClipBoard.PNG", ImageFormat.Png); return new Bitmap(img); } } return default; } [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool GetCursorPos(out MousePoint lpMousePoint); [DllImport("user32.dll")] private static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo); private MousePoint GetCursorPosition() { var gotPoint = GetCursorPos(out MousePoint currentMousePoint); if (!gotPoint) { currentMousePoint = new MousePoint(0, 0); } return currentMousePoint; } private void MouseEvent(MouseEvents value) { MousePoint position = GetCursorPosition(); mouse_event ((int)value, position.X, position.Y, 0, 0) ; }
      So after managing to compile the dll with COM support, with much reading of this forum and many posts from paulpmeier, ptrex, LarsJ, and others about loading .net, I managed to get this all working.

      Here is the BotIt Core:
      ; BotIt Core Global $sPath = "BotIt.dll" Global $RegAsmPath = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" Func BotIt_StartUp() RegisterBotIt() OnAutoItExitRegister("UnregisterBotIt") EndFunc ;==>BotIt_StartUp Func RegisterBotIt() RunWait($RegAsmPath & " /register /codebase /tlb " & $sPath, @ScriptDir, @SW_HIDE) EndFunc ;==>RegisterBotIt Func UnregisterBotIt() FileDelete("Step.txt") RunWait($RegAsmPath & " /unregister " & $sPath, @ScriptDir, @SW_HIDE) EndFunc ;==>UnregisterBotIt Func ActivateAndSearch($sTitle, $sImgPath, $bClick = True) WinActivate($sTitle) Sleep(1000) $oBotIt = ObjCreate("BotIt.DetectImageAndClick") ConsoleWrite($sImgPath & @CRLF & $bClick & @CRLF) $bRet = $oBotIt.FindAndClick($sImgPath, $bClick) Return $bRet EndFunc ;==>ActivateAndSearch  
      Usage:
      Do Sleep(500) Until ActivateAndSearch("Window Title", "PathToFile")

      I hope you enjoy!
      Regards,
      ScrapeYourself
       
       
      BotIt.cs
    • By Aelc
      Hey there,
      I'm trying to create an DLL callback loop to get an updated screen (actually just 1 pic that should refresh because i already got a screencapturetool to get a pic from my game every sec)
      i want to bring that pic on a mobile phone. the dll can connect with the program i'm using to get the connection so that's fine.
      The prob is: it's my first DLL project so i don't even get 1 call or other returns of it. I tried much with the examples but i can't compare it that much with it.
      The calls shall be with c# where i'm not familiar with... i just searched much in forums and programsites but i didn't get a reference point.
      could someone have a tip to start please?
       
      there are calls like
      [DllImport("file.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] public static extern bool $funcname1(String identifier, String friendlyName, ref CbConext callback);
      [DllImport("file.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] public static extern bool $funcname2(String identifier, String friendlyName, ref logiArxCbContext callback, byte [] iconBitmap);
      [DllImport("file.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] public static extern bool $funcname3(String filePath, String fileName, String mimeType = "");
      tried something like
      $dll = DllOpen ("file.dll")
      $call = DllCall ( $dll,"bool","$funcname1","str","indetifier","str","test","int","CbContext callback" )
       
      or have i work with dllstructcreate or dllcallbackregister? 
      it would be enough for me if someone just could explain me how to get the imports with the params/funcs/types in autoit.
       
      i don't know if it's important but u shall call 
      public classes and public constants in c# before such as using.system make this sense?
       
      sry for my bad english 
      and thank you in advance
    • By NathanV
      If you are interested upgrading my existing AutoIt script as the original developer is no longer available. You can reach me at "nvalliap  at  yahoo   com"
      If you know C# and DLL it would be  a plus.
      Thanks
×
×
  • Create New...