Jump to content
Sign in to follow this  
ogloed

"memory cannot be 'read'" after DllCall().

Recommended Posts

ogloed

Again, I'm struggling with DllCall(). So I have this MS C++ 6.0 compiled DLL and a manual for it. There's a function:
 

Get information of disk arrays
Declaration:
VINT vr_get_array_info (VINT array_index, vr_array_info_t* pinfo);
Description:
Application can fetch the information of one specific disk array, which is located
by index of all disk arrays in current system.
Input parameters:
VINT array_index :
Index to all disk arrays in system, specify which disk array.
vr_array_info_t *pinfo :
14
Pointer to a vr_array_info_t data structure to get the information
Return value:
VR_SUCCESS :
Get the information successfully.
VR_ERR_NOT_INITED :
Raid lib hasn’t been initialized.
VR_ERR_INVALID_INDEX :
The input index is invalid.
VR_ERR_INVALID_PARAM :
Input parameter is invalid: the pointer is NULL.

Here's what DLL Export Viewer says:
 

Function Name     : int __cdecl vr_get_array_info(int,struct _vr_array_info *)


Here's what is this _vr_array_info:
 

typedef struct _vr_array_info {
        VWORD status;  // current status of disk array
                        
        VBYTE raidType;// same as Disk_Array.raidType, but value 0xFF means
                        // a stand-alone disk. When it's a stand-alone disk,
                        // only arDevices[0] and diskNum has meaning, and diskNum should
                        // always be 1 .

        VBYTE diskNum;// count of valid arDevices[] members. 

        // Note: disk array maybe incomplete, i.e. , some disk in the array maybe missing, 
        //     corresponding device ptr arDevices[i]->pRealDevice should be NULL.
        
        VDWORD capacityLow;// (Unit: sector)
        VDWORD capacityHigh;// (Unit: sector)

        // following 8 bytes define the real-capcity (in sector) of every disk in array
        VDWORD realCapacityLow;        // (Unit: sector)
        VDWORD realCapacityHigh;       // (Unit: sector)


        VDWORD stripeSize; // valid when raid is raid0, raid5 or raid01, in Kbytes
        VDWORD blockSize; // valid when raid is RAID5, in Kbytes

        VBOOL  bNeedMigration; // the raid need migration
                               // only valid when raid0/raid5/matrixRaid
        VBOOL  bNeedInit;      // the raid need initialization, only valid for RAID5
        VBOOL  bOptimized;     // only for RAID5, this RAID5 access was optimized

         VBYTE systemDisk;     /* does the devices within this disk array 
                                  contain system files of current running OS ? 
                                   the probably value are:
                                   VR_DEVICE_NOT_SYS_DISK
                                   VR_DEVICE_MAYBE_SYS_DISK
                                   VR_DEVICE_SYS_DISK
                                 they are defined in this file */

        VWORD raid_index;// only raid index, no meaning with stand-alone disk
        VINT  index; // all device index, including all raid and stand-alone disk
} vr_array_info_t;



Here's my code (function names are actually decorated, so):
 

Local $pTest

$hDLL = DllOpen(@ScriptDir & "\drvInterface.dll")

;~ VINT vr_init (void);
ConsoleWrite("vr_init..." & @CRLF)
$sTest = DllCall($hDLL, "int:cdecl", "?vr_init@@YAHXZ")

;~ VINT vr_get_controller_num (VINT *pnumber);
ConsoleWrite("vr_get_controller_num..." & @CRLF)
$sTest = DllCall($hDLL, "int:cdecl", "?vr_get_controller_num@@YAHPAH@Z", "int*", "$pTest")
$iControllerNumber = $sTest[1]
ConsoleWrite("$iControllerNumber = " & $iControllerNumber & @CRLF)

;~ VINT vr_get_device_num (VINT *pnumber);
ConsoleWrite("vr_get_device_num..." & @CRLF)
$sTest = DllCall($hDLL, "int:cdecl", "?vr_get_device_num@@YAHPAH@Z", "int*", "$pTest")
$iDeviceNumber = $sTest[1]
ConsoleWrite("$iDeviceNumber = " & $iDeviceNumber & @CRLF)

