Ontosy

exe work but dll not

6 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

I attach full code and example:

test.exe work

test.dll not.

example is here.

Share this post


Link to post
Share on other sites

I have seen a similar problem here.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I have tryed to load dll from a C software and it work fine.

Do it is a autoit3 bug?

Edited by Ontosy

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