Jump to content

exe work but dll not


Recommended Posts

I have this C code

DWORD Interface() {
DWORD i;
HDEVINFO hDevInfo;
SP_DEVINFO_DATA spDevInfoData ;
hDevInfo=(HDEVINFO) SetupDiGetClassDevsW(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
if(hDevInfo == INVALID_HANDLE_VALUE){
    if(dbg) wprintf(L"error");
    return FALSE;
}
spDevInfoData.cbSize=sizeof(SP_DEVINFO_DATA);
SetupDiEnumDeviceInfo(hDevInfo, 0, &spDevInfoData);
wprintf(L"Error: %d", GetLastError());
i=GetLastError();
if(i == 0) {
    MessageBoxW(NULL, L"WORK!", L"OK", MB_OK);
}else{
    MessageBoxW(NULL, L"FAIL!", L"KO", MB_OK);
}
return i;
}

when run from command line it work fine.

when i use dllCall instead it return a error 6.

Do you have a help for me?

Edited by Ontosy
Link to comment
Share on other sites

Ontosy,

with this kind of information nobody will probably be able to help you.

Maybe you can provide the DLL incl. some documentation.

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I have not time to debug. but you can do all using AutoIt.

 

Global Const $INVALID_HANDLE_VALUE = -1
Global Const $DIGCF_ALLCLASSES = 4
Global Const $DIGCF_PRESENT = 2
Const $tagSP_DEVICEINFO_DATA = "dword Size;byte Guid[16];dword DevInst;ulong_ptr Reserved"

Local $hDevInfo = _SetupDiGetClassDevs(BitOR($DIGCF_ALLCLASSES, $DIGCF_PRESENT))
ConsoleWrite($hDevInfo & @CRLF)

If $hDevInfo = $INVALID_HANDLE_VALUE Then
    ConsoleWrite("Invalid handle..." & @CRLF)
    Exit
EndIf
Local $tDeviceInfo = DllStructCreate($tagSP_DEVICEINFO_DATA)
$tDeviceInfo.Size = DllStructGetSize($tDeviceInfo)

Local $iRet= _SetupDiEnumDeviceInfo($hDevInfo, 0, $tDeviceInfo)

If $iRet Then
    MsgBox(64,"OK","WORK")
Else
    MsgBox(64,"FAIL","KO")
EndIf


Func _SetupDiGetClassDevs($iFlags)
    Local $iResult = DllCall("SetupAPI.dll", "ptr", "SetupDiGetClassDevsW", "ptr", Null, _
            "ptr", Null, "hWnd", Null, "dword", $iFlags)
    Return $iResult[0]
EndFunc   ;==>_SetupDiGetClassDevs


Func _SetupDiEnumDeviceInfo($hDevs, $iIndex, ByRef $tSP_DEVINFO_DATA)
    Local $pSP_DEVINFO_DATA = DllStructGetPtr($tSP_DEVINFO_DATA)
    Local $iResult = DllCall("SetupAPI.dll", "int", "SetupDiEnumDeviceInfo", _
            "ptr", $hDevs, "int", $iIndex, "ptr", $pSP_DEVINFO_DATA)
    Return $iResult[0]
EndFunc   ;==>_SetupDiEnumDeviceInfo

Saludos

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...