;~ VINT vr_get_array_num (VINT only_raid, VINT *pnumber);
ConsoleWrite("vr_get_array_num..." & @CRLF)
$sTest = DllCall($hDLL, "int:cdecl", "?vr_get_array_num@@YAHHPAH@Z", "int", 0, "int*", "$pTest")
$iArrayNumber = $sTest[2]
ConsoleWrite("$iArrayNumber = " & $iArrayNumber & @CRLF)

$vr_array_info = DllStructCreate("ushort status;byte raidType;byte diskNum;dword capacityLow;dword capacityHigh;dword stripeSize;dword blockSize;boolean bNeedMigration;boolean bNeedInit;boolean bOptimized;byte systemDisk;byte raid_index;int index")
;~ VINT vr_get_array_info (VINT array_index, vr_array_info_t* pinfo);
ConsoleWrite("vr_get_array_info..." & @CRLF)
$sTest = DllCall($hDLL, "int:cdecl", "?vr_get_array_info@@YAHHPAU_vr_array_info@@@Z", "int", 0, "struct*", $vr_array_info)

;~ void vr_exit (void);
ConsoleWrite("vr_exit..." & @CRLF)
$sTest = DllCall($hDLL, "none", "?vr_exit@@YAXXZ")

DllClose($hDLL)

Exit

Everything works fine up to vr_get_array_info part. This is where I get a "memory cannot be 'read'" Windows error ("Instruction at 0x7c93a514 referenced memory at 0x00000000").

What am I doing wrong? Please help.

drvInterface.dll

ProgGuide.pdf

Share this post


Link to post
Share on other sites
Danp2

Looks like you got the structure definition wrong --

VDWORD realCapacityLow;        // (Unit: sector)
        VDWORD realCapacityHigh;       // (Unit: sector)

is missing

byte raid_index;

also appears to be wrong.

  • Like 1

Share this post


Link to post
Share on other sites
ogloed
1 hour ago, Danp2 said:

Looks like you got the structure definition wrong --

VDWORD realCapacityLow;        // (Unit: sector)
        VDWORD realCapacityHigh;       // (Unit: sector)

is missing

byte raid_index;

also appears to be wrong.

Well, thank you and "thank you" to authors of the DLL manual. For there's a little bit different picture:

 

vr_array_info_t
typedef struct _vr_array_info {
VWORD status;
VBYTE raidType; // value 0xFF means
// a stand-alone disk. When it's a stand-alone disk,
// only diskNum has meaning, and diskNum should
// always be 1 .
VBYTE diskNum;// count of valid disk members.
VDWORD capacityLow;// (Unit: sector)
VDWORD capacityHigh;// (Unit: sector)
VDWORD stripeSize; // valid when raid is raid0 or raid01, in Kbytes
VDWORD blockSize; // valid when raid is RAID5, in Kbytes
VBOOL bNeedMigration; // the raid need migration
// only valid when raid0/raid5/matrixRaid
VBOOL bNeedInit; // the raid need initialization, only valid for RAID5
VBOOL bOptimized; // only for RAID5, this RAID5 access was optimized
VBYTE systemDisk; /* does the devices within this disk array contain system
files of current running OS ? The probably value are:
VR_DEVICE_NOT_SYS_DISK
VR_DEVICE_MAYBE_SYS_DISK
VR_DEVICE_SYS_DISK
they are defined in this file */
VBYTE raid_index;// only raid index, no meaning with stand-alone disk
VINT index; // all device index, including all raid and stand-alone disk
} vr_array_info_t;

OK, so here's what I changed:
 

$vr_array_info = DllStructCreate("ushort status;byte raidType;byte diskNum;dword capacityLow;dword capacityHigh;dword realCapacityLow;dword realCapacityHigh;dword stripeSize;dword blockSize;boolean bNeedMigration;boolean bNeedInit;boolean bOptimized;byte systemDisk;ushort raid_index;int index")

