JohnOne Posted January 12, 2014 Share Posted January 12, 2014 (edited) Getting an odd result from a DllCall. I'd expect 65 as a result. MsgBox(0,"Success", _Asc("A")) Func _Asc($char) $a_Asc = DllCall("AU3.dll", "uint", "_Asc", "str", $char) If @error Then Exit MsgBox(0, "_Asc Error", @error) EndIf Return $a_Asc[0] EndFunc unsigned int __stdcall _Asc(char Char){ return static_cast<unsigned int>(Char); } Instead I'm getting what appears to be random results such as 120, 4294967184 and others. Can anyone give me a hint as to why this might be happening? Win 7 32 VS 2010 Edited January 13, 2014 by JohnOne 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...
jaberwacky Posted January 13, 2014 Share Posted January 13, 2014 Only thing I see is that the c++ func expects a char but you call it a string in _Asc. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
JohnOne Posted January 13, 2014 Author Share Posted January 13, 2014 Yes, I'm not sure dllcall has a type char, well it errors out with 1 if I use it with a data struct value, and if I use byte or int the return is 0. 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...
jaberwacky Posted January 13, 2014 Share Posted January 13, 2014 OK, my current research leads me to believe that the problem lies in the cast. Maybe there is some sort of undefined compiler issue. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
JohnOne Posted January 13, 2014 Author Share Posted January 13, 2014 Possibly, cheers. I've tried using a c style cast "(unsigned int)Char;" which is no good either. 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...
jaberwacky Posted January 13, 2014 Share Posted January 13, 2014 One possible solution I came across is this: char a = "A"; unsigned int b = a; return b; Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
JohnOne Posted January 13, 2014 Author Share Posted January 13, 2014 I believe it's on autoit side. this works fine. unsigned int __stdcall _Asc(char Char){ return static_cast<unsigned int>('A'); } 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...
Richard Robertson Posted January 13, 2014 Share Posted January 13, 2014 You can't mark the parameter as a string. Strings are sent via handles and not as literal data. The value you are printing is just one part of a handle. Try using CHAR since that is valid in DllStructs. If that doesn't work, use BYTE and change the C function parameter type to unsigned char. jaberwacky 1 Link to comment Share on other sites More sharing options...
trancexx Posted January 13, 2014 Share Posted January 13, 2014 When you say "wstr" or "str" it means string pointer. That means your dll func should accept just that: unsigned int __stdcall _Asc(wchar_t* Char) { // Sanity check if (Char == nullptr) return 0; // Read firts character wchar_t x = Char[0]; // Return character value of your type return static_cast<unsigned int>(x); }And on script side: MsgBox(0,"Success", _Asc("A")) Func _Asc($char) $a_Asc = DllCall("AU3.dll", "uint", "_Asc", "wstr", $char) If @error Then Exit MsgBox(0, "_Asc Error", @error) EndIf Return $a_Asc[0] EndFunc JohnOne and jaberwacky 2 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
JohnOne Posted January 13, 2014 Author Share Posted January 13, 2014 Thanks trancex, I was so sure i was getting it wrong on AU3 side, I'd stopped looking on C side. What is reason you recommend wstr over str? 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...
trancexx Posted January 13, 2014 Share Posted January 13, 2014 Of course you can use "str" if that suits your needs, only then you should adjust dll code to accept char* because the null terminator would be missing if you pass strings larger than one character and you would get results you don't expect. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
JohnOne Posted January 13, 2014 Author Share Posted January 13, 2014 I see, thank you very kindly ma'am. 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...
jchd Posted January 13, 2014 Share Posted January 13, 2014 Isn't it also that str is retricted to ANSI while wstr welcomes UTF-16? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
trancexx Posted January 13, 2014 Share Posted January 13, 2014 Yes, but maybe JohnOne is ANSI gay. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
JohnOne Posted January 13, 2014 Author Share Posted January 13, 2014 (edited) I'm everything the ladies want me to be, all kinds of gay too, if the price is right. EDIT: But I'll be honest, I do get mixed up with ANSI and ASCII all the time until I'm reminded. Edited January 13, 2014 by JohnOne 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...
jchd Posted January 13, 2014 Share Posted January 13, 2014 You never know: maybe he's learning glagolitic. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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