MoRBiDuS Posted September 19, 2014 Share Posted September 19, 2014 (edited) Hi, I've this DLL structure, Code: extern "C" __declspec(dllexport) void GetInfo(MODULEINFO *); The GetInfo() function is to fill the MODULEINFO structure with information on the module: Code: typedef struct { DWORD dwFlags; // Combination of flags defining different modes of hashing char *szAbout; // Address of text line containing module information char *szHashType; // Address of text line containing hash name DWORD dwReserved[13]; // Reserved for future usage } MODULEINFO; But I do not know how to implement in AutoIt "char * string" Can you help me? Edited September 19, 2014 by MoRBiDuS Link to comment Share on other sites More sharing options...
Solution Danyfirex Posted September 19, 2014 Solution Share Posted September 19, 2014 maybe this: Local $tMODULEINFO=DllStructCreate("DWORD dwFlags;ptr szAbout;ptr szHashType;DWORD dwReserved[13]") Local $aResult = DllCall("yourdll.dll", "none:cdecl", "GetInfo", "ptr", DllStructGetPtr($tMODULEINFO)) Saludos MoRBiDuS 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
MoRBiDuS Posted September 19, 2014 Author Share Posted September 19, 2014 Thank you Danyfirex This is the complete code, in case anyone needs it in the future... expandcollapse popup$dll = DllOpen("md5.dll") If $dll=-1 Then MsgBox(0, "", "DLL not found " & @error); Exit EndIf ;~ typedef struct { ;~ DWORD dwFlags; // Combination of flags defining different modes of hashing ;~ char *szAbout; // Address of text line containing module information ;~ char *szHashType; // Address of text line containing hash name ;~ DWORD dwReserved[13]; // Reserved for future usage ;~ } MODULEINFO; $tMODULEINFO=DllStructCreate("DWORD dwFlags;ptr szAbout;ptr szHashType;DWORD dwReserved[13]") If @error Then MsgBox(0, "", "Error in DllStructCreate " & @error); Exit EndIf ;========================================================= ; make the DllCall ;========================================================= $aResult = DllCall($dll, "none:cdecl", "GetInfo", "ptr", DllStructGetPtr($tMODULEINFO)) If @error Then MsgBox(0, "", "Error in DllCall " & @error); Exit EndIf ;========================================================= ; Get data from pointer ;========================================================= $ptr_szAbout = DllStructGetData($tMODULEINFO, "szAbout") $ptr_szHashType = DllStructGetData($tMODULEINFO, "szHashType") $data_szAbout = DllStructCreate("char[255]", $ptr_szAbout) $data_szHashType = DllStructCreate("char[255]", $ptr_szHashType) ;========================================================= ; Display info ;========================================================= MsgBox(0, "DllStruct", _ "Struct Size: " & DllStructGetSize($tMODULEINFO) & @CRLF & _ "Struct pointer: " & DllStructGetPtr($tMODULEINFO) & @CRLF & _ "__________________________________" & @CRLF & _ "dwFlags: " & DllStructGetData($tMODULEINFO, "dwFlags", 1) & @CRLF & _ "szAbout ptr: " & DllStructGetData($tMODULEINFO, "szAbout") & @CRLF & _ "szHashType ptr: " & DllStructGetData($tMODULEINFO, "szHashType") & @CRLF & _ "__________________________________" & @CRLF & _ "szAbout str: " & DllStructGetData($data_szAbout, 1) & @CRLF & _ "szHashType str: " & DllStructGetData($data_szHashType, 1)) ;========================================================= ; Free the memory allocated for the structs if needed ;========================================================= $tMODULEINFO = 0 $data_szAbout = 0 $data_szHashType = 0 ;========================================================= ; Close DLL ;========================================================= DllClose($dll) Link to comment Share on other sites More sharing options...
JohnOne Posted September 19, 2014 Share Posted September 19, 2014 If Danyfirex has solved your problem, It's customary to like his post and mark the question as answered. MoRBiDuS 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
funkey Posted September 19, 2014 Share Posted September 19, 2014 This can not work correct. You have to allocate the memory for the strings first! Here the non-tested function: #include <Array.au3> ;~ typedef struct { ;~ DWORD dwFlags; // Combination of flags defining different modes of hashing ;~ char *szAbout; // Address of text line containing module information ;~ char *szHashType; // Address of text line containing hash name ;~ DWORD dwReserved[13]; // Reserved for future usage ;~ } MODULEINFO; Global Const $tagMODULEINFO = "DWORD dwFlags;ptr szAbout;ptr szHashType;DWORD dwReserved[13]" Global $aInfo = _MD5_GetInfo() If Not @error Then _ArrayDisplay($aInfo) EndIf Func _MD5_GetInfo() Local $tInfo = DllStructCreate($tagMODULEINFO) Local $tszAbout = DllStructCreate("char szAbout[256]") Local $tszHashType = DllStructCreate("char szHashtype[256]") DllStructSetData($tInfo, "szAbout", DllStructGetPtr($tszAbout)) DllStructSetData($tInfo, "szHashType", DllStructGetPtr($tszHashType)) Local $aRet = DllCall("md5.dll", "none:cdecl", "GetInfo", "struct", $tInfo) If @error Then Return SetError(1, 0, "") Local $aResult[3] = [ _ DllStructGetData($tInfo, "dwFlags"), _ DllStructGetData($tszAbout, "szAbout"), _ DllStructGetData($tszHashType, "szHashType")] Return $aResult EndFunc Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Danyfirex Posted September 19, 2014 Share Posted September 19, 2014 is allocated $data_szAbout = DllStructCreate("char[255]", $ptr_szAbout) saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
funkey Posted September 19, 2014 Share Posted September 19, 2014 But you need to allocate before dll call, as I said 'first'. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
MoRBiDuS Posted September 19, 2014 Author Share Posted September 19, 2014 (edited) I need to allocate the memory for the strings first? This section of my code is to fetch the data that is inside the pointers provided by the DLL: ;========================================================= ; Get data from pointer ;========================================================= $ptr_szAbout = DllStructGetData($tMODULEINFO, "szAbout") $ptr_szHashType = DllStructGetData($tMODULEINFO, "szHashType") $data_szAbout = DllStructCreate("char[255]", $ptr_szAbout) $data_szHashType = DllStructCreate("char[255]", $ptr_szHashType) The strucs "data_szAbout $" and "$ data_szHashType" are necessary before dll call ? Edited September 19, 2014 by MoRBiDuS Link to comment Share on other sites More sharing options...
funkey Posted September 19, 2014 Share Posted September 19, 2014 The MODULEINFO has pointers for the string position. You have to make structs for the strings and tell the position of the strings to the MODULEINFO struct. Then the GetInfo() function can fill the strings to the position of the reserved memory for the strings. Go step by step through the code in post #5 to understand how it has to works. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
trancexx Posted September 19, 2014 Share Posted September 19, 2014 funkey, where did that come from. I mean, how do you know that? Is there some documentation by the dll dev available? If so, would you mind linking it. Otherwise, I see no reason to think your code is more correct than the other. Maybe the dll allocates memory space for the strings. That's also valid option. Danyfirex 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
funkey Posted September 20, 2014 Share Posted September 20, 2014 funkey, where did that come from. I mean, how do you know that? Is there some documentation by the dll dev available? If so, would you mind linking it. Otherwise, I see no reason to think your code is more correct than the other. Maybe the dll allocates memory space for the strings. That's also valid option. Function looks like this in post#10: https://forum.antichat.ru/printthread.php?t=91666&page=13&pp=40 So if this is the code there is no memory allocation in the dll. And if there was one the memory has to be freed. But of course I could be wrong. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Danyfirex Posted September 20, 2014 Share Posted September 20, 2014 it does not need to be allocate because it return a pointer to a const in .idata section who inizialized with size of 24 bytes. @funkey Your code will not work correctly because the fucntion will fill the structure. it will overwrite your pointer passed in the structure. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
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