Jump to content

Weird return from C++ dll


JohnOne
 Share

Recommended Posts

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 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

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

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

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

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 here
RegExp tutorial: enough to get started
PCRE 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

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 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

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 here
RegExp tutorial: enough to get started
PCRE 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

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...