Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Stuck trying to use Win32::API

by newbieperlperson (Acolyte)
on Aug 30, 2016 at 18:43 UTC ( [id://1170815]=perlquestion: print w/replies, xml ) Need Help??

newbieperlperson has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use Win32::API to access advapi32.dll CredRead API, I have little experience with how to interact with Windows DLL’s, pointers, etc and way out of my depth here.

The error I am getting is “Win32::API a function was called with the wrong prototype and caused a C stack inconsistency”, code is below.

The CredRead is used to access the Windows version of Keepass, it is the Windows Credentials Manager.

Here is the code I have, can someone please assist me. Thank You
use strict; use Win32; use Win32::API; # public enum CRED_TYPE : int # { # GENERIC = 1, # DOMAIN_PASSWORD = 2, # DOMAIN_CERTIFICATE = 3, # DOMAIN_VISIBLE_PASSWORD = 4, # MAXIMUM = 5 # } my $CredRead = new Win32::API('advapi32.dll', 'CredRead', [qw(P P)], 'N') or die "Find CredRead: $^E"; my $strTarget = "testUser"; #I created user testUser via Control Panel > Credential Manager $CredRead->Call($strTarget,1) or die "CredRead->Call: $^E";

Reference URL's:-
https://msdn.microsoft.com/en-us/library/windows/desktop/aa374804(v=vs.85).aspx
http://www.pinvoke.net/default.aspx/advapi32/CredRead%20.html
http://stackoverflow.com/questions/32548714/how-to-store-and-retrieve-credentials-on-windows-using-c-sharp?rq=1

Replies are listed 'Best First'.
Re: Stuck trying to use Win32::API
by runrig (Abbot) on Aug 30, 2016 at 22:23 UTC
    It's been a while since I've used Win32::API, but from your link on the CredRead function, I believe the argument prototype should be [qw(P I I S)], not [qw(P P)]. then you'll need to pre-allocate the size of the structure returned in the last argument, which you can try to do with Win32::API::Struct (read the Win32::API docs), so that you'll have a convenient object to peek into the structure with.
      Thanks, I think this is currently beyond me, I do not have the domain knowledge to succeed here, is there any other way to do this, perhaps a wrapper?, etc.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1170815]
Approved by stevieb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-04-18 21:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found