Getting the same "memory cannot be 'read'", but now with "referenced memory at 0x00000004" and "referenced memory at 0x00000000"  showing randomly.

Share this post


Link to post
Share on other sites
ogloed
1 hour ago, Danp2 said:

Look at the bottom of page 3 in the manual. There they show the definition of the data types, which are different than what you are using.

 

IT WORKS, THANK YOU!!! I'm so happy now! :) 

Share this post


Link to post
Share on other sites
ogloed

Working piece of code:

 

$vr_array_info = DllStructCreate("ushort status;ubyte raidType;ubyte diskNum;ulong capacityLow;ulong capacityHigh;ulong realCapacityLow;ulong realCapacityHigh;ulong stripeSize;ulong blockSize;int bNeedMigration;int bNeedInit;int bOptimized;ubyte systemDisk;ushort raid_index;int index")
$sTest = DllCall($hDLL, "int:cdecl", "?vr_get_array_info@@YAHHPAU_vr_array_info@@@Z", "int", 0, "struct*", DllStructGetPtr($vr_array_info))

 

Share this post


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
Sign in to follow this  

  • Similar Content

    • Yirrlaar
      By Yirrlaar
      Hello All,
      I'm using "ImageSearch2015.au3" and i'm trying to figure out WHY, for the life of me, I can't find an image is hidden.
      So what I came up with, is as follows:
      _ImageSearchAreaHidden("C:\icon.png", 1, 0, 0, 800, 600, $x1, $y1, 80, 0) Func _ImageSearchAreaHidden($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance, $transparency = 0) Local $h, $result local $TestScreen = "C:\TestScreen.png" ;previsous screenshot of the image looking for, fully visible If Not FileExists($findImage) Then Return "Image File not found" If $transparency <> 0 Then $findImage = "*" & $transparency & " " & $findImage If $tolerance < 0 Or $tolerance > 255 Then $tolerance = 0 If $h_ImageSearchDLL = -1 Then _ImageSearchStartup() If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage $result = DllCall($h_ImageSearchDLL, "str", "ImageSearchEx", "str", $TestScreen, "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage) If @error Then Return "DllCall Error=" & @error If $result = "0" Then Return False $array = StringSplit($result[0], "|") If (UBound($array) >= 4) Then $x = Int(Number($array[2])) ; Get the x,y location of the match $y = Int(Number($array[3])) If $resultPosition = 1 Then $x = $x + Int(Number($array[4]) / 2) ; Account for the size of the image to compute the centre of search $y = $y + Int(Number($array[5]) / 2) EndIf Return True EndIf EndFunc ;==>_ImageSearchAreaHidden Now when the folder with the icon is completely visible, it finds the icon without any issues, however if I cover up the icon, it no longer finds the image in the folder.
      Any ideas?
    • cdeb
      By cdeb
      I'm trying to verify which is the default scanner and if it is different from what I need to propose a choice among those available.
      All this is possible with eztw32.dll however I can not make certain functions work
      Are these:
      int TWAIN_GetDefaultSourceName(LPSTR pzName)
      string TWAIN_DefaultSourceName()
      int TWAIN_GetSourceList(void)
      source: http://www.eztwain.com/pub/eztp/EZTwain_User_Guide.pdf
      I tried this way but they do not work:
      Local $pzName
      $pzName = DllCall($pathDLL,"int","TWAIN_DefaultSourceName") ;
      $rc = DllCall($pathDLL,"int","TWAIN_GetDefaultSourceName", "str*", $pzName) ;
      $rc = DllCall($pathDLL,"int","TWAIN_GetDefaultSourceName","str", $pzName) ;
      $rc = DllCall($pathDLL,"int","TWAIN_GetSourceList")
      $rc = DllCall($pathDLL,"int","TWAIN_GetSourceList", "NONE", "") ;
       
      Can anyone help me?
      Everything else works, here is the code:
       
      Local $pathDLL = @ScriptDir&"\_res\eztw32.dll" Local $rc = DllCall($pathDLL,'int','TWAIN_EasyVersion') if @error <> 0 then MsgBox(16+262144, "DllCall Error", "Error load eztw32.dll") else ConsoleWrite('--> eztw32.dll version: ' & $rc[0]/100 & @CRLF) $rc = DllCall($pathDLL,"int","TWAIN_IsAvailable") If @error > 0 Then MsgBox(16+262144, "DllCall Error", "Error call DLL - TWAIN_IsAvailable") if $rc[0] <> 0 then ConsoleWrite('--> TWAIN available: RC = ' & $rc[0]&@CRLF) ;;;;;;;;;;;;;;;;;;;;;; I NEED HERE ;manual select scanner Local $hwnd $rc = DllCall($pathDLL,"long","TWAIN_SelectImageSource",'hwnd',$hwnd) ConsoleWrite('--> TWAIN_SelectImageSource = ' & $rc[0]&@CRLF) if $rc[0] <> 0 then ConsoleWrite("--> TWAIN device selected"&@CRLF) else ConsoleWrite("--> no TWAIN device selected"&@CRLF) endif Else ConsoleWrite('--> TWAIN NOT available: RC = ' & $rc[0]&@CRLF) ; es: 0 endif endif thank you
    • Mannyfresh31
      By Mannyfresh31
      Hi Everybody I want know if there is someone kind enough to help me translate this code in to Autoit please don't blame me cause I'm a newbe 
      here is the code I need to translate also I want know if it's possible to look through a DLL  functions
       
      Declaration in Visual Basic 6: 
      Simply add the DLL import unit 'cashdll.bas' to your project, 
      or add following line to the declarations part: 
      Declare Function CASH_OPENCOM Lib "CASH.DLL" (ByVal CASH_COMPORT As Long) As Long 
       
      Declaration in Visual Basic 6: 
      Simply add the DLL import unit 'cashdll.bas' to your project, 
      or add following line to the declarations part: 
      Declare Sub CASH_CLOSECOM Lib "CASH.DLL" ()
       
       
      and here is the code I have written so far
      down below is the DLL attached also a screen shot of the  exit code of SciTE
      #include<Array.au3> $CashDLL = DllOpen("C:\Users\manue\Downloads\Casll DLL\cash.dll") if $CashDLL Then MsgBox (0,"","CashDLL Open",0) $HOPPER_OPENCOM = DllCall($CashDLL,"LONG","HOPPER_OPENCOM") if isarray ($HOPPER_OPENCOM) Then _Arraydisplay ($HOPPER_OPENCOM) Else MsgBox (0,"",@error,0) EndIf $HOPPER_CLOSECOM = DllCall($CashDLL,"NONE","HOPPER_CLOSECOM") if isarray ($HOPPER_CLOSECOM) Then _Arraydisplay ($HOPPER_CLOSECOM) Else MsgBox (0,"",@error,0) EndIf DllClose ($CashDLL)  
       

      cash.dll
    • marcoauto
      By marcoauto
      Ciao
      I would like to control an ATEM Video Mixer from autoit. I downloaded his SDK which is written in c ++ and I found the sequences to interface, but I was not able to convert the script to self.
      The instructions say to follow this sequence:
      and to connectTo with C++ is:
      string address = "192.168.1.240"; _BMDSwitcherConnectToFailure failureReason = 0; IBMDSwitcher switcher = null; var discovery = new CBMDSwitcherDiscovery(); discovery.ConnectTo(address, out switcher, out failureReason); From Blackmagic SDK:
      IBMDSwitcherDiscovery::ConnectTo method
      The ConnectTo method connects to the specified switcher and returns an IBMDSwitcher object interface for the switcher.
      Syntax HRESULT ConnectTo (string deviceAddress, IBMDSwitcher** switcherDevice, BMDSwitcherConnectToFailure* failReason); Parameters: deviceAddress in Network hostname or IP address of switcher to connect to. switcherDevice out IBMDSwitcher object interface for the connected switcher. failReason out Reason for connection failure as a BMDSwitcherConnectToFailure value. So, I have I tried these solutions but with non success:
      $DllName =@ScriptDir&"\BMDSwitcherAPI.dll" $result = DllCall($DllName, "none", "IBMDSwitcherDiscovery::ConnectTo" & @CRLF) ConsoleWrite("DLLCall Result: " & $result & @CRLF) and I have tried also create an Object (That I think is the best way solution):
      #include <MsgBoxConstants.au3> $oSwitcher=ObjCreate("IBMDSwitcher") If IsObj($oSwitcher) Then MsgBox(64, "", "Object $oSwitcher created successfully") EndIf $oAtem=ObjCreate("IBMDSwitcherDiscovery") If IsObj($oAtem) Then MsgBox(64, "", "Object $oAtem created successfully") EndIf $failureReason =ObjCreate("_BMDSwitcherConnectToFailure") If IsObj($failureReason) Then MsgBox(64, "", "Object $failureReason created successfully") EndIf $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler Global $errore,$oSwitcher1 $oAtem.ConnectTo("192.168.1.36",$oSwitcher,$failureReason); ; This is the custom error handler Func MyErrFunc() $HexNumber = Hex($oMyError.number, 8) MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "Windescription is: " & $oMyError.windescription & @CRLF & _ "Source is: " & $oMyError.source & @CRLF & _ "Description is: " & $oMyError.description & @CRLF & _ "Helpfile is: " & $oMyError.helpfile & @CRLF & _ "Helpcontext is: " & $oMyError.helpcontext & @CRLF & _ "Lastdllerror is: " & $oMyError.lastdllerror & @CRLF & _ "Scriptline is: " & $oMyError.scriptline) EndFunc ;==>MyErrFunc But the result is:
      We intercepted a COM Error !
      Number is: 000000A9
      Windescription is: Variable must be of type 'Object'.
      Source is: 
      Description is: 
      Helpfile is: 
      Helpcontext is: 
      Lastdllerror is: 0
      Scriptline is: 17
      The BMDSwitcherAPI.dll is registered in system. Can someone help me?
      Grazie
      Marco
    • Bilgus
      By Bilgus
      So first things first the example in the help file for _WinApi_Enum_Windows has an error
      ;_ArrayDisplay($aResult, "_WinAPI_EnumWindows", Default, Default, Default, Default, "#|Handle|Class|Title|Text|Process") Should Be _ArrayDisplay($aResult, "_WinAPI_EnumWindows", Default, Default, Default, "Handle|Class|Title|Text|Process") Next is a bit of helpful info on LPCSTR in a callback function it needs  to be passed as a PTR
      DllCallbackRegister($sFUNCT, $sRETURN, "ptr") Finally on to my question
      I'd want to call EnumPropsEX and pass a string through lparam + append to it rather than declaring anything globally
      I can Come up with two ways to do this The second it a lot more code but possibly safer but the first way I think Should do
      1. From a bit of testing It seems AutoIt won't overflow a DllStruct?
      2. Are strings passed through DLL call guaranteed to be 'an ANSI string (a minimum of 65536 chars is allocated)' as the Helpfile clearly states?
      #include <Array.au3> #include <WinAPI.au3> Example() Func Example() Local $aWindows = _WinAPI_EnumWindows() Local $aResult[$aWindows[0][0]][6] For $i = 1 To $aWindows[0][0] $aResult[$i - 1][0] = "0x" & Hex($aWindows[$i][0], 8) $aResult[$i - 1][1] = $aWindows[$i][1] $aResult[$i - 1][2] = WinGetTitle($aWindows[$i][0]) $aResult[$i - 1][3] = WinGetText($aWindows[$i][0]) $aResult[$i - 1][4] = WinGetProcess($aWindows[$i][0]) $aResult[$i - 1][5] = _ArrayToString(EnumProps($aWindows[$i][0]), ", ", 1) Next _ArrayDisplay($aResult, "_WinAPI_EnumWindows", Default, Default, Default, "Handle|Class|Title|Text|Process|Properties") EndFunc ;==>Example Func EnumProps($hWnd, $vDLL = 'user32.dll') ; Create callback function. Local $iErr = 0 Local $aProps[1] = [0] Local $hCb = DllCallbackRegister('_PropEnumProcEx', 'int', 'hwnd;ptr;handle;ptr') ; Call EnumPropsEx Local $aRet = DllCall($vDLL, 'int', 'EnumPropsEx', 'HWND', $hWnd, 'ptr', DllCallbackGetPtr($hCb), 'str', "") If @error Or Not $aRet[0] Then $iErr = @error ConsoleWrite("EnumProps Error:" & $iErr & @CRLF) ElseIf $aRet[3] <> "" Then $aProps = StringSplit($aRet[3], ";") EndIf DllCallbackFree($hCb) Return SetError($iErr, 0, $aProps) EndFunc ;==>EnumProps Func _PropEnumProcEx($hWnd, $sProp, $hData, $pStr) Local $iSzStr = _WinAPI_StringLenA($sProp) + 1 ; + Null Char If $iSzStr > 1 Then Local $tProp = DllStructCreate('char[' & $iSzStr & ']', $sProp) Local $tRetn = DllStructCreate('char[65535]', $pStr) DllStructSetData($tRetn, 1, DllStructGetData($tRetn, 1) & DllStructGetData($tProp, 1) & ";") EndIf Return 1 EndFunc ;==>_PropEnumProcEx ;-------------------------------------------------------------------------------------------------------------- Func EnumProps2($hWnd, $iSzBuffer = 4096, $vDLL = 'user32.dll') ; Create callback function. Local $iErr = 0 Local $sProps Local $aProps[1] = [0] Local $hCb = DllCallbackRegister('_PropEnumProcEx', 'int', 'hwnd;ptr;handle;ptr') Local $tProps = DllStructCreate('int;int;char[' & $iSzBuffer & ']') DllStructSetData($tProps, 1, $iSzBuffer) ;BufferSz DllStructSetData($tProps, 2, $iSzBuffer) ;BufferRemaining ; Call EnumPropsEx Local $aRet = DllCall($vDLL, 'int', 'EnumPropsEx', 'HWND', $hWnd, 'ptr', DllCallbackGetPtr($hCb), 'ptr', DllStructGetPtr($tProps)) If @error Or Not $aRet[0] Then $iErr = @error DllStructSetData($tProps, 2, 0) EndIf DllCallbackFree($hCb) $sProps = DllStructGetData($tProps, 3) If DllStructGetData($tProps, 2) > 0 Then If $sProps <> "" Then $aProps = StringSplit(StringTrimRight($sProps, 1), ";") EndIf Else If Not $iErr Then $iErr = 6 ;buffer overflow Return SetError($iErr, -DllStructGetData($tProps, 2), $aProps) EndIf Return $aProps EndFunc ;==>EnumProps2 Func _PropEnumProcEx2($hWnd, $sProp, $hData, $ptProp) Local $iSzStr = _WinAPI_StringLenA($sProp) + 1 Local $tProp = DllStructCreate('char[' & $iSzStr & ']', $sProp) If $iSzStr > 1 Then Local $sRet = DllStructGetData($tProp, 1) Local $iSzBuffer = DllStructGetData(DllStructCreate('int', $ptProp), 1) Local $tRetn = DllStructCreate('int;int;char[' & $iSzBuffer & ']', $ptProp) DllStructSetData($tRetn, 2, DllStructGetData($tRetn, 2) - $iSzStr) If DllStructGetData($tRetn, 2) > 0 Then DllStructSetData($tRetn, 3, DllStructGetData($tRetn, 3) & $sRet & ";") EndIf EndIf Return 1 EndFunc ;==>_PropEnumProcEx2  